private BitSet getFilteredIndexes( DimensionColumnDataChunk dimensionColumnDataChunk, int numerOfRows) { byte[] defaultValue = null; if (dimColEvaluatorInfoList.get(0).getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) { DirectDictionaryGenerator directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator( dimColEvaluatorInfoList.get(0).getDimension().getDataType()); int key = directDictionaryGenerator.generateDirectSurrogateKey(null) + 1; defaultValue = FilterUtil.getMaskKey( key, dimColEvaluatorInfoList.get(0).getDimension(), this.segmentProperties.getDimensionKeyGenerator()); } if (null != dimensionColumnDataChunk.getAttributes().getInvertedIndexes() && dimensionColumnDataChunk instanceof FixedLengthDimensionDataChunk) { return setFilterdIndexToBitSetWithColumnIndex( (FixedLengthDimensionDataChunk) dimensionColumnDataChunk, numerOfRows, defaultValue); } return setFilterdIndexToBitSet(dimensionColumnDataChunk, numerOfRows, defaultValue); }
/** * Method will scan the block and finds the range start index from which all members will be * considered for applying range filters. this method will be called if the column is sorted * default so column index mapping will be present for accesing the members from the block. * * @param dimensionColumnDataChunk * @param numerOfRows * @return BitSet. */ private BitSet setFilterdIndexToBitSet( DimensionColumnDataChunk dimensionColumnDataChunk, int numerOfRows, byte[] defaultValue) { BitSet bitSet = new BitSet(numerOfRows); if (dimensionColumnDataChunk instanceof FixedLengthDimensionDataChunk) { int start = 0; int last = 0; int startIndex = 0; int skip = 0; byte[][] filterValues = this.filterRangeValues; // find the number of default values to skip the null value in case of direct dictionary if (null != defaultValue) { start = CarbonUtil.getFirstIndexUsingBinarySearch( (FixedLengthDimensionDataChunk) dimensionColumnDataChunk, startIndex, numerOfRows - 1, defaultValue, false); if (start < 0) { skip = -(start + 1); // end of block if (skip == numerOfRows) { return bitSet; } } else { skip = start; } startIndex = skip; } for (int k = 0; k < filterValues.length; k++) { start = CarbonUtil.getFirstIndexUsingBinarySearch( (FixedLengthDimensionDataChunk) dimensionColumnDataChunk, startIndex, numerOfRows - 1, filterValues[k], false); start = CarbonUtil.nextLesserValueToTarget( start, (FixedLengthDimensionDataChunk) dimensionColumnDataChunk, filterValues[k]); if (start < 0) { start = -(start + 1); if (start >= numerOfRows) { start = numerOfRows - 1; } // Method will compare the tentative index value after binary search, this tentative // index needs to be compared by the filter member if its < filter then from that // index the bitset will be considered for filtering process. if (ByteUtil.compare(filterValues[k], dimensionColumnDataChunk.getChunkData(start)) < 0) { start = start - 1; } } last = start; for (int j = start; j >= skip; j--) { bitSet.set(j); last--; } startIndex = last; if (startIndex <= 0) { break; } } } return bitSet; }