use of org.apache.iceberg.expressions.BoundPredicate in project iceberg by apache.
the class TestStartsWith method testTruncateString.
@Test
public void testTruncateString() {
Truncate<String> trunc = Truncate.get(Types.StringType.get(), 2);
Expression expr = startsWith(COLUMN, "abcde");
BoundPredicate<String> boundExpr = (BoundPredicate<String>) Binder.bind(SCHEMA.asStruct(), expr, false);
UnboundPredicate<String> projected = trunc.project(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
Assert.assertTrue("startsWith(abcde, truncate(abcdg,2)) => true", evaluator.eval(TestHelpers.Row.of("abcdg")));
}
use of org.apache.iceberg.expressions.BoundPredicate in project iceberg by apache.
the class TestNotStartsWith method testTruncateStringWhenProjectedPredicateTermIsShorterThanWidth.
@Test
public void testTruncateStringWhenProjectedPredicateTermIsShorterThanWidth() {
Truncate<String> trunc = Truncate.get(Types.StringType.get(), 16);
UnboundPredicate<String> expr = notStartsWith(COLUMN, "ab");
BoundPredicate<String> boundExpr = (BoundPredicate<String>) Binder.bind(SCHEMA.asStruct(), expr, false);
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
Assert.assertEquals("The projected literal should not be truncated as its size is shorter than truncation width", projected.literal().value(), "ab");
Assert.assertFalse("notStartsWith(ab, truncate(abcde, 16)) => false", evaluator.eval(TestHelpers.Row.of("abcde")));
Assert.assertFalse("notStartsWith(ab, truncate(ab, 16)) => false", evaluator.eval(TestHelpers.Row.of("ab")));
Assert.assertTrue("notStartsWith(ab, truncate(a, 16)) => true", evaluator.eval(TestHelpers.Row.of("a")));
}
use of org.apache.iceberg.expressions.BoundPredicate in project iceberg by apache.
the class TestNotStartsWith method testTruncateStringWhenProjectedPredicateTermIsLongerThanWidth.
@Test
public void testTruncateStringWhenProjectedPredicateTermIsLongerThanWidth() {
Truncate<String> trunc = Truncate.get(Types.StringType.get(), 2);
UnboundPredicate<String> expr = notStartsWith(COLUMN, "abcde");
BoundPredicate<String> boundExpr = (BoundPredicate<String>) Binder.bind(SCHEMA.asStruct(), expr, false);
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
Assert.assertEquals("The projected literal should be truncated to the truncation width", projected.literal().value(), "ab");
Assert.assertFalse("notStartsWith(abcde, truncate(abcde,2)) => false", evaluator.eval(TestHelpers.Row.of("abcde")));
Assert.assertFalse("notStartsWith(abcde, truncate(ab, 2)) => false", evaluator.eval(TestHelpers.Row.of("ab")));
Assert.assertFalse("notStartsWith(abcde, truncate(abcdz, 2)) => false", evaluator.eval(TestHelpers.Row.of("abcdz")));
Assert.assertTrue("notStartsWith(abcde, truncate(a, 2)) => true", evaluator.eval(TestHelpers.Row.of("a")));
Assert.assertTrue("notStartsWith(abcde, truncate(aczcde, 2)) => true", evaluator.eval(TestHelpers.Row.of("aczcde")));
}
use of org.apache.iceberg.expressions.BoundPredicate in project iceberg by apache.
the class TestNotStartsWith method testTruncateStringWhenProjectedPredicateTermIsEqualToWidth.
@Test
public void testTruncateStringWhenProjectedPredicateTermIsEqualToWidth() {
Truncate<String> trunc = Truncate.get(Types.StringType.get(), 7);
UnboundPredicate<String> expr = notStartsWith(COLUMN, "abcdefg");
BoundPredicate<String> boundExpr = (BoundPredicate<String>) Binder.bind(SCHEMA.asStruct(), expr, false);
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
Assert.assertEquals("The projected literal should not be truncated as its size is equal to truncation width", projected.literal().value(), "abcdefg");
Assert.assertFalse("notStartsWith(abcdefg, truncate(abcdefg, 7)) => false", evaluator.eval(TestHelpers.Row.of("abcdefg")));
Assert.assertTrue("notStartsWith(abcdefg, truncate(ab, 2)) => true", evaluator.eval(TestHelpers.Row.of("ab")));
Assert.assertTrue("notStartsWith(abcdefg, truncate(a, 16)) => true", evaluator.eval(TestHelpers.Row.of("a")));
}
Aggregations