use of com.linkedin.pinot.core.startree.StarTreeIndexNode in project pinot by linkedin.
the class SegmentIndexCreationDriverImpl method serializeTree.
private void serializeTree(StarTreeBuilder starTreeBuilder, boolean enableOffHeapFormat) throws Exception {
//star tree was built using its own dictionary, we need to re-map dimension value id
Map<String, HashBiMap<Object, Integer>> dictionaryMap = starTreeBuilder.getDictionaryMap();
StarTree tree = starTreeBuilder.getTree();
HashBiMap<String, Integer> dimensionNameToIndexMap = starTreeBuilder.getDimensionNameToIndexMap();
StarTreeIndexNode node = (StarTreeIndexNode) tree.getRoot();
updateTree(node, dictionaryMap, dimensionNameToIndexMap);
File starTreeFile = new File(tempIndexDir, V1Constants.STAR_TREE_INDEX_FILE);
if (enableOffHeapFormat) {
StarTreeSerDe.writeTreeOffHeapFormat(tree, starTreeFile);
} else {
StarTreeSerDe.writeTreeOnHeapFormat(tree, starTreeFile);
}
}
use of com.linkedin.pinot.core.startree.StarTreeIndexNode in project pinot by linkedin.
the class SegmentIndexCreationDriverImpl method updateTree.
/**
* Startree built its only dictionary that is different from the columnar segment dictionary.
* This method updates the tree with new mapping
* @param node
* @param dictionaryMap
* @param dimensionNameToIndexMap
*/
private void updateTree(StarTreeIndexNode node, Map<String, HashBiMap<Object, Integer>> dictionaryMap, HashBiMap<String, Integer> dimensionNameToIndexMap) {
//current node needs to update only if its not star
if (node.getDimensionName() != StarTreeIndexNodeInterf.ALL) {
String dimName = dimensionNameToIndexMap.inverse().get(node.getDimensionName());
int dimensionValue = node.getDimensionValue();
if (dimensionValue != StarTreeIndexNodeInterf.ALL) {
Object sortedValuesForDim = indexCreationInfoMap.get(dimName).getSortedUniqueElementsArray();
int indexForDimValue = searchValueInArray(sortedValuesForDim, dictionaryMap.get(dimName).inverse().get(dimensionValue));
node.setDimensionValue(indexForDimValue);
}
}
//update children map
Iterator<StarTreeIndexNode> childrenIterator = node.getChildrenIterator();
if (childrenIterator.hasNext()) {
Map<Integer, StarTreeIndexNode> newChildren = new HashMap<>();
String childDimName = dimensionNameToIndexMap.inverse().get(node.getChildDimensionName());
Object sortedValuesForDim = indexCreationInfoMap.get(childDimName).getSortedUniqueElementsArray();
while (childrenIterator.hasNext()) {
StarTreeIndexNode child = childrenIterator.next();
int childDimValue = child.getDimensionValue();
int childMappedDimValue = StarTreeIndexNodeInterf.ALL;
if (childDimValue != StarTreeIndexNodeInterf.ALL) {
childMappedDimValue = searchValueInArray(sortedValuesForDim, dictionaryMap.get(childDimName).inverse().get(childDimValue));
}
newChildren.put(childMappedDimValue, child);
updateTree(child, dictionaryMap, dimensionNameToIndexMap);
}
node.setChildren(newChildren);
}
}
Aggregations