Search in sources :

Example 1 with Expression

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

the class RangeExpression method getLiteralsResult.

private void getLiteralsResult(Expression expression, List<ExpressionResult> listOfExp) {
    for (Expression child : expression.getChildren()) {
        if (child instanceof LiteralExpression) {
            ExpressionResult colExp = ((LiteralExpression) child).getExpressionResult();
            listOfExp.add(colExp);
        } else {
            getLiteralsResult(child, listOfExp);
        }
    }
}
Also used : Expression(org.apache.carbondata.core.scan.expression.Expression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Example 2 with Expression

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

the class BinaryLogicalExpression method getColumnList.

private void getColumnList(Expression expression, List<ColumnExpression> lst) {
    if (expression instanceof ColumnExpression) {
        ColumnExpression colExp = (ColumnExpression) expression;
        boolean found = false;
        for (ColumnExpression currentColExp : lst) {
            if (currentColExp.getColumnName().equals(colExp.getColumnName())) {
                found = true;
                colExp.setColIndex(currentColExp.getColIndex());
                break;
            }
        }
        if (!found) {
            colExp.setColIndex(lst.size());
            lst.add(colExp);
        }
    }
    for (Expression child : expression.getChildren()) {
        getColumnList(child, lst);
    }
}
Also used : Expression(org.apache.carbondata.core.scan.expression.Expression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression)

Example 3 with Expression

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

the class BinaryLogicalExpression method getExpressionResultList.

private void getExpressionResultList(Expression binaryConditionalExpression, List<ExpressionResult> listOfExp) {
    if (binaryConditionalExpression instanceof LiteralExpression) {
        ExpressionResult colExp = ((LiteralExpression) binaryConditionalExpression).getExpressionResult();
        listOfExp.add(colExp);
    }
    for (Expression child : binaryConditionalExpression.getChildren()) {
        getExpressionResultList(child, listOfExp);
    }
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) Expression(org.apache.carbondata.core.scan.expression.Expression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Example 4 with Expression

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

the class ListExpressionUnitTest method test.

@Test
public void test() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression left = new ColumnExpression("left_name", DataType.STRING);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_name", DataType.STRING);
    right.setColIndex(1);
    List<Expression> children = new ArrayList<>();
    children.add(left);
    children.add(right);
    listExpression = new ListExpression(children);
    RowImpl value = new RowImpl();
    String row = "Row is for left";
    String row1 = "I am row 1";
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    String expected_value = "Row is for left";
    ExpressionResult result = listExpression.evaluate(value);
    assertThat(expected_value, is(equalTo(result.getList().get(0).getString())));
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) Expression(org.apache.carbondata.core.scan.expression.Expression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Expression

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

the class FilterUtilTest method testCheckIfExpressionContainsColumnWithExpressionNotInstanceOfColumnExpression.

@Test
public void testCheckIfExpressionContainsColumnWithExpressionNotInstanceOfColumnExpression() {
    String columnName = "IMEI";
    Expression expression = new LiteralExpression(columnName, DataType.STRING);
    boolean result = FilterUtil.checkIfExpressionContainsColumn(expression);
    assertFalse(result);
}
Also used : ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Aggregations

Expression (org.apache.carbondata.core.scan.expression.Expression)31 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)25 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)24 Test (org.junit.Test)18 ListExpression (org.apache.carbondata.core.scan.expression.conditional.ListExpression)10 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)9 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)7 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)7 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)6 ArrayList (java.util.ArrayList)5 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)5 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)5 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)4 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)4 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)4 GreaterThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression)4 GreaterThanExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression)4 LessThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression)4 NotEqualsExpression (org.apache.carbondata.core.scan.expression.conditional.NotEqualsExpression)4 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)4