Search in sources :

Example 51 with RowImpl

use of org.apache.carbondata.core.scan.filter.intf.RowImpl in project carbondata by apache.

the class FilterUtil method getFilterListForAllMembersRS.

/**
   * This method will get the member based on filter expression evaluation from the
   * forward dictionary cache, this method will be basically used in restructure.
   *
   * @param expression
   * @param columnExpression
   * @param defaultValues
   * @param defaultSurrogate
   * @param isIncludeFilter
   * @return
   * @throws FilterUnsupportedException
   */
public static DimColumnFilterInfo getFilterListForAllMembersRS(Expression expression, ColumnExpression columnExpression, String defaultValues, int defaultSurrogate, boolean isIncludeFilter) throws FilterUnsupportedException {
    List<Integer> filterValuesList = new ArrayList<Integer>(20);
    List<String> evaluateResultListFinal = new ArrayList<String>(20);
    DimColumnFilterInfo columnFilterInfo = null;
    // KeyGeneratorFactory.getKeyGenerator(new int[] { defaultSurrogate });
    try {
        RowIntf row = new RowImpl();
        if (defaultValues.equals(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
            defaultValues = null;
        }
        row.setValues(new Object[] { DataTypeUtil.getDataBasedOnDataType(defaultValues, columnExpression.getCarbonColumn().getDataType()) });
        Boolean rslt = expression.evaluate(row).getBoolean();
        if (null != rslt && rslt == isIncludeFilter) {
            if (null == defaultValues) {
                evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
            } else {
                evaluateResultListFinal.add(defaultValues);
            }
        }
    } catch (FilterIllegalMemberException e) {
        LOGGER.audit(e.getMessage());
    }
    if (null == defaultValues) {
        defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL;
    }
    columnFilterInfo = new DimColumnFilterInfo();
    for (int i = 0; i < evaluateResultListFinal.size(); i++) {
        if (evaluateResultListFinal.get(i).equals(defaultValues)) {
            filterValuesList.add(defaultSurrogate);
            break;
        }
    }
    columnFilterInfo.setFilterList(filterValuesList);
    return columnFilterInfo;
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ArrayList(java.util.ArrayList) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 52 with RowImpl

use of org.apache.carbondata.core.scan.filter.intf.RowImpl in project carbondata by apache.

the class FilterUtil method getFilterListForAllValues.

/**
   * This method will get all the members of column from the forward dictionary
   * cache, this method will be basically used in row level filter resolver.
   *
   * @param tableIdentifier
   * @param expression
   * @param columnExpression
   * @param isIncludeFilter
   * @return DimColumnFilterInfo
   * @throws FilterUnsupportedException
   * @throws IOException
   */
public static DimColumnFilterInfo getFilterListForAllValues(AbsoluteTableIdentifier tableIdentifier, Expression expression, final ColumnExpression columnExpression, boolean isIncludeFilter) throws IOException, FilterUnsupportedException {
    Dictionary forwardDictionary = null;
    List<String> evaluateResultListFinal = new ArrayList<String>(20);
    DictionaryChunksWrapper dictionaryWrapper = null;
    try {
        forwardDictionary = getForwardDictionaryCache(tableIdentifier, columnExpression.getDimension());
        dictionaryWrapper = forwardDictionary.getDictionaryChunks();
        while (dictionaryWrapper.hasNext()) {
            byte[] columnVal = dictionaryWrapper.next();
            try {
                RowIntf row = new RowImpl();
                String stringValue = new String(columnVal, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
                if (stringValue.equals(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
                    stringValue = null;
                }
                row.setValues(new Object[] { DataTypeUtil.getDataBasedOnDataType(stringValue, columnExpression.getCarbonColumn().getDataType()) });
                Boolean rslt = expression.evaluate(row).getBoolean();
                if (null != rslt && rslt == isIncludeFilter) {
                    if (null == stringValue) {
                        evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                    } else {
                        evaluateResultListFinal.add(stringValue);
                    }
                }
            } catch (FilterIllegalMemberException e) {
                LOGGER.debug(e.getMessage());
            }
        }
        return getFilterValues(columnExpression, evaluateResultListFinal, forwardDictionary, isIncludeFilter);
    } finally {
        CarbonUtil.clearDictionaryCache(forwardDictionary);
    }
}
Also used : Dictionary(org.apache.carbondata.core.cache.dictionary.Dictionary) ForwardDictionary(org.apache.carbondata.core.cache.dictionary.ForwardDictionary) RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ArrayList(java.util.ArrayList) DictionaryChunksWrapper(org.apache.carbondata.core.cache.dictionary.DictionaryChunksWrapper) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 53 with RowImpl

use of org.apache.carbondata.core.scan.filter.intf.RowImpl in project carbondata by apache.

the class RowLevelFilterExecuterImpl method applyFilter.

@Override
public BitSetGroup applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException, IOException {
    readBlocks(blockChunkHolder);
    // CHECKSTYLE:ON
    int[] numberOfRows = null;
    int pageNumbers = 0;
    if (dimColEvaluatorInfoList.size() > 0) {
        if (isDimensionPresentInCurrentBlock[0]) {
            pageNumbers = blockChunkHolder.getDimensionRawDataChunk()[dimensionBlocksIndex[0]].getPagesCount();
            numberOfRows = blockChunkHolder.getDimensionRawDataChunk()[dimensionBlocksIndex[0]].getRowCount();
        } else {
            // specific for restructure case where default values need to be filled
            pageNumbers = blockChunkHolder.getDataBlock().numberOfPages();
            numberOfRows = new int[] { blockChunkHolder.getDataBlock().nodeSize() };
        }
    }
    if (msrColEvalutorInfoList.size() > 0) {
        if (isMeasurePresentInCurrentBlock[0]) {
            pageNumbers = blockChunkHolder.getMeasureRawDataChunk()[measureBlocksIndex[0]].getPagesCount();
            numberOfRows = blockChunkHolder.getMeasureRawDataChunk()[measureBlocksIndex[0]].getRowCount();
        } else {
            // specific for restructure case where default values need to be filled
            pageNumbers = blockChunkHolder.getDataBlock().numberOfPages();
            numberOfRows = new int[] { blockChunkHolder.getDataBlock().nodeSize() };
        }
    }
    BitSetGroup bitSetGroup = new BitSetGroup(pageNumbers);
    for (int i = 0; i < pageNumbers; i++) {
        BitSet set = new BitSet(numberOfRows[i]);
        RowIntf row = new RowImpl();
        boolean invalidRowsPresent = false;
        for (int index = 0; index < numberOfRows[i]; index++) {
            createRow(blockChunkHolder, row, i, index);
            Boolean rslt = false;
            try {
                rslt = exp.evaluate(row).getBoolean();
            }// too much log inforation only once the log will be printed.
             catch (FilterIllegalMemberException e) {
                FilterUtil.logError(e, invalidRowsPresent);
            }
            if (null != rslt && rslt) {
                set.set(index);
            }
        }
        bitSetGroup.setBitSet(set, i);
    }
    return bitSetGroup;
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) BitSetGroup(org.apache.carbondata.core.util.BitSetGroup) BitSet(java.util.BitSet) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 54 with RowImpl

use of org.apache.carbondata.core.scan.filter.intf.RowImpl in project carbondata by apache.

the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithShortDataType.

@Test
public void testEvaluateForLessThanEqualToExpressionWithShortDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("id", DataType.SHORT);
    left.setColIndex(1);
    lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
    RowImpl value = new RowImpl();
    Short[] row = { 1550 };
    Short[] row1 = { 3365 };
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public Short getShort() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return 1550;
            } else {
                return 3365;
            }
        }
    };
    ExpressionResult result = lessThanEqualToExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 55 with RowImpl

use of org.apache.carbondata.core.scan.filter.intf.RowImpl in project carbondata by apache.

the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithDecimalDataType.

@Test
public void testEvaluateForLessThanEqualToExpressionWithDecimalDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL);
    left.setColIndex(1);
    lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
    RowImpl value = new RowImpl();
    Decimal[] row = new Decimal[] { Decimal.apply(46851.2) };
    Decimal[] row1 = new Decimal[] { Decimal.apply(45821.02) };
    Object[] objectRow = { row1, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public BigDecimal getDecimal() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return new BigDecimal(45821.02);
            } else {
                return new BigDecimal(46851.2);
            }
        }
    };
    ExpressionResult result = lessThanEqualToExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) Decimal(org.apache.spark.sql.types.Decimal) BigDecimal(java.math.BigDecimal) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)95 Test (org.junit.Test)92 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)83 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)81 MockUp (mockit.MockUp)80 BigDecimal (java.math.BigDecimal)8 Timestamp (java.sql.Timestamp)8 DateFormat (java.text.DateFormat)8 ParseException (java.text.ParseException)8 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 Decimal (org.apache.spark.sql.types.Decimal)8 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)7 ArrayList (java.util.ArrayList)3 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)3 BitSet (java.util.BitSet)1 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)1 DictionaryChunksWrapper (org.apache.carbondata.core.cache.dictionary.DictionaryChunksWrapper)1 ForwardDictionary (org.apache.carbondata.core.cache.dictionary.ForwardDictionary)1 Expression (org.apache.carbondata.core.scan.expression.Expression)1