Search in sources :

Example 21 with UnboundPredicate

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

the class TestProjection method testCaseInsensitiveIdentityProjection.

@Test
public void testCaseInsensitiveIdentityProjection() {
    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.inclusive(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)

Example 22 with UnboundPredicate

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

the class TestProjection method testIdentityProjection.

@Test
public void testIdentityProjection() {
    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.inclusive(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)

Example 23 with UnboundPredicate

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

the class TestProjection method testProjectionNames.

@Test
@SuppressWarnings("unchecked")
public void testProjectionNames() {
    final Schema schema = new Schema(required(1, "timestamp1", Types.TimestampType.withoutZone()), optional(2, "timestamp2", Types.TimestampType.withoutZone()), optional(3, "timestamp3", Types.TimestampType.withoutZone()), optional(4, "timestamp4", Types.TimestampType.withoutZone()), optional(5, "date1", Types.DateType.get()), optional(6, "date2", Types.DateType.get()), optional(7, "date3", Types.DateType.get()), optional(8, "long", Types.LongType.get()), optional(9, "string", Types.StringType.get()));
    final PartitionSpec partitionSpec = PartitionSpec.builderFor(schema).withSpecId(0).hour("timestamp1").day("timestamp2").month("timestamp3").year("timestamp4").day("date1").month("date2").year("date3").bucket("long", 10).truncate("string", 10).build();
    UnboundPredicate<Integer> predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(hour("timestamp1"), 20));
    Assert.assertEquals("should expected timestamp1_hour", "timestamp1_hour", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(hour("timestamp1"), 20));
    Assert.assertEquals("should expected timestamp1_hour", "timestamp1_hour", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(day("timestamp2"), 20));
    Assert.assertEquals("should expected timestamp2_day", "timestamp2_day", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(day("timestamp2"), 20));
    Assert.assertEquals("should expected timestamp2_day", "timestamp2_day", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(month("timestamp3"), 20));
    Assert.assertEquals("should expected timestamp3_month", "timestamp3_month", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(month("timestamp3"), 20));
    Assert.assertEquals("should expected timestamp3_month", "timestamp3_month", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(year("timestamp4"), 20));
    Assert.assertEquals("should expected timestamp4_year", "timestamp4_year", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(year("timestamp4"), 20));
    Assert.assertEquals("should expected timestamp4_year", "timestamp4_year", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(day("date1"), 20));
    Assert.assertEquals("should expected date1_day", "date1_day", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(day("date1"), 20));
    Assert.assertEquals("should expected date1_day", "date1_day", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(month("date2"), 20));
    Assert.assertEquals("should expected date2_month", "date2_month", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(month("date2"), 20));
    Assert.assertEquals("should expected date2_month", "date2_month", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(year("date3"), 20));
    Assert.assertEquals("should expected date3_year", "date3_year", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(year("date3"), 20));
    Assert.assertEquals("should expected date3_year", "date3_year", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(bucket("long", 10), 20));
    Assert.assertEquals("should expected long_bucket", "long_bucket", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(bucket("long", 10), 20));
    Assert.assertEquals("should expected long_bucket", "long_bucket", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.strict(partitionSpec).project(equal(truncate("string", 10), "abc"));
    Assert.assertEquals("should expected string_trunc", "string_trunc", predicate.ref().name());
    predicate = (UnboundPredicate<Integer>) Projections.inclusive(partitionSpec).project(equal(truncate("string", 10), "abc"));
    Assert.assertEquals("should expected string_trunc", "string_trunc", predicate.ref().name());
}
Also used : Schema(org.apache.iceberg.Schema) UnboundPredicate(org.apache.iceberg.expressions.UnboundPredicate) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Example 24 with UnboundPredicate

use of org.apache.iceberg.expressions.UnboundPredicate in project iceberg 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 25 with UnboundPredicate

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

the class TestHiveIcebergFilterFactory method testLessThanEqualsOperand.

@Test
public void testLessThanEqualsOperand() {
    SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
    SearchArgument arg = builder.startAnd().lessThanEquals("salary", PredicateLeaf.Type.LONG, 3000L).end().build();
    UnboundPredicate expected = Expressions.lessThanOrEqual("salary", 3000L);
    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)

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