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