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());
}
}
}
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());
}
}
}
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());
}
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);
}
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);
}
Aggregations