Search in sources :

Example 1 with EqualToExpression

use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.

the class CarbonInputFormat_FT method testGetFilteredSplits.

@Test
public void testGetFilteredSplits() throws Exception {
    CarbonInputFormat carbonInputFormat = new CarbonInputFormat();
    JobConf jobConf = new JobConf(new Configuration());
    Job job = Job.getInstance(jobConf);
    FileInputFormat.addInputPath(job, new Path("/opt/carbonstore/db/table1"));
    job.getConfiguration().set(CarbonInputFormat.INPUT_SEGMENT_NUMBERS, "1,2");
    Expression expression = new EqualToExpression(new ColumnExpression("c1", DataType.STRING), new LiteralExpression("a", DataType.STRING));
    CarbonInputFormat.setFilterPredicates(job.getConfiguration(), expression);
    List splits = carbonInputFormat.getSplits(job);
    Assert.assertTrue(splits != null);
    Assert.assertTrue(!splits.isEmpty());
}
Also used : Path(org.apache.hadoop.fs.Path) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) Configuration(org.apache.hadoop.conf.Configuration) Expression(org.apache.carbondata.core.scan.expression.Expression) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) CarbonInputFormat(org.apache.carbondata.hadoop.CarbonInputFormat) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) List(java.util.List) Job(org.apache.hadoop.mapreduce.Job) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 2 with EqualToExpression

use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.

the class FilterExpressionProcessor method createPartitionFilterTree.

/**
 * create partition filter by basing on pushed-down filter
 * @param expressionTree
 * @param partitionInfo
 * @return
 */
private PartitionFilterIntf createPartitionFilterTree(Expression expressionTree, PartitionInfo partitionInfo) {
    ExpressionType filterExpressionType = expressionTree.getFilterExpressionType();
    String partitionColumnName = partitionInfo.getColumnSchemaList().get(0).getColumnName();
    BinaryExpression currentExpression = null;
    ColumnExpression left = null;
    switch(filterExpressionType) {
        case OR:
            currentExpression = (BinaryExpression) expressionTree;
            return new OrFilterImpl(createPartitionFilterTree(currentExpression.getLeft(), partitionInfo), createPartitionFilterTree(currentExpression.getRight(), partitionInfo));
        case RANGE:
        case AND:
            currentExpression = (BinaryExpression) expressionTree;
            return new AndFilterImpl(createPartitionFilterTree(currentExpression.getLeft(), partitionInfo), createPartitionFilterTree(currentExpression.getRight(), partitionInfo));
        case EQUALS:
            EqualToExpression equalTo = (EqualToExpression) expressionTree;
            if (equalTo.getLeft() instanceof ColumnExpression && equalTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) equalTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new EqualToFilterImpl(equalTo, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case IN:
            InExpression in = (InExpression) expressionTree;
            if (in.getLeft() instanceof ColumnExpression && in.getRight() instanceof ListExpression) {
                left = (ColumnExpression) in.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new InFilterImpl(in, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case FALSE:
            return new PruneAllPartitionFilterImpl();
        case TRUE:
            return new KeepAllPartitionFilterImpl();
        case GREATERTHAN:
            GreaterThanExpression greaterThan = (GreaterThanExpression) expressionTree;
            if (greaterThan.getLeft() instanceof ColumnExpression && greaterThan.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) greaterThan.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) greaterThan.getRight(), true, false, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case GREATERTHAN_EQUALTO:
            GreaterThanEqualToExpression greaterThanEqualTo = (GreaterThanEqualToExpression) expressionTree;
            if (greaterThanEqualTo.getLeft() instanceof ColumnExpression && greaterThanEqualTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) greaterThanEqualTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) greaterThanEqualTo.getRight(), true, true, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case LESSTHAN:
            LessThanExpression lessThan = (LessThanExpression) expressionTree;
            if (lessThan.getLeft() instanceof ColumnExpression && lessThan.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) lessThan.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) lessThan.getRight(), false, false, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case LESSTHAN_EQUALTO:
            LessThanEqualToExpression lessThanEqualTo = (LessThanEqualToExpression) expressionTree;
            if (lessThanEqualTo.getLeft() instanceof ColumnExpression && lessThanEqualTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) lessThanEqualTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) lessThanEqualTo.getRight(), false, true, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case NOT_IN:
        case NOT_EQUALS:
        default:
            return new KeepAllPartitionFilterImpl();
    }
}
Also used : LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) AndFilterImpl(org.apache.carbondata.core.scan.filter.partition.AndFilterImpl) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) GreaterThanExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression) LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) EqualToFilterImpl(org.apache.carbondata.core.scan.filter.partition.EqualToFilterImpl) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) KeepAllPartitionFilterImpl(org.apache.carbondata.core.scan.filter.partition.KeepAllPartitionFilterImpl) PruneAllPartitionFilterImpl(org.apache.carbondata.core.scan.filter.partition.PruneAllPartitionFilterImpl) RangeFilterImpl(org.apache.carbondata.core.scan.filter.partition.RangeFilterImpl) InFilterImpl(org.apache.carbondata.core.scan.filter.partition.InFilterImpl) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType) OrFilterImpl(org.apache.carbondata.core.scan.filter.partition.OrFilterImpl) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression)

Example 3 with EqualToExpression

use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.

the class NoDictionaryTypeVisitor method populateFilterResolvedInfo.

/**
 * Visitor Method will update the filter related details in visitableObj, For no dictionary
 * type columns the filter members will resolved directly, no need to look up in dictionary
 * since it will not be part of dictionary, directly the actual data can be converted as
 * byte[] and can be set. this type of encoding is effective when the particular column
 * is having very high cardinality.
 *
 * @param visitableObj
 * @param metadata
 * @throws FilterUnsupportedException,if exception occurs while evaluating
 * filter models.
 */
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    if (visitableObj instanceof DimColumnResolvedFilterInfo) {
        DimColumnResolvedFilterInfo resolveDimension = (DimColumnResolvedFilterInfo) visitableObj;
        ColumnFilterInfo resolvedFilterObject = null;
        List<String> evaluateResultListFinal = new ArrayList<>(1);
        try {
            // handling for is null case scenarios
            if (metadata.getExpression() instanceof EqualToExpression) {
                EqualToExpression expression = (EqualToExpression) metadata.getExpression();
                if (expression.isNull) {
                    evaluateResultListFinal = new ArrayList<>(1);
                    evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                }
            } else {
                evaluateResultListFinal = metadata.getExpression().evaluate(null).getListAsString();
            }
            // displaying the report as per hive compatibility.
            if (!metadata.isIncludeFilter() && !evaluateResultListFinal.contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
                evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
            }
        } catch (FilterIllegalMemberException e) {
            throw new FilterUnsupportedException(e);
        }
        resolvedFilterObject = FilterUtil.getNoDictionaryValKeyMemberForFilter(evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDataType());
        resolveDimension.setFilterValues(resolvedFilterObject);
    }
}
Also used : DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) ArrayList(java.util.ArrayList) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 4 with EqualToExpression

use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.

the class MeasureColumnVisitor method populateFilterResolvedInfo.

/**
 * Visitor Method will update the filter related details in visitableObj, For no dictionary
 * type columns the filter members will resolved directly, no need to look up in dictionary
 * since it will not be part of dictionary, directly the actual data can be converted as
 * byte[] and can be set. this type of encoding is effective when the particular column
 * is having very high cardinality.
 *
 * @param visitableObj
 * @param metadata
 * @throws FilterUnsupportedException,if exception occurs while evaluating
 *                                       filter models.
 */
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    if (visitableObj instanceof MeasureColumnResolvedFilterInfo) {
        MeasureColumnResolvedFilterInfo resolveDimension = (MeasureColumnResolvedFilterInfo) visitableObj;
        ColumnFilterInfo resolvedFilterObject = null;
        List<String> evaluateResultListFinal = new ArrayList<>(1);
        try {
            // handling for is null case scenarios
            if (metadata.getExpression() instanceof EqualToExpression) {
                EqualToExpression expression = (EqualToExpression) metadata.getExpression();
                if (expression.isNull) {
                    evaluateResultListFinal = new ArrayList<>(1);
                    evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                }
            } else {
                evaluateResultListFinal = metadata.getExpression().evaluate(null).getListAsString();
            }
            // displaying the report as per hive compatibility.
            if (!metadata.isIncludeFilter() && !evaluateResultListFinal.contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
                evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
            }
        } catch (FilterIllegalMemberException e) {
            throw new FilterUnsupportedException(e);
        }
        resolvedFilterObject = FilterUtil.getMeasureValKeyMemberForFilter(evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDataType(), resolveDimension.getMeasure());
        resolveDimension.setFilterValues(resolvedFilterObject);
    }
}
Also used : MeasureColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) ArrayList(java.util.ArrayList) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 5 with EqualToExpression

use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.

the class ObjectSerializationUtilTest method testConvertStringToObject.

@Test
public void testConvertStringToObject() throws Exception {
    Expression expression = new EqualToExpression(new ColumnExpression("c1", DataTypes.STRING), new LiteralExpression("a", DataTypes.STRING));
    String string = ObjectSerializationUtil.convertObjectToString(expression);
    Assert.assertTrue(string != null);
    Object object = ObjectSerializationUtil.convertStringToObject(string);
    Assert.assertTrue(object != null);
    Assert.assertTrue(object instanceof Expression);
}
Also used : EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) Test(org.junit.Test)

Aggregations

EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)11 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)8 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)8 Expression (org.apache.carbondata.core.scan.expression.Expression)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IOException (java.io.IOException)2 GreaterThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression)2 GreaterThanExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression)2 InExpression (org.apache.carbondata.core.scan.expression.conditional.InExpression)2 LessThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression)2 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)2 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)2 ColumnFilterInfo (org.apache.carbondata.core.scan.filter.ColumnFilterInfo)2 CarbonProjection (org.apache.carbondata.hadoop.CarbonProjection)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 Domain (com.facebook.presto.spi.predicate.Domain)1 Range (com.facebook.presto.spi.predicate.Range)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1