Java Code Examples for org.apache.iceberg.expressions.Expression#Operation

The following examples show how to use org.apache.iceberg.expressions.Expression#Operation . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTruncatesProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter,
                                      Expression.Operation expectedOp, String expectedLiteral) {
  Expression projection = Projections.inclusive(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(predicate.op(), expectedOp);

  Assert.assertNotEquals("Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());

  Truncate transform = (Truncate) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString(v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString(literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 2
Source File: TestDatesProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter,
                                      Expression.Operation expectedOp, String expectedLiteral) {
  Expression projection = Projections.inclusive(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(predicate.op(), expectedOp);

  Assert.assertNotEquals("Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());

  Dates transform = (Dates) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString((Integer) v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString((int) literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 3
Source File: TestTimestampsProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionStrict(PartitionSpec spec, UnboundPredicate<?> filter,
                                   Expression.Operation expectedOp, String expectedLiteral) {

  Expression projection = Projections.strict(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(expectedOp, predicate.op());

  Assert.assertNotEquals("Strict projection never runs for IN", Expression.Operation.IN, predicate.op());

  Timestamps transform = (Timestamps) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.NOT_IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString((Integer) v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString((int) literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 4
Source File: TestTruncatesProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionStrict(PartitionSpec spec, UnboundPredicate<?> filter,
                                   Expression.Operation expectedOp, String expectedLiteral) {

  Expression projection = Projections.strict(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(expectedOp, predicate.op());

  Assert.assertNotEquals("Strict projection never runs for IN", Expression.Operation.IN, predicate.op());

  Truncate transform = (Truncate) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.NOT_IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString(v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString(literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 5
Source File: TestTimestampsProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter,
                                      Expression.Operation expectedOp, String expectedLiteral) {
  Expression projection = Projections.inclusive(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(predicate.op(), expectedOp);

  Assert.assertNotEquals("Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());

  Timestamps transform = (Timestamps) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString((Integer) v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString((int) literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 6
Source File: TestBucketingProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionStrict(PartitionSpec spec, UnboundPredicate<?> filter,
                                   Expression.Operation expectedOp, String expectedLiteral) {

  Expression projection = Projections.strict(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(expectedOp, predicate.op());

  Assert.assertNotEquals("Strict projection never runs for IN", Expression.Operation.IN, predicate.op());

  Bucket transform = (Bucket) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.NOT_IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString(v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString(literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 7
Source File: TestDatesProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionStrict(PartitionSpec spec, UnboundPredicate<?> filter,
                                   Expression.Operation expectedOp, String expectedLiteral) {

  Expression projection = Projections.strict(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(expectedOp, predicate.op());

  Assert.assertNotEquals("Strict projection never runs for IN", Expression.Operation.IN, predicate.op());

  Dates transform = (Dates) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.NOT_IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString((Integer) v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString((int) literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 8
Source File: TestBucketingProjection.java    From iceberg with Apache License 2.0 6 votes vote down vote up
public void assertProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter,
                                      Expression.Operation expectedOp, String expectedLiteral) {
  Expression projection = Projections.inclusive(spec).project(filter);
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);

  Assert.assertEquals(predicate.op(), expectedOp);

  Assert.assertNotEquals("Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());

  Bucket transform = (Bucket) spec.getFieldsBySourceId(1).get(0).transform();
  if (predicate.op() == Expression.Operation.IN) {
    Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
    String actual = Lists.newArrayList(values).stream().sorted()
        .map(v -> transform.toHumanString(v)).collect(Collectors.toList()).toString();
    Assert.assertEquals(expectedLiteral, actual);
  } else {
    Literal literal = predicate.literal();
    String output = transform.toHumanString(literal.value());
    Assert.assertEquals(expectedLiteral, output);
  }
}
 
Example 9
Source File: TestStartsWith.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private void assertProjection(PartitionSpec spec, String expectedLiteral, Expression projection,
                              Expression.Operation expectedOp) {
  UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);
  Literal literal = predicate.literal();
  Truncate<CharSequence> transform = (Truncate<CharSequence>) spec.getFieldsBySourceId(1).get(0).transform();
  String output = transform.toHumanString((String) literal.value());

  Assert.assertEquals(expectedOp, predicate.op());
  Assert.assertEquals(expectedLiteral, output);
}
 
Example 10
Source File: TestBucketingProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionStrictValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                        Expression.Operation expectedOp) {
  Expression projection = Projections.strict(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 11
Source File: TestTruncatesProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionInclusiveValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                           Expression.Operation expectedOp) {

  Expression projection = Projections.inclusive(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 12
Source File: TestTruncatesProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionStrictValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                        Expression.Operation expectedOp) {

  Expression projection = Projections.strict(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 13
Source File: TestStartsWith.java    From iceberg with Apache License 2.0 4 votes vote down vote up
private void assertProjectionStrict(PartitionSpec spec, UnboundPredicate<?> filter,
                                       String expectedLiteral, Expression.Operation expectedOp) {
  Expression projection = Projections.strict(spec).project(filter);
  assertProjection(spec, expectedLiteral, projection, expectedOp);
}
 
Example 14
Source File: TestStartsWith.java    From iceberg with Apache License 2.0 4 votes vote down vote up
private void assertProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter,
                                       String expectedLiteral, Expression.Operation expectedOp) {
  Expression projection = Projections.inclusive(spec).project(filter);
  assertProjection(spec, expectedLiteral, projection, expectedOp);
}
 
Example 15
Source File: TestBucketingProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionInclusiveValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                           Expression.Operation expectedOp) {
  Expression projection = Projections.inclusive(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 16
Source File: TestTimestampsProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionInclusiveValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                           Expression.Operation expectedOp) {

  Expression projection = Projections.inclusive(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 17
Source File: TestTimestampsProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionStrictValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                        Expression.Operation expectedOp) {

  Expression projection = Projections.strict(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 18
Source File: TestDatesProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionInclusiveValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                           Expression.Operation expectedOp) {

  Expression projection = Projections.inclusive(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 19
Source File: TestDatesProjection.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public void assertProjectionStrictValue(PartitionSpec spec, UnboundPredicate<?> filter,
                                        Expression.Operation expectedOp) {

  Expression projection = Projections.strict(spec).project(filter);
  Assert.assertEquals(projection.op(), expectedOp);
}
 
Example 20
Source File: TestTruncatesResiduals.java    From iceberg with Apache License 2.0 3 votes vote down vote up
/**
 * Test helper method to compute residual for a given partitionValue against a predicate
 * and assert the resulting residual expression is same as the expectedOp
 *
 * @param spec the partition spec
 * @param predicate predicate to calculate the residual against
 * @param partitionValue value of the partition to check the residual for
 * @param expectedOp expected operation to assert against
 * @param <T> Type parameter of partitionValue
 */
public <T> void assertResidualValue(PartitionSpec spec, UnboundPredicate<?> predicate,
                                T partitionValue, Expression.Operation expectedOp) {
  ResidualEvaluator resEval = ResidualEvaluator.of(spec, predicate, true);
  Expression residual = resEval.residualFor(TestHelpers.Row.of(partitionValue));

  Assert.assertEquals(expectedOp, residual.op());
}