private boolean checkForChildColumns(CarbonDimension parentDimension, CarbonDimension childDimension) { boolean output = false; if (parentDimension.getOrdinal() == childDimension.getOrdinal()) { output = true; } else if (parentDimension.getNumberOfChild() > 0) { for (int i = 0; i < parentDimension.getNumberOfChild() && !output; i++) { output = checkForChildColumns(parentDimension.getListOfChildDimensions().get(i), childDimension); } } else { output = false; } return output; }
/** * Below method will be used to add the children block index * this will be basically for complex dimension which will have children * * @param blockIndexes block indexes * @param dimension parent dimension */ private static void addChildrenBlockIndex(Set<Integer> blockIndexes, CarbonDimension dimension) { for (int i = 0; i < dimension.getNumberOfChild(); i++) { addChildrenBlockIndex(blockIndexes, dimension.getListOfChildDimensions().get(i)); blockIndexes.add(dimension.getListOfChildDimensions().get(i).getOrdinal()); } }
/** * Below method will be used to add the complex dimension child * block index.It is a recursive method which will be get the children * add the block index * * @param blockOrdinal start block ordinal * @param dimension parent dimension * @return last block index */ private int fillComplexDimensionChildBlockIndex(int blockOrdinal, CarbonDimension dimension) { for (int i = 0; i < dimension.getNumberOfChild(); i++) { dimensionOrdinalToChunkMapping .put(dimension.getListOfChildDimensions().get(i).getOrdinal(), ++blockOrdinal); if (dimension.getListOfChildDimensions().get(i).getNumberOfChild() > 0) { blockOrdinal = fillComplexDimensionChildBlockIndex(blockOrdinal, dimension.getListOfChildDimensions().get(i)); } } return blockOrdinal; }
/** * Below method will be used to fill the children dimension column id */ private static void getChildDimensionOrdinal(CarbonDimension queryDimensions, Set<Integer> filterDimensionsOrdinal) { for (int j = 0; j < queryDimensions.getNumberOfChild(); j++) { List<Encoding> encodingList = queryDimensions.getListOfChildDimensions().get(j).getEncoder(); if (queryDimensions.getListOfChildDimensions().get(j).getNumberOfChild() > 0) { getChildDimensionOrdinal(queryDimensions.getListOfChildDimensions().get(j), filterDimensionsOrdinal); } else if (!CarbonUtil.hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY)) { filterDimensionsOrdinal.add(queryDimensions.getListOfChildDimensions().get(j).getOrdinal()); } } }
/** * Read all primitive/complex children and set it as list of child carbon dimension to parent * dimension */ private int assignComplexOrdinal(CarbonDimension parentDimension, int complexDimensionOrdinal) { for (int i = 0; i < parentDimension.getNumberOfChild(); i++) { CarbonDimension dimension = parentDimension.getListOfChildDimensions().get(i); if (dimension.getNumberOfChild() > 0) { dimension.setComplexTypeOridnal(++complexDimensionOrdinal); complexDimensionOrdinal = assignComplexOrdinal(dimension, complexDimensionOrdinal); } else { parentDimension.getListOfChildDimensions().get(i) .setComplexTypeOridnal(++complexDimensionOrdinal); } } return complexDimensionOrdinal; }
/** * Read all primitive/complex children and set it as list of child carbon dimension to parent * dimension */ private int assignComplexOrdinal(CarbonDimension parentDimension, int complexDimensionOrdianl) { for (int i = 0; i < parentDimension.getNumberOfChild(); i++) { CarbonDimension dimension = parentDimension.getListOfChildDimensions().get(i); if (dimension.getNumberOfChild() > 0) { dimension.setComplexTypeOridnal(++complexDimensionOrdianl); complexDimensionOrdianl = assignComplexOrdinal(dimension, complexDimensionOrdianl); } else { parentDimension.getListOfChildDimensions().get(i) .setComplexTypeOridnal(++complexDimensionOrdianl); } } return complexDimensionOrdianl; }
/** * This method will return all the child dimensions under complex dimension */ private static void addAllComplexTypeChildren(CarbonDimension dimension, StringBuilder dimString, String parent) { dimString.append(dimension.getColName()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(dimension.getDataType()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(parent).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(isDictionaryType(dimension)).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(dimension.getColumnId()).append(CarbonCommonConstants.HASH_SPC_CHARACTER); for (int i = 0; i < dimension.getNumberOfChild(); i++) { CarbonDimension childDim = dimension.getListOfChildDimensions().get(i); if (childDim.getNumberOfChild() > 0) { addAllComplexTypeChildren(childDim, dimString, dimension.getColName()); } else { dimString.append(childDim.getColName()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(childDim.getDataType()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(dimension.getColName()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(isDictionaryType(dimension)).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(childDim.getColumnId()).append(CarbonCommonConstants.COLON_SPC_CHARACTER) .append(childDim.getOrdinal()).append(CarbonCommonConstants.HASH_SPC_CHARACTER); } } }
/** * Below method will be used to get the dimension based on column identifier * for complex dimension children * * @param columnIdentifier column identifier * @param dimension parent dimension * @return children dimension */ private CarbonDimension getCarbonChildDimsBasedOnColIdentifier(String columnIdentifier, CarbonDimension dimension) { for (int i = 0; i < dimension.getNumberOfChild(); i++) { if (dimension.getListOfChildDimensions().get(i).getColumnId() .equalsIgnoreCase(columnIdentifier)) { return dimension.getListOfChildDimensions().get(i); } else if (dimension.getListOfChildDimensions().get(i).getNumberOfChild() > 0) { CarbonDimension childDim = getCarbonChildDimsBasedOnColIdentifier(columnIdentifier, dimension.getListOfChildDimensions().get(i)); if (null != childDim) { return childDim; } } } return null; } }
public static void getAllFilterDimensionsAndMeasures(FilterResolverIntf filterResolverTree, Set<CarbonDimension> filterDimensions, Set<CarbonMeasure> filterMeasure) { if (null == filterResolverTree) { return; } List<ColumnExpression> dimensionResolvedInfos = new ArrayList<ColumnExpression>(); Expression filterExpression = filterResolverTree.getFilterExpression(); addColumnDimensions(filterExpression, filterDimensions, filterMeasure); for (ColumnExpression info : dimensionResolvedInfos) { if (info.isDimension() && info.getDimension().getNumberOfChild() > 0) { filterDimensions.add(info.getDimension()); } } }
private CarbonDimension getDimensionBasedOnOrdinal(List<CarbonDimension> dimList, Integer ordinal) { for (CarbonDimension dims : dimList) { if (dims.getOrdinal() == ordinal) { return dims; } else if (dims.getNumberOfChild() > 0) { CarbonDimension dimensionBasedOnOrdinal = getDimensionBasedOnOrdinal(dims.getListOfChildDimensions(), ordinal); if (null != dimensionBasedOnOrdinal) { return dimensionBasedOnOrdinal; } } } return null; }
@Override public Object getDataBasedOnColumnList(Map<CarbonDimension, ByteBuffer> childBuffer, CarbonDimension presentColumn) { // Traverse through the Complex Tree and check if the at present column is same as the // column present in the child column then fill it up else add null to the column. if (childBuffer.get(presentColumn) != null) { if (presentColumn.getNumberOfChild() > 0) { // This is complex Column. And all its child will be present in the corresponding data // buffer. Object field = getDataBasedOnDataType(childBuffer.get(presentColumn)); return field; } else { // This is a child column with with primitive data type. Object field = children.get(0) .getDataBasedOnColumn(childBuffer.get(presentColumn), presentColumn, presentColumn); return field; } } else { int childLength; childLength = presentColumn.getNumberOfChild(); Object[] fields = new Object[childLength]; for (int i = 0; i < childLength; i++) { fields[i] = children.get(i) .getDataBasedOnColumnList(childBuffer, presentColumn.getListOfChildDimensions().get(i)); } return DataTypeUtil.getDataTypeConverter().wrapWithGenericRow(fields); } } }
/** * Below method will be used to fill the children dimension column id * * @param queryDimensions query dimension * @param dictionaryDimensionFromQuery dictionary dimension for query */ private static void getChildDimensionDictionaryDetail(CarbonDimension queryDimensions, Set<String> dictionaryDimensionFromQuery) { for (int j = 0; j < queryDimensions.getNumberOfChild(); j++) { List<Encoding> encodingList = queryDimensions.getListOfChildDimensions().get(j).getEncoder(); if (queryDimensions.getListOfChildDimensions().get(j).getNumberOfChild() > 0) { getChildDimensionDictionaryDetail(queryDimensions.getListOfChildDimensions().get(j), dictionaryDimensionFromQuery); } else if (CarbonUtil.hasEncoding(encodingList, Encoding.DICTIONARY) && !CarbonUtil .hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY)) { dictionaryDimensionFromQuery .add(queryDimensions.getListOfChildDimensions().get(j).getColumnId()); } } }
int counter = 0; while (counter < queryDimension.size()) { if (queryDimension.get(counter).getDimension().getNumberOfChild() > 0) { counter += queryDimension.get(counter).getDimension().getNumberOfChild(); } else if (!CarbonUtil.hasEncoding(queryDimension.get(counter).getDimension().getEncoder(), Encoding.DICTIONARY)) {
.hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY) && !CarbonUtil .hasEncoding(encodingList, Encoding.IMPLICIT) && queryDimensions.get(i).getDimension().getNumberOfChild() > 0) { getChildDimensionDictionaryDetail(queryDimensions.get(i).getDimension(), dictionaryDimensionFromQuery); CarbonDimension filterDim = iterator.next(); if (filterDim.getNumberOfChild() > 0) { getChildDimensionDictionaryDetail(filterDim, dictionaryDimensionFromQuery);
/** * method will return dimension instance based on the column identifier * and table instance passed to it. * * @param carbonTable * @param columnIdentifier * @return CarbonDimension instance */ public CarbonDimension getCarbonDimensionBasedOnColIdentifier(CarbonTable carbonTable, String columnIdentifier) { List<CarbonDimension> listOfCarbonDims = carbonTable.getDimensionByTableName(carbonTable.getTableName()); for (CarbonDimension dimension : listOfCarbonDims) { if (dimension.getColumnId().equalsIgnoreCase(columnIdentifier)) { return dimension; } if (dimension.getNumberOfChild() > 0) { CarbonDimension childDim = getCarbonChildDimsBasedOnColIdentifier(columnIdentifier, dimension); if (null != childDim) { return childDim; } } } return null; }
} else if (DataTypes.isStructType(type)) { Map<String, Object> childFieldsMap = (Map<String, Object>) childObject; int size = column.getNumberOfChild(); Object[] structChildObjects = new Object[size]; for (int i = 0; i < size; i++) {
/** * Below method will be used to fill block indexes of the query dimension * which will be used in creating a output row Here is method we are passing * two list which store the indexes one for dictionary column other for not * dictionary column. This is done for specific purpose so that in one * iteration we will be able to fill both type dimension block indexes * * @param projectDimensions dimension present in the query * @param columnOrdinalToChunkIndexMapping column ordinal to block index mapping * @param dictionaryDimensionChunkIndex list to store dictionary column block indexes * @param noDictionaryDimensionChunkIndex list to store no dictionary block indexes */ public static void fillQueryDimensionChunkIndexes( List<ProjectionDimension> projectDimensions, Map<Integer, Integer> columnOrdinalToChunkIndexMapping, Set<Integer> dictionaryDimensionChunkIndex, List<Integer> noDictionaryDimensionChunkIndex) { for (ProjectionDimension queryDimension : projectDimensions) { if (CarbonUtil.hasEncoding(queryDimension.getDimension().getEncoder(), Encoding.DICTIONARY) && queryDimension.getDimension().getNumberOfChild() == 0) { dictionaryDimensionChunkIndex .add(columnOrdinalToChunkIndexMapping.get(queryDimension.getDimension().getOrdinal())); } else if ( !CarbonUtil.hasEncoding(queryDimension.getDimension().getEncoder(), Encoding.IMPLICIT) && queryDimension.getDimension().getNumberOfChild() == 0) { noDictionaryDimensionChunkIndex .add(columnOrdinalToChunkIndexMapping.get(queryDimension.getDimension().getOrdinal())); } } }
} else if (DataTypes.isStructType(type)) { CarbonDimension carbonDimension = (CarbonDimension) column; int size = carbonDimension.getNumberOfChild(); Map<String, Object> jsonMap = (Map<String, Object>) jsonNodeMap.get(extractChildColumnName(column));
@Override public Object getDataBasedOnColumn(ByteBuffer dataBuffer, CarbonDimension parent, CarbonDimension child) { int childLength; if (parent.getOrdinal() < child.getOrdinal()) { childLength = parent.getNumberOfChild(); Object[] fields = new Object[childLength]; for (int i = 0; i < childLength; i++) { fields[i] = children.get(i) .getDataBasedOnColumn(dataBuffer, parent.getListOfChildDimensions().get(i), child); } return DataTypeUtil.getDataTypeConverter().wrapWithGenericRow(fields); } else if (parent.getOrdinal() > child.getOrdinal()) { return null; } else { // childLength = dataBuffer.getShort(); Object field = getDataBasedOnDataType(dataBuffer); return field; } }
actualDimension = dimension.getDimension(); if (actualDimension.getNumberOfChild() == 0) { continue; || filterDimension.getNumberOfChild() == 0) { continue;