Search in sources :

Example 16 with UnboundPredicate

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

the class TestHiveIcebergFilterFactory method testDecimalType.

@Test
public void testDecimalType() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().equals("decimal", PredicateLeaf.Type.DECIMAL, new HiveDecimalWritable("20.12")).end().build();
    UnboundPredicate expected = Expressions.equal("decimal", new BigDecimal("20.12"));
    UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg);
    assertPredicatesMatch(expected, actual);
}
Also used : HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) SearchArgument(org.apache.hadoop.hive.ql.io.sarg.SearchArgument) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 17 with UnboundPredicate

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

the class TestHiveIcebergFilterFactory method testEqualsOperandRewrite.

@Test
public void testEqualsOperandRewrite() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().equals("float", PredicateLeaf.Type.FLOAT, Double.NaN).end().build();
    UnboundPredicate expected = Expressions.isNaN("float");
    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 18 with UnboundPredicate

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

the class TestHiveIcebergFilterFactory method testInOperand.

@Test
public void testInOperand() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().in("salary", PredicateLeaf.Type.LONG, 3000L, 4000L).end().build();
    UnboundPredicate expected = Expressions.in("salary", 3000L, 4000L);
    UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg);
    assertEquals(actual.op(), expected.op());
    assertEquals(actual.literals(), expected.literals());
    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 19 with UnboundPredicate

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

the class TestFlinkFilters method matchLiteral.

@SuppressWarnings("unchecked")
private <T> void matchLiteral(String fieldName, Object flinkLiteral, T icebergLiteral) {
    Expression expr = resolve(Expressions.$(fieldName).isEqual(Expressions.lit(flinkLiteral)));
    Optional<org.apache.iceberg.expressions.Expression> actual = FlinkFilters.convert(expr);
    Assert.assertTrue("Conversion should succeed", actual.isPresent());
    org.apache.iceberg.expressions.Expression expression = actual.get();
    Assertions.assertThat(expression).as("The expression should be a UnboundPredicate").isInstanceOf(UnboundPredicate.class);
    UnboundPredicate<T> unboundPredicate = (UnboundPredicate<T>) expression;
    org.apache.iceberg.expressions.Expression expression1 = unboundPredicate.bind(FlinkSchemaUtil.convert(TABLE_SCHEMA).asStruct(), false);
    Assertions.assertThat(expression1).as("The expression should be a BoundLiteralPredicate").isInstanceOf(BoundLiteralPredicate.class);
    BoundLiteralPredicate<T> predicate = (BoundLiteralPredicate<T>) expression1;
    Assert.assertTrue("Should match the  literal", predicate.test(icebergLiteral));
}
Also used : UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) BoundLiteralPredicate(org.apache.iceberg.expressions.BoundLiteralPredicate)

Example 20 with UnboundPredicate

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

the class TestProjection method testCaseInsensitiveStrictIdentityProjection.

@Test
public void testCaseInsensitiveStrictIdentityProjection() {
    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, false).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(), false));
        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