kumarvishal09 commented on a change in pull request #3444: [CARBONDATA-3581] Support page level bloom filter
URL: https://github.com/apache/carbondata/pull/3444#discussion_r349119775 ########## File path: core/src/main/java/org/apache/carbondata/core/bloom/ColumnPagesBloomFilter.java ########## @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.carbondata.core.bloom; + +import java.io.*; +import java.nio.ByteBuffer; +import java.util.*; + +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.format.PageBloomChunk; + +import org.apache.hadoop.util.bloom.BloomFilter; +import org.apache.hadoop.util.bloom.HashFunction; +import org.apache.hadoop.util.bloom.Key; +import org.apache.hadoop.util.hash.Hash; +import org.apache.log4j.Logger; +import org.roaringbitmap.RoaringBitmap; + +/** + * Store hash function parameters and bitmaps of each page for a column. + */ +public class ColumnPagesBloomFilter { + + private static final Logger LOGGER = + LogServiceFactory.getLogService(ColumnPagesBloomFilter.class.getName()); + + /** The vector size of page bloom filter. */ + private int vectorSize; + + /** The number of hash function to consider. */ + private short nbHash; + + /** Type of hashing function to use. */ + private short hashType; + + /** The hash function used to map a key to several positions in the vector. */ + protected HashFunction hash; + + private List<RoaringBitmap> pageBitmaps; + + private List<ByteBuffer> bloomByteBuffers; + + /** + * This constructor is used for building page blooms. + */ + public ColumnPagesBloomFilter() { + int[] bloomParas = BloomFilterUtil.getPageBloomParameters(); + this.vectorSize = bloomParas[0]; + this.nbHash = (short) bloomParas[1]; + this.hashType = Hash.MURMUR_HASH; + this.hash = new HashFunction(vectorSize, nbHash, hashType); + } + + /** + * This constructor is used for query. + * Only recover the bitmaps for necessary pages + */ + public ColumnPagesBloomFilter(PageBloomChunk pageBloomChunk) { + this.vectorSize = pageBloomChunk.getVector_size(); + this.nbHash = pageBloomChunk.getNum_hash(); + this.hashType = pageBloomChunk.getHash_type(); + this.hash = new HashFunction(vectorSize, nbHash, hashType); + this.bloomByteBuffers = pageBloomChunk.getPagebloom_list(); + } + + + public void addPageBloomFilter(BloomFilter bloomFilter) { + if (null == pageBitmaps) { + pageBitmaps = new ArrayList<>(); + } + try { + RoaringBitmap bitmap = BloomFilterUtil.convertBloomFilterToRoaringBitmap(bloomFilter); + pageBitmaps.add(bitmap); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + /** + * prune pages based on minmax result bitset + */ + public BitSet prunePages(byte[][] filterValues, BitSet minMaxBitSet) throws IOException { + // decode pages which is set to TRUE in minMaxBitSet + RoaringBitmap[] candidatePageBitmaps = new RoaringBitmap[minMaxBitSet.length()]; + int length = minMaxBitSet.cardinality(); + int nextSetBit = minMaxBitSet.nextSetBit(0); + for (int i = 0; i < length; ++i) { + byte[] bloomFilterInBytes = bloomByteBuffers.get(nextSetBit).array(); + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bloomFilterInBytes)); Review comment: Please add detail level comment for this logic ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |