Search in sources :

Example 1 with BoundPredicate

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")));
}
Also used : Expression(org.apache.iceberg.expressions.Expression) BoundPredicate(org.apache.iceberg.expressions.BoundPredicate) Evaluator(org.apache.iceberg.expressions.Evaluator) Test(org.junit.Test)

Example 2 with BoundPredicate

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")));
}
Also used : BoundPredicate(org.apache.iceberg.expressions.BoundPredicate) InclusiveMetricsEvaluator(org.apache.iceberg.expressions.InclusiveMetricsEvaluator) StrictMetricsEvaluator(org.apache.iceberg.expressions.StrictMetricsEvaluator) Evaluator(org.apache.iceberg.expressions.Evaluator) Test(org.junit.Test)

Example 3 with BoundPredicate

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")));
}
Also used : BoundPredicate(org.apache.iceberg.expressions.BoundPredicate) InclusiveMetricsEvaluator(org.apache.iceberg.expressions.InclusiveMetricsEvaluator) StrictMetricsEvaluator(org.apache.iceberg.expressions.StrictMetricsEvaluator) Evaluator(org.apache.iceberg.expressions.Evaluator) Test(org.junit.Test)

Example 4 with BoundPredicate

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")));
}
Also used : BoundPredicate(org.apache.iceberg.expressions.BoundPredicate) InclusiveMetricsEvaluator(org.apache.iceberg.expressions.InclusiveMetricsEvaluator) StrictMetricsEvaluator(org.apache.iceberg.expressions.StrictMetricsEvaluator) Evaluator(org.apache.iceberg.expressions.Evaluator) Test(org.junit.Test)

Aggregations

BoundPredicate (org.apache.iceberg.expressions.BoundPredicate)4 Evaluator (org.apache.iceberg.expressions.Evaluator)4 Test (org.junit.Test)4 InclusiveMetricsEvaluator (org.apache.iceberg.expressions.InclusiveMetricsEvaluator)3 StrictMetricsEvaluator (org.apache.iceberg.expressions.StrictMetricsEvaluator)3 Expression (org.apache.iceberg.expressions.Expression)1