Search in sources :

Example 1 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg by apache.

the class TestHiveIcebergFilterFactory method testNotEqualsOperand.

@Test
public void testNotEqualsOperand() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startNot().equals("salary", PredicateLeaf.Type.LONG, 3000L).end().build();
    Not expected = (Not) Expressions.not(Expressions.equal("salary", 3000L));
    Not actual = (Not) HiveIcebergFilterFactory.generateFilterExpression(arg);
    UnboundPredicate childExpressionActual = (UnboundPredicate) actual.child();
    UnboundPredicate childExpressionExpected = Expressions.equal("salary", 3000L);
    assertEquals(actual.op(), expected.op());
    assertEquals(actual.child().op(), expected.child().op());
    assertEquals(childExpressionActual.ref().name(), childExpressionExpected.ref().name());
    assertEquals(childExpressionActual.literal(), childExpressionExpected.literal());
}
Also used : Not(org.apache.iceberg.expressions.Not) UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) Test(org.junit.Test)

Example 2 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg by apache.

the class TestHiveIcebergFilterFactory method testLessThanOperand.

@Test
public void testLessThanOperand() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().lessThan("salary", PredicateLeaf.Type.LONG, 3000L).end().build();
    UnboundPredicate expected = Expressions.lessThan("salary", 3000L);
    UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg);
    assertEquals(actual.op(), expected.op());
    assertEquals(actual.literal(), expected.literal());
    assertEquals(actual.ref().name(), expected.ref().name());
}
Also used : UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) Test(org.junit.Test)

Example 3 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg by apache.

the class TestHiveIcebergFilterFactory method testDateType.

@Test
public void testDateType() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    Date gmtDate = Date.valueOf(LocalDate.of(2015, 11, 12));
    SearchArgument arg = builder.startAnd().equals("date", PredicateLeaf.Type.DATE, gmtDate).end().build();
    UnboundPredicate expected = Expressions.equal("date", Literal.of("2015-11-12").to(Types.DateType.get()).value());
    UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg);
    assertPredicatesMatch(expected, actual);
}
Also used : UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) Date(java.sql.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 4 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg by apache.

the class TestHiveIcebergFilterFactory method testFloatType.

@Test
public void testFloatType() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().equals("float", PredicateLeaf.Type.FLOAT, 1200D).end().build();
    UnboundPredicate expected = Expressions.equal("float", 1200D);
    UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg);
    assertPredicatesMatch(expected, actual);
}
Also used : UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) Test(org.junit.Test)

Example 5 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg by apache.

the class TestProjection method testStrictIdentityProjection.

@Test
public void testStrictIdentityProjection() {
    List<UnboundPredicate<?>> predicates = Lists.newArrayList(Expressions.notNull("id"), Expressions.isNull("id"), Expressions.lessThan("id", 100), Expressions.lessThanOrEqual("id", 101), Expressions.greaterThan("id", 102), Expressions.greaterThanOrEqual("id", 103), Expressions.equal("id", 104), Expressions.notEqual("id", 105));
    PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).identity("id").build();
    for (UnboundPredicate<?> predicate : predicates) {
        // get the projected predicate
        Expression expr = Projections.strict(spec).project(predicate);
        UnboundPredicate<?> projected = assertAndUnwrapUnbound(expr);
        // check inclusive the bound predicate to ensure the types are correct
        BoundPredicate<?> bound = assertAndUnwrap(predicate.bind(spec.schema().asStruct(), true));
        Assert.assertEquals("Field name should match partition struct field", "id", projected.ref().name());
        Assert.assertEquals("Operation should match", bound.op(), projected.op());
        if (bound.isLiteralPredicate()) {
            Assert.assertEquals("Literal should be equal", bound.asLiteralPredicate().literal().value(), projected.literal().value());
        } else {
            Assert.assertNull("Literal should be null", projected.literal());
        }
    }
}
Also used : Expression(org.apache.iceberg.expressions.Expression) UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Aggregations

UnboundPredicate (org.apache.iceberg.expressions.UnboundPredicate)32 Test (org.junit.Test)31 SearchArgument (org.apache.hadoop.hive.ql.io.sarg.SearchArgument)26 PartitionSpec (org.apache.iceberg.PartitionSpec)5 Expression (org.apache.iceberg.expressions.Expression)4 BigDecimal (java.math.BigDecimal)2 Date (java.sql.Date)2 Timestamp (java.sql.Timestamp)2 LocalDate (java.time.LocalDate)2 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)2 Not (org.apache.iceberg.expressions.Not)2 CallExpression (org.apache.flink.table.expressions.CallExpression)1 Expression (org.apache.flink.table.expressions.Expression)1 FieldReferenceExpression (org.apache.flink.table.expressions.FieldReferenceExpression)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 UnresolvedCallExpression (org.apache.flink.table.expressions.UnresolvedCallExpression)1 UnresolvedReferenceExpression (org.apache.flink.table.expressions.UnresolvedReferenceExpression)1 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)1 Schema (org.apache.iceberg.Schema)1 BoundLiteralPredicate (org.apache.iceberg.expressions.BoundLiteralPredicate)1