use of org.apache.carbondata.core.scan.executor.infos.DimensionInfo in project carbondata by apache.
the class RestructureUtil method createDimensionInfoAndGetCurrentBlockQueryDimension.
/**
* Below method will be used to get the updated query dimension updation
* means, after restructuring some dimension will be not present in older
* table blocks in that case we need to select only those dimension out of
* query dimension which is present in the current table block
*
* @param blockExecutionInfo
* @param queryDimensions
* @param tableBlockDimensions
* @param tableComplexDimension
* @return list of query dimension which is present in the table block
*/
public static List<QueryDimension> createDimensionInfoAndGetCurrentBlockQueryDimension(BlockExecutionInfo blockExecutionInfo, List<QueryDimension> queryDimensions, List<CarbonDimension> tableBlockDimensions, List<CarbonDimension> tableComplexDimension) {
List<QueryDimension> presentDimension = new ArrayList<QueryDimension>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
boolean[] isDimensionExists = new boolean[queryDimensions.size()];
Object[] defaultValues = new Object[queryDimensions.size()];
// create dimension information instance
DimensionInfo dimensionInfo = new DimensionInfo(isDimensionExists, defaultValues);
int newDictionaryColumnCount = 0;
int newNoDictionaryColumnCount = 0;
// selecting only those dimension which is present in the query
int dimIndex = 0;
for (QueryDimension queryDimension : queryDimensions) {
if (queryDimension.getDimension().hasEncoding(Encoding.IMPLICIT)) {
presentDimension.add(queryDimension);
isDimensionExists[dimIndex] = true;
} else {
for (CarbonDimension tableDimension : tableBlockDimensions) {
if (tableDimension.getColumnId().equals(queryDimension.getDimension().getColumnId())) {
QueryDimension currentBlockDimension = new QueryDimension(tableDimension.getColName());
tableDimension.getColumnSchema().setDataType(queryDimension.getDimension().getDataType());
tableDimension.getColumnSchema().setPrecision(queryDimension.getDimension().getColumnSchema().getPrecision());
tableDimension.getColumnSchema().setScale(queryDimension.getDimension().getColumnSchema().getScale());
tableDimension.getColumnSchema().setDefaultValue(queryDimension.getDimension().getDefaultValue());
currentBlockDimension.setDimension(tableDimension);
currentBlockDimension.setQueryOrder(queryDimension.getQueryOrder());
presentDimension.add(currentBlockDimension);
isDimensionExists[dimIndex] = true;
break;
}
}
// if dimension is found then no need to search in the complex dimensions list
if (isDimensionExists[dimIndex]) {
dimIndex++;
continue;
}
for (CarbonDimension tableDimension : tableComplexDimension) {
if (tableDimension.getColumnId().equals(queryDimension.getDimension().getColumnId())) {
QueryDimension currentBlockDimension = new QueryDimension(tableDimension.getColName());
// TODO: for complex dimension set scale and precision by traversing
// the child dimensions
currentBlockDimension.setDimension(tableDimension);
currentBlockDimension.setQueryOrder(queryDimension.getQueryOrder());
presentDimension.add(currentBlockDimension);
isDimensionExists[dimIndex] = true;
break;
}
}
// add default value only in case query dimension is not found in the current block
if (!isDimensionExists[dimIndex]) {
defaultValues[dimIndex] = validateAndGetDefaultValue(queryDimension.getDimension());
blockExecutionInfo.setRestructuredBlock(true);
// newly added columns data need to be filled
if (queryDimension.getDimension().hasEncoding(Encoding.DICTIONARY)) {
dimensionInfo.setDictionaryColumnAdded(true);
newDictionaryColumnCount++;
} else {
dimensionInfo.setNoDictionaryColumnAdded(true);
newNoDictionaryColumnCount++;
}
}
}
dimIndex++;
}
dimensionInfo.setNewDictionaryColumnCount(newDictionaryColumnCount);
dimensionInfo.setNewNoDictionaryColumnCount(newNoDictionaryColumnCount);
blockExecutionInfo.setDimensionInfo(dimensionInfo);
return presentDimension;
}
Aggregations