Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ public <T> Expression notIn(BoundReference<T> ref, Set<T> literalSet) {

@Override
public <T> Expression startsWith(BoundReference<T> ref, Literal<T> lit) {
return ((String) ref.eval(struct)).startsWith((String) lit.value())
? alwaysTrue()
: alwaysFalse();
String value = (String) ref.eval(struct);
return value != null && value.startsWith((String) lit.value()) ? alwaysTrue() : alwaysFalse();
}

@Override
public <T> Expression notStartsWith(BoundReference<T> ref, Literal<T> lit) {
return ((String) ref.eval(struct)).startsWith((String) lit.value())
? alwaysFalse()
: alwaysTrue();
String value = (String) ref.eval(struct);
return value == null || !value.startsWith((String) lit.value())
? alwaysTrue()
: alwaysFalse();
}

@Override
Expand Down
38 changes: 38 additions & 0 deletions api/src/test/java/org/apache/iceberg/transforms/TestResiduals.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,44 @@ public void testNotInWithNullStringPartition() {
assertThat(residual).as("null not in [a, b, c] => true").isEqualTo(alwaysTrue());
}

@Test
public void testStartsWithWithNullStringPartition() {
Schema schema = new Schema(Types.NestedField.optional(50, "category", Types.StringType.get()));

PartitionSpec spec = PartitionSpec.builderFor(schema).identity("category").build();

ResidualEvaluator resEval =
ResidualEvaluator.of(spec, Expressions.startsWith("category", "a"), true);

Expression residual = resEval.residualFor(Row.of("abc"));
assertThat(residual).isEqualTo(alwaysTrue());

residual = resEval.residualFor(Row.of("bcd"));
assertThat(residual).isEqualTo(alwaysFalse());

residual = resEval.residualFor(Row.of((Object) null));
assertThat(residual).as("null startsWith a => false").isEqualTo(alwaysFalse());
}

@Test
public void testNotStartsWithWithNullStringPartition() {
Schema schema = new Schema(Types.NestedField.optional(50, "category", Types.StringType.get()));

PartitionSpec spec = PartitionSpec.builderFor(schema).identity("category").build();

ResidualEvaluator resEval =
ResidualEvaluator.of(spec, Expressions.notStartsWith("category", "a"), true);

Expression residual = resEval.residualFor(Row.of("bcd"));
assertThat(residual).isEqualTo(alwaysTrue());

residual = resEval.residualFor(Row.of("abc"));
assertThat(residual).isEqualTo(alwaysFalse());

residual = resEval.residualFor(Row.of((Object) null));
assertThat(residual).as("null notStartsWith a => true").isEqualTo(alwaysTrue());
}

@Test
public void testIsNaN() {
Schema schema =
Expand Down
Loading