carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipesala <...@git.apache.org>
Subject [GitHub] carbondata pull request #1079: [WIP]Measure Filter implementation
Date Sat, 01 Jul 2017 04:13:57 GMT
Github user ravipesala commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1079#discussion_r125154170
  
    --- Diff: core/src/main/java/org/apache/carbondata/core/scan/filter/executer/RowLevelRangeGrtThanFiterExecuterImpl.java
---
    @@ -74,80 +87,205 @@ private void ifDefaultValueMatchesFilter() {
               }
             }
           }
    +    } else if (!msrColEvalutorInfoList.isEmpty() && !isMeasurePresentInCurrentBlock[0])
{
    +      CarbonMeasure measure = this.msrColEvalutorInfoList.get(0).getMeasure();
    +      byte[] defaultValue = measure.getDefaultValue();
    +      if (null != defaultValue) {
    +        for (int k = 0; k < filterRangeValues.length; k++) {
    +          int maxCompare =
    +              ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterRangeValues[k], defaultValue);
    +          if (maxCompare < 0) {
    +            isDefaultValuePresentInFilter = true;
    +            break;
    +          }
    +        }
    +      }
         }
       }
     
       @Override public BitSet isScanRequired(byte[][] blockMaxValue, byte[][] blockMinValue)
{
         BitSet bitSet = new BitSet(1);
    -    boolean isScanRequired =
    -        isScanRequired(blockMaxValue[dimensionBlocksIndex[0]], filterRangeValues);
    +    boolean isScanRequired = false;
    +    byte[] maxValue = null;
    +    if (isMeasurePresentInCurrentBlock[0] || isDimensionPresentInCurrentBlock[0]) {
    +      if (isMeasurePresentInCurrentBlock[0]) {
    +        maxValue = blockMaxValue[measureBlocksIndex[0] + lastDimensionColOrdinal];
    +        isScanRequired =
    +            isScanRequired(maxValue, filterRangeValues, msrColEvalutorInfoList.get(0).getType());
    +      } else {
    +        maxValue = blockMaxValue[dimensionBlocksIndex[0]];
    +        isScanRequired = isScanRequired(maxValue, filterRangeValues);
    +      }
    +    } else {
    +      isScanRequired = isDefaultValuePresentInFilter;
    +    }
    +
         if (isScanRequired) {
           bitSet.set(0);
         }
         return bitSet;
       }
     
    +
       private boolean isScanRequired(byte[] blockMaxValue, byte[][] filterValues) {
         boolean isScanRequired = false;
    -    if (isDimensionPresentInCurrentBlock[0]) {
    -      for (int k = 0; k < filterValues.length; k++) {
    -        // filter value should be in range of max and min value i.e
    -        // max>filtervalue>min
    -        // so filter-max should be negative
    -        int maxCompare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterValues[k],
blockMaxValue);
    -        // if any filter value is in range than this block needs to be
    -        // scanned means always less than block max range.
    -        if (maxCompare < 0) {
    -          isScanRequired = true;
    -          break;
    -        }
    +    for (int k = 0; k < filterValues.length; k++) {
    +      // filter value should be in range of max and min value i.e
    +      // max>filtervalue>min
    +      // so filter-max should be negative
    +      int maxCompare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterValues[k], blockMaxValue);
    +      // if any filter value is in range than this block needs to be
    +      // scanned less than equal to max range.
    +      if (maxCompare < 0) {
    +        isScanRequired = true;
    +        break;
           }
    -    } else {
    -      isScanRequired = isDefaultValuePresentInFilter;
         }
         return isScanRequired;
       }
     
    +  private boolean isScanRequired(byte[] maxValue, byte[][] filterValue,
    +      DataType dataType) {
    +    for (int i = 0; i < filterValue.length; i++) {
    +      if (filterValue[i].length == 0 || maxValue.length == 0) {
    +        return isScanRequired(maxValue, filterValue);
    +      }
    +      switch (dataType) {
    +        case DOUBLE:
    +          double maxValueDouble = ByteBuffer.wrap(maxValue).getDouble();
    +          double filterValueDouble = ByteBuffer.wrap(filterValue[i]).getDouble();
    +          if (filterValueDouble < maxValueDouble) {
    +            return true;
    +          }
    +          break;
    +        case INT:
    +        case SHORT:
    +        case LONG:
    +          long maxValueLong = ByteBuffer.wrap(maxValue).getLong();
    +          long filterValueLong = ByteBuffer.wrap(filterValue[i]).getLong();
    +          if (filterValueLong < maxValueLong) {
    +            return true;
    +          }
    +          break;
    +        case DECIMAL:
    +          BigDecimal maxDecimal = DataTypeUtil.byteToBigDecimal(maxValue);
    +          BigDecimal filterDecimal = DataTypeUtil.byteToBigDecimal(filterValue[i]);
    +          if (filterDecimal.compareTo(maxDecimal) < 0) {
    +            return true;
    +          }
    +      }
    +    }
    +    return false;
    +  }
    +
       @Override public BitSetGroup applyFilter(BlocksChunkHolder blockChunkHolder)
           throws FilterUnsupportedException, IOException {
         // select all rows if dimension does not exists in the current block
    -    if (!isDimensionPresentInCurrentBlock[0]) {
    +    if (!isDimensionPresentInCurrentBlock[0] && !isMeasurePresentInCurrentBlock[0])
{
           int numberOfRows = blockChunkHolder.getDataBlock().nodeSize();
           return FilterUtil
               .createBitSetGroupWithDefaultValue(blockChunkHolder.getDataBlock().numberOfPages(),
                   numberOfRows, true);
         }
    -    int blockIndex =
    -        segmentProperties.getDimensionOrdinalToBlockMapping().get(dimensionBlocksIndex[0]);
    -    if (null == blockChunkHolder.getDimensionRawDataChunk()[blockIndex]) {
    -      blockChunkHolder.getDimensionRawDataChunk()[blockIndex] = blockChunkHolder.getDataBlock()
    -          .getDimensionChunk(blockChunkHolder.getFileReader(), blockIndex);
    -    }
    -    DimensionRawColumnChunk rawColumnChunk =
    -        blockChunkHolder.getDimensionRawDataChunk()[blockIndex];
    -    BitSetGroup bitSetGroup = new BitSetGroup(rawColumnChunk.getPagesCount());
    -    for (int i = 0; i < rawColumnChunk.getPagesCount(); i++) {
    -      if (rawColumnChunk.getMaxValues() != null) {
    -        if (isScanRequired(rawColumnChunk.getMaxValues()[i], this.filterRangeValues))
{
    -          int compare = ByteUtil.UnsafeComparer.INSTANCE
    -              .compareTo(filterRangeValues[0], rawColumnChunk.getMinValues()[i]);
    -          if (compare < 0) {
    -            BitSet bitSet = new BitSet(rawColumnChunk.getRowCount()[i]);
    -            bitSet.flip(0, rawColumnChunk.getRowCount()[i]);
    -            bitSetGroup.setBitSet(bitSet, i);
    -          } else {
    -            BitSet bitSet = getFilteredIndexes(rawColumnChunk.convertToDimColDataChunk(i),
    -                rawColumnChunk.getRowCount()[i]);
    -            bitSetGroup.setBitSet(bitSet, i);
    +    if (isDimensionPresentInCurrentBlock[0]) {
    +      int blockIndex =
    +          segmentProperties.getDimensionOrdinalToBlockMapping().get(dimensionBlocksIndex[0]);
    +      if (null == blockChunkHolder.getDimensionRawDataChunk()[blockIndex]) {
    +        blockChunkHolder.getDimensionRawDataChunk()[blockIndex] = blockChunkHolder.getDataBlock()
    +            .getDimensionChunk(blockChunkHolder.getFileReader(), blockIndex);
    +      }
    +      DimensionRawColumnChunk rawColumnChunk =
    +          blockChunkHolder.getDimensionRawDataChunk()[blockIndex];
    +      BitSetGroup bitSetGroup = new BitSetGroup(rawColumnChunk.getPagesCount());
    +      for (int i = 0; i < rawColumnChunk.getPagesCount(); i++) {
    +        if (rawColumnChunk.getMaxValues() != null) {
    +          if (isScanRequired(rawColumnChunk.getMaxValues()[i], this.filterRangeValues))
{
    +            int compare = ByteUtil.UnsafeComparer.INSTANCE
    +                .compareTo(filterRangeValues[0], rawColumnChunk.getMinValues()[i]);
    +            if (compare < 0) {
    +              BitSet bitSet = new BitSet(rawColumnChunk.getRowCount()[i]);
    +              bitSet.flip(0, rawColumnChunk.getRowCount()[i]);
    +              bitSetGroup.setBitSet(bitSet, i);
    +            } else {
    +              BitSet bitSet = getFilteredIndexes(rawColumnChunk.convertToDimColDataChunk(i),
    +                  rawColumnChunk.getRowCount()[i]);
    +              bitSetGroup.setBitSet(bitSet, i);
    +            }
               }
    +        } else {
    +          BitSet bitSet = getFilteredIndexes(rawColumnChunk.convertToDimColDataChunk(i),
    +              rawColumnChunk.getRowCount()[i]);
    +          bitSetGroup.setBitSet(bitSet, i);
    +        }
    +      }
    +      return bitSetGroup;
    +    } else if (isMeasurePresentInCurrentBlock[0]) {
    +      int blockIndex =
    +          segmentProperties.getMeasuresOrdinalToBlockMapping().get(measureBlocksIndex[0]);
    +      if (null == blockChunkHolder.getMeasureRawDataChunk()[blockIndex]) {
    +        blockChunkHolder.getMeasureRawDataChunk()[blockIndex] = blockChunkHolder.getDataBlock()
    +            .getMeasureChunk(blockChunkHolder.getFileReader(), blockIndex);
    +      }
    +      MeasureRawColumnChunk rawColumnChunk = blockChunkHolder.getMeasureRawDataChunk()[blockIndex];
    +      BitSetGroup bitSetGroup = new BitSetGroup(rawColumnChunk.getPagesCount());
    +      for (int i = 0; i < rawColumnChunk.getPagesCount(); i++) {
    +        if (rawColumnChunk.getMaxValues() != null) {
    +          if (isScanRequired(rawColumnChunk.getMaxValues()[i], this.filterRangeValues,
    +              msrColEvalutorInfoList.get(0).getType())) {
    +            int compare = ByteUtil.UnsafeComparer.INSTANCE
    --- End diff --
    
    This binary comparison cannot be used for measures, compare actual values


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message