Search in sources :

Example 51 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class CarbonTable method createQueryModelWithProjectAllColumns.

/**
 * Create a new QueryModel with projection all columns in the table.
 */
public QueryModel createQueryModelWithProjectAllColumns(DataTypeConverter converter) {
    QueryProjection projection = new QueryProjection();
    List<CarbonDimension> dimensions = getDimensionByTableName(getTableName());
    for (int i = 0; i < dimensions.size(); i++) {
        projection.addDimension(dimensions.get(i), i);
    }
    List<CarbonMeasure> measures = getMeasureByTableName(getTableName());
    for (int i = 0; i < measures.size(); i++) {
        projection.addMeasure(measures.get(i), i);
    }
    QueryModel model = QueryModel.newInstance(this);
    model.setProjection(projection);
    model.setConverter(converter);
    return model;
}
Also used : QueryProjection(org.apache.carbondata.core.scan.model.QueryProjection) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) QueryModel(org.apache.carbondata.core.scan.model.QueryModel) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 52 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class CarbonTable method fillVisibleMeasures.

/**
 * This method will all the visible allMeasures
 *
 * @param tableName
 */
private void fillVisibleMeasures(String tableName) {
    List<CarbonMeasure> visibleMeasures = new ArrayList<CarbonMeasure>(allMeasures.size());
    for (CarbonMeasure measure : allMeasures) {
        if (!measure.isInvisible()) {
            visibleMeasures.add(measure);
        }
    }
    tableMeasuresMap.put(tableName, visibleMeasures);
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ArrayList(java.util.ArrayList)

Example 53 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class CarbonTable method createProjection.

public QueryProjection createProjection(String[] projectionColumnNames) {
    String factTableName = getTableName();
    QueryProjection projection = new QueryProjection();
    // fill dimensions
    // If columns are null, set all dimensions and measures
    int i = 0;
    if (projectionColumnNames != null) {
        for (String projectionColumnName : projectionColumnNames) {
            CarbonDimension dimension = getDimensionByName(factTableName, projectionColumnName);
            if (dimension != null) {
                projection.addDimension(dimension, i);
                i++;
            } else {
                CarbonMeasure measure = getMeasureByName(factTableName, projectionColumnName);
                if (measure == null) {
                    throw new RuntimeException(projectionColumnName + " column not found in the table " + factTableName);
                }
                projection.addMeasure(measure, i);
                i++;
            }
        }
    }
    return projection;
}
Also used : QueryProjection(org.apache.carbondata.core.scan.model.QueryProjection) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 54 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class SparkDataTypeConverterImpl method convertCarbonSchemaToSparkSchema.

/**
 * convert from CarbonColumn array to Spark's StructField array
 */
@Override
public Object[] convertCarbonSchemaToSparkSchema(CarbonColumn[] carbonColumns) {
    StructField[] fields = new StructField[carbonColumns.length];
    for (int i = 0; i < carbonColumns.length; i++) {
        CarbonColumn carbonColumn = carbonColumns[i];
        if (carbonColumn.isDimension()) {
            if (carbonColumn.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                DirectDictionaryGenerator generator = DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(carbonColumn.getDataType());
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(generator.getReturnType()), true, null);
            } else if (!carbonColumn.hasEncoding(Encoding.DICTIONARY)) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(carbonColumn.getDataType()), true, null);
            } else if (carbonColumn.isComplex()) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(carbonColumn.getDataType()), true, null);
            } else {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(org.apache.carbondata.core.metadata.datatype.DataTypes.INT), true, null);
            }
        } else if (carbonColumn.isMeasure()) {
            DataType dataType = carbonColumn.getDataType();
            if (dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.BOOLEAN || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.SHORT || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.INT || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.LONG) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(dataType), true, null);
            } else if (org.apache.carbondata.core.metadata.datatype.DataTypes.isDecimal(dataType)) {
                CarbonMeasure measure = (CarbonMeasure) carbonColumn;
                fields[i] = new StructField(carbonColumn.getColName(), new DecimalType(measure.getPrecision(), measure.getScale()), true, null);
            } else {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(org.apache.carbondata.core.metadata.datatype.DataTypes.DOUBLE), true, null);
            }
        }
    }
    return fields;
}
Also used : StructField(org.apache.spark.sql.types.StructField) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) DataType(org.apache.carbondata.core.metadata.datatype.DataType) DecimalType(org.apache.spark.sql.types.DecimalType) DirectDictionaryGenerator(org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)

Example 55 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class FilterUtil method getExcludeFilterExecutor.

/**
 * It gives filter executor based on columnar or column group
 *
 * @param dimColResolvedFilterInfo
 * @param segmentProperties
 * @return
 */
private static FilterExecutor getExcludeFilterExecutor(DimColumnResolvedFilterInfo dimColResolvedFilterInfo, MeasureColumnResolvedFilterInfo msrColResolvedFilterInfo, SegmentProperties segmentProperties) {
    if (null != msrColResolvedFilterInfo && msrColResolvedFilterInfo.getMeasure().isMeasure()) {
        CarbonMeasure measuresFromCurrentBlock = segmentProperties.getMeasureFromCurrentBlock(msrColResolvedFilterInfo.getMeasure());
        if (null != measuresFromCurrentBlock) {
            // update dimension and column index according to the dimension position in current block
            MeasureColumnResolvedFilterInfo msrColResolvedFilterInfoCopyObject = msrColResolvedFilterInfo.getCopyObject();
            msrColResolvedFilterInfoCopyObject.setMeasure(measuresFromCurrentBlock);
            msrColResolvedFilterInfoCopyObject.setColumnIndex(measuresFromCurrentBlock.getOrdinal());
            msrColResolvedFilterInfoCopyObject.setType(measuresFromCurrentBlock.getDataType());
            return new ExcludeFilterExecutorImpl(null, msrColResolvedFilterInfoCopyObject, segmentProperties, true);
        } else {
            return new RestructureExcludeFilterExecutorImpl(dimColResolvedFilterInfo, msrColResolvedFilterInfo, true);
        }
    }
    CarbonDimension dimensionFromCurrentBlock = segmentProperties.getDimensionFromCurrentBlock(dimColResolvedFilterInfo.getDimension());
    if (null != dimensionFromCurrentBlock) {
        // update dimension and column index according to the dimension position in current block
        DimColumnResolvedFilterInfo dimColResolvedFilterInfoCopyObject = dimColResolvedFilterInfo.getCopyObject();
        dimColResolvedFilterInfoCopyObject.setDimension(dimensionFromCurrentBlock);
        dimColResolvedFilterInfoCopyObject.setColumnIndex(dimensionFromCurrentBlock.getOrdinal());
        return new ExcludeFilterExecutorImpl(dimColResolvedFilterInfoCopyObject, null, segmentProperties, false);
    } else {
        return new RestructureExcludeFilterExecutorImpl(dimColResolvedFilterInfo, msrColResolvedFilterInfo, false);
    }
}
Also used : MeasureColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo) RestructureExcludeFilterExecutorImpl(org.apache.carbondata.core.scan.filter.executer.RestructureExcludeFilterExecutorImpl) ExcludeFilterExecutorImpl(org.apache.carbondata.core.scan.filter.executer.ExcludeFilterExecutorImpl) DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) RestructureExcludeFilterExecutorImpl(org.apache.carbondata.core.scan.filter.executer.RestructureExcludeFilterExecutorImpl) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Aggregations

CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)74 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)52 ArrayList (java.util.ArrayList)28 DataType (org.apache.carbondata.core.metadata.datatype.DataType)12 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)12 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)11 HashSet (java.util.HashSet)8 ProjectionMeasure (org.apache.carbondata.core.scan.model.ProjectionMeasure)8 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)7 BlockExecutionInfo (org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo)5 ProjectionDimension (org.apache.carbondata.core.scan.model.ProjectionDimension)5 SerializableComparator (org.apache.carbondata.core.util.comparator.SerializableComparator)5 MeasureInfo (org.apache.carbondata.core.scan.executor.infos.MeasureInfo)4 DimColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo)4 MeasureColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo)4 BitSet (java.util.BitSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)3 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)3