-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
api/src/test/java/org/apache/iceberg/transforms/TestStartsWithProjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.apache.iceberg.transforms; | ||
|
||
import org.apache.iceberg.PartitionSpec; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.expressions.Expression; | ||
import org.apache.iceberg.expressions.Literal; | ||
import org.apache.iceberg.expressions.Projections; | ||
import org.apache.iceberg.expressions.UnboundPredicate; | ||
import org.apache.iceberg.types.Types; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.apache.iceberg.TestHelpers.assertAndUnwrapUnbound; | ||
import static org.apache.iceberg.expressions.Expressions.startsWith; | ||
import static org.apache.iceberg.types.Types.NestedField.optional; | ||
|
||
public class TestStartsWithProjection { | ||
private static final Schema SCHEMA = new Schema(optional(1, "someStringCol", Types.StringType.get())); | ||
@Test | ||
public void assertTruncateProjections(){ | ||
PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).truncate("someStringCol", 4).build(); | ||
|
||
assertTruncateProjectionInclusive(spec, startsWith("someStringCol", "ab"), "ab"); | ||
assertTruncateProjectionInclusive(spec, startsWith("someStringCol", "abab"), "abab"); | ||
assertTruncateProjectionInclusive(spec, startsWith("someStringCol", "ababab"), "abab"); | ||
|
||
} | ||
|
||
private void assertTruncateProjectionInclusive(PartitionSpec spec, UnboundPredicate<?> filter, | ||
String expectedLiteral) { | ||
Expression projection = Projections.inclusive(spec).project(filter); | ||
UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection); | ||
|
||
Assert.assertEquals(predicate.op(), Expression.Operation.STARTS_WITH); | ||
|
||
Literal literal = predicate.literal(); | ||
Truncate<CharSequence> transform = (Truncate<CharSequence>) spec.getFieldsBySourceId(1).get(0).transform(); | ||
String output = transform.toHumanString((String) literal.value()); | ||
Assert.assertEquals(expectedLiteral, output); | ||
} | ||
} |