Skip to content
Open
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
12 changes: 5 additions & 7 deletions api/src/main/java/org/apache/iceberg/ManifestContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ public int id() {
}

public static ManifestContent fromId(int id) {
switch (id) {
case 0:
return DATA;
case 1:
return DELETES;
}
throw new IllegalArgumentException("Unknown manifest content: " + id);
return switch (id) {
case 0 -> DATA;
case 1 -> DELETES;
default -> throw new IllegalArgumentException("Unknown manifest content: " + id);
};
}
}
13 changes: 5 additions & 8 deletions api/src/main/java/org/apache/iceberg/NullOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ public enum NullOrder {

@Override
public String toString() {
switch (this) {
case NULLS_FIRST:
return "NULLS FIRST";
case NULLS_LAST:
return "NULLS LAST";
default:
throw new IllegalArgumentException("Unexpected null order: " + this);
}
return switch (this) {
case NULLS_FIRST -> "NULLS FIRST";
case NULLS_LAST -> "NULLS LAST";
default -> throw new IllegalArgumentException("Unexpected null order: " + this);
};
}
}
22 changes: 8 additions & 14 deletions api/src/main/java/org/apache/iceberg/expressions/Aggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@ public C term() {

@Override
public String toString() {
switch (op()) {
case COUNT:
return "count(" + term() + ")";
case COUNT_NULL:
return "count_if(" + term() + " is null)";
case COUNT_STAR:
return "count(*)";
case MAX:
return "max(" + term() + ")";
case MIN:
return "min(" + term() + ")";
default:
throw new UnsupportedOperationException("Invalid aggregate: " + op());
}
return switch (op()) {
case COUNT -> "count(" + term() + ")";
case COUNT_NULL -> "count_if(" + term() + " is null)";
case COUNT_STAR -> "count(*)";
case MAX -> "max(" + term() + ")";
case MIN -> "min(" + term() + ")";
default -> throw new UnsupportedOperationException("Invalid aggregate: " + op());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,14 @@ public String columnName() {
}

public String describe() {
switch (op()) {
case COUNT_STAR:
return "count(*)";
case COUNT:
return "count(" + ExpressionUtil.describe(term()) + ")";
case COUNT_NULL:
return "count_if(" + ExpressionUtil.describe(term()) + " is null)";
case MAX:
return "max(" + ExpressionUtil.describe(term()) + ")";
case MIN:
return "min(" + ExpressionUtil.describe(term()) + ")";
default:
throw new UnsupportedOperationException("Unsupported aggregate type: " + op());
}
return switch (op()) {
case COUNT_STAR -> "count(*)";
case COUNT -> "count(" + ExpressionUtil.describe(term()) + ")";
case COUNT_NULL -> "count_if(" + ExpressionUtil.describe(term()) + " is null)";
case MAX -> "max(" + ExpressionUtil.describe(term()) + ")";
case MIN -> "min(" + ExpressionUtil.describe(term()) + ")";
default -> throw new UnsupportedOperationException("Unsupported aggregate type: " + op());
};
}

<V> boolean safeContainsKey(Map<Integer, V> map, int key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,18 @@ public BoundLiteralPredicate<T> asLiteralPredicate() {
@Override
public boolean test(T value) {
Comparator<T> cmp = literal.comparator();
switch (op()) {
case LT:
return cmp.compare(value, literal.value()) < 0;
case LT_EQ:
return cmp.compare(value, literal.value()) <= 0;
case GT:
return cmp.compare(value, literal.value()) > 0;
case GT_EQ:
return cmp.compare(value, literal.value()) >= 0;
case EQ:
return cmp.compare(value, literal.value()) == 0;
case NOT_EQ:
return cmp.compare(value, literal.value()) != 0;
case STARTS_WITH:
return String.valueOf(value).startsWith((String) literal.value());
case NOT_STARTS_WITH:
return !String.valueOf(value).startsWith((String) literal.value());
default:
throw new IllegalStateException("Invalid operation for BoundLiteralPredicate: " + op());
}
return switch (op()) {
case LT -> cmp.compare(value, literal.value()) < 0;
case LT_EQ -> cmp.compare(value, literal.value()) <= 0;
case GT -> cmp.compare(value, literal.value()) > 0;
case GT_EQ -> cmp.compare(value, literal.value()) >= 0;
case EQ -> cmp.compare(value, literal.value()) == 0;
case NOT_EQ -> cmp.compare(value, literal.value()) != 0;
case STARTS_WITH -> String.valueOf(value).startsWith((String) literal.value());
case NOT_STARTS_WITH -> !String.valueOf(value).startsWith((String) literal.value());
default ->
throw new IllegalStateException("Invalid operation for BoundLiteralPredicate: " + op());
};
}

@Override
Expand All @@ -108,32 +100,21 @@ public boolean isEquivalentTo(Expression expr) {
} else if (expr instanceof BoundLiteralPredicate) {
BoundLiteralPredicate<?> other = (BoundLiteralPredicate<?>) expr;
if (INTEGRAL_TYPES.contains(term().type().typeId()) && term().isEquivalentTo(other.term())) {
switch (op()) {
case LT:
if (other.op() == Operation.LT_EQ) {
return switch (op()) {
case LT ->
// < 6 is equivalent to <= 5
return toLong(literal()) == toLong(other.literal()) + 1L;
}
break;
case LT_EQ:
if (other.op() == Operation.LT) {
other.op() == Operation.LT_EQ && toLong(literal()) == toLong(other.literal()) + 1L;
case LT_EQ ->
// <= 5 is equivalent to < 6
return toLong(literal()) == toLong(other.literal()) - 1L;
}
break;
case GT:
if (other.op() == Operation.GT_EQ) {
other.op() == Operation.LT && toLong(literal()) == toLong(other.literal()) - 1L;
case GT ->
// > 5 is equivalent to >= 6
return toLong(literal()) == toLong(other.literal()) - 1L;
}
break;
case GT_EQ:
if (other.op() == Operation.GT) {
other.op() == Operation.GT_EQ && toLong(literal()) == toLong(other.literal()) - 1L;
case GT_EQ ->
// >= 5 is equivalent to > 4
return toLong(literal()) == toLong(other.literal()) + 1L;
}
break;
}
other.op() == Operation.GT && toLong(literal()) == toLong(other.literal()) + 1L;
default -> false;
};
}
}

Expand All @@ -142,29 +123,18 @@ public boolean isEquivalentTo(Expression expr) {

@Override
public String toString() {
switch (op()) {
case LT:
return term() + " < " + literal;
case LT_EQ:
return term() + " <= " + literal;
case GT:
return term() + " > " + literal;
case GT_EQ:
return term() + " >= " + literal;
case EQ:
return term() + " == " + literal;
case NOT_EQ:
return term() + " != " + literal;
case STARTS_WITH:
return term() + " startsWith \"" + literal + "\"";
case NOT_STARTS_WITH:
return term() + " notStartsWith \"" + literal + "\"";
case IN:
return term() + " in { " + literal + " }";
case NOT_IN:
return term() + " not in { " + literal + " }";
default:
return "Invalid literal predicate: operation = " + op();
}
return switch (op()) {
case LT -> term() + " < " + literal;
case LT_EQ -> term() + " <= " + literal;
case GT -> term() + " > " + literal;
case GT_EQ -> term() + " >= " + literal;
case EQ -> term() + " == " + literal;
case NOT_EQ -> term() + " != " + literal;
case STARTS_WITH -> term() + " startsWith \"" + literal + "\"";
case NOT_STARTS_WITH -> term() + " notStartsWith \"" + literal + "\"";
case IN -> term() + " in { " + literal + " }";
case NOT_IN -> term() + " not in { " + literal + " }";
default -> "Invalid literal predicate: operation = " + op();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ public Set<T> literalSet() {

@Override
public boolean test(T value) {
switch (op()) {
case IN:
return value != null && literalSet.contains(value);
case NOT_IN:
return value == null || !literalSet.contains(value);
default:
throw new IllegalStateException("Invalid operation for BoundSetPredicate: " + op());
}
return switch (op()) {
case IN -> value != null && literalSet.contains(value);
case NOT_IN -> value == null || !literalSet.contains(value);
default ->
throw new IllegalStateException("Invalid operation for BoundSetPredicate: " + op());
};
}

@Override
Expand All @@ -80,13 +78,10 @@ public boolean isEquivalentTo(Expression other) {

@Override
public String toString() {
switch (op()) {
case IN:
return term() + " in (" + COMMA.join(literalSet) + ")";
case NOT_IN:
return term() + " not in (" + COMMA.join(literalSet) + ")";
default:
return "Invalid unary predicate: operation = " + op();
}
return switch (op()) {
case IN -> term() + " in (" + COMMA.join(literalSet) + ")";
case NOT_IN -> term() + " not in (" + COMMA.join(literalSet) + ")";
default -> "Invalid unary predicate: operation = " + op();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ public BoundUnaryPredicate<T> asUnaryPredicate() {

@Override
public boolean test(T value) {
switch (op()) {
case IS_NULL:
return value == null;
case NOT_NULL:
return value != null;
case IS_NAN:
return NaNUtil.isNaN(value);
case NOT_NAN:
return !NaNUtil.isNaN(value);
default:
throw new IllegalStateException("Invalid operation for BoundUnaryPredicate: " + op());
}
return switch (op()) {
case IS_NULL -> value == null;
case NOT_NULL -> value != null;
case IS_NAN -> NaNUtil.isNaN(value);
case NOT_NAN -> !NaNUtil.isNaN(value);
default ->
throw new IllegalStateException("Invalid operation for BoundUnaryPredicate: " + op());
};
}

@Override
Expand All @@ -67,17 +63,12 @@ public boolean isEquivalentTo(Expression other) {

@Override
public String toString() {
switch (op()) {
case IS_NULL:
return "is_null(" + term() + ")";
case NOT_NULL:
return "not_null(" + term() + ")";
case IS_NAN:
return "is_nan(" + term() + ")";
case NOT_NAN:
return "not_nan(" + term() + ")";
default:
return "Invalid unary predicate: operation = " + op();
}
return switch (op()) {
case IS_NULL -> "is_null(" + term() + ")";
case NOT_NULL -> "not_null(" + term() + ")";
case IS_NAN -> "is_nan(" + term() + ")";
case NOT_NAN -> "not_nan(" + term() + ")";
default -> "Invalid unary predicate: operation = " + op();
};
}
}
Loading
Loading