Search in sources :

Example 86 with ExpressionResult

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

the class FalseExpressionTest method testEvaluate.

@Test
public void testEvaluate() throws FilterUnsupportedException, FilterIllegalMemberException {
    RowImpl rowImpl = new RowImpl();
    rowImpl.setValues(new Boolean[] { true });
    ExpressionResult actualValue = falseExpression.evaluate(rowImpl);
    assertEquals(new ExpressionResult(DataType.BOOLEAN, false), actualValue);
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) Test(org.junit.Test)

Example 87 with ExpressionResult

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

the class OrExpressionTest method testEvaluate.

@Test
public void testEvaluate() throws FilterIllegalMemberException, FilterUnsupportedException {
    RowImpl rowImpl = new RowImpl();
    rowImpl.setValues(new Boolean[] { false });
    final ExpressionResult expressionResult = new ExpressionResult(DataType.BOOLEAN, "test");
    new MockUp<ColumnExpression>() {

        @Mock
        public ExpressionResult evaluate(RowIntf value) {
            return expressionResult;
        }
    };
    assertTrue(orExpression.evaluate(rowImpl) instanceof ExpressionResult);
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 88 with ExpressionResult

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

the class OrExpressionTest method testEvaluateForDefault.

@Test(expected = Exception.class)
public void testEvaluateForDefault() throws FilterUnsupportedException, FilterIllegalMemberException {
    RowImpl rowImpl = new RowImpl();
    rowImpl.setValues(new Boolean[] { true });
    final ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "test");
    new MockUp<ColumnExpression>() {

        @Mock
        public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
            return expressionResult;
        }
    };
    orExpression.evaluate(rowImpl);
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 89 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithDecimalDataType.

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

        @Mock
        public BigDecimal getDecimal() {
            return new BigDecimal(1234521215454.0);
        }
    };
    ExpressionResult result = notInExpression.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)

Example 90 with ExpressionResult

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

the class NotEqualsExpressionUnitTest method testEvaluateWithForNotEqualsExpressionDecimalDataType.

@Test
public void testEvaluateWithForNotEqualsExpressionDecimalDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL);
    right.setColIndex(1);
    ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL);
    left.setColIndex(0);
    notEqualsExpression = new NotEqualsExpression(left, right);
    RowImpl value = new RowImpl();
    Decimal[] row = new Decimal[] { Decimal.apply(12345.0) };
    Decimal[] row1 = new Decimal[] { Decimal.apply(1235445.0) };
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public BigDecimal getDecimal() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return new BigDecimal(12345.0);
            } else {
                return new BigDecimal(1235445.0);
            }
        }
    };
    ExpressionResult result = notEqualsExpression.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

ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)99 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)81 Test (org.junit.Test)81 MockUp (mockit.MockUp)78 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)77 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)14 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 ArrayList (java.util.ArrayList)6 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)5 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)4 Expression (org.apache.carbondata.core.scan.expression.Expression)3 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)3 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)2 DimColumnFilterInfo (org.apache.carbondata.core.scan.filter.DimColumnFilterInfo)2