/** * returns level 2 or more child allDimensions * * @param dimName * @param dimensions * @return list of child allDimensions */ public List<CarbonDimension> getChildren(String dimName, List<CarbonDimension> dimensions) { for (CarbonDimension carbonDimension : dimensions) { if (carbonDimension.getColName().equals(dimName)) { return carbonDimension.getListOfChildDimensions(); } else if (null != carbonDimension.getListOfChildDimensions() && carbonDimension.getListOfChildDimensions().size() > 0) { List<CarbonDimension> childDims = getChildren(dimName, carbonDimension.getListOfChildDimensions()); if (childDims != null) { return childDims; } } } return null; }
/** * 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 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()); } } }
private static void fillCollumnSchemaListForComplexDims( List<CarbonDimension> carbonDimensionsList, List<ColumnSchema> wrapperColumnSchemaList) { for (CarbonDimension carbonDimension : carbonDimensionsList) { wrapperColumnSchemaList.add(carbonDimension.getColumnSchema()); List<CarbonDimension> childDims = carbonDimension.getListOfChildDimensions(); if (null != childDims && childDims.size() > 0) { fillCollumnSchemaListForComplexDims(childDims, wrapperColumnSchemaList); } } }
/** * 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; } }
/** * 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 * * @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()); } } }
/** * Below method will be used to get the dimension * * @param tableDimensionList table dimension list * @return boolean array specifying true if dimension is dictionary * and false if dimension is not a dictionary column */ public static boolean[] identifyDimensionType(List<CarbonDimension> tableDimensionList) { List<Boolean> isDictionaryDimensions = new ArrayList<Boolean>(); for (CarbonDimension carbonDimension : tableDimensionList) { List<CarbonDimension> childs = carbonDimension.getListOfChildDimensions(); //assuming complex dimensions will always be atlast if (null != childs && childs.size() > 0) { break; } if (hasEncoding(carbonDimension.getEncoder(), Encoding.DICTIONARY)) { isDictionaryDimensions.add(true); } else { isDictionaryDimensions.add(false); } } return ArrayUtils .toPrimitive(isDictionaryDimensions.toArray(new Boolean[isDictionaryDimensions.size()])); }
if (tableColumn instanceof CarbonDimension) { List<CarbonDimension> parentDimension = ((CarbonDimension) tableColumn).getListOfChildDimensions(); CarbonDimension carbonDimension = null; String[] colSplits = queryColumn.getColName().split("\\."); return true; if (carbonDimension.getListOfChildDimensions() != null) { parentDimension = carbonDimension.getListOfChildDimensions();
if (carbonDimension != null && carbonDimension.getListOfChildDimensions() != null) { dimList = carbonDimension.getListOfChildDimensions();
/** * 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); } } }
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; }
public static void getComplexNoDictionaryMapping(List<CarbonDimension> carbonDimensions, List<Integer> complexNoDictionary) { for (CarbonDimension carbonDimension : carbonDimensions) { if (carbonDimension.isComplex()) { getComplexNoDictionaryMapping(carbonDimension.getListOfChildDimensions(), complexNoDictionary); } else { // This is primitive type. Check the encoding for NoDictionary. if (!carbonDimension.hasEncoding(Encoding.DICTIONARY)) { complexNoDictionary.add(carbonDimension.getOrdinal()); } } } }
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; }
@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); } } }
public static void getComplexNoDictionaryMapping(DataField[] dataFields, List<Integer> complexNoDictionary) { // save the Ordinal Number in the List. for (DataField field : dataFields) { if (field.getColumn().isComplex()) { // get the childs. getComplexNoDictionaryMapping( ((CarbonDimension) field.getColumn()).getListOfChildDimensions(), complexNoDictionary); } } }
columnSchema.getSchemaOrdinal(), -1, -1); complexDimension.initializeChildDimensionsList(columnSchema.getNumberOfChild()); parentDimension.getListOfChildDimensions().add(complexDimension); dimensionOrdinal = readAllComplexTypeChildrens(dimensionOrdinal, columnSchema.getNumberOfChild(), new CarbonDimension(columnSchema, dimensionOrdinal++, columnSchema.getSchemaOrdinal(), -1, -1); parentDimension.getListOfChildDimensions().add(carbonDimension); primitiveDimensions.add(carbonDimension);
@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; } }