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;
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations