Skip to content
Merged
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
1 change: 1 addition & 0 deletions buildSrc/src/main/resources/substrait-pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

<rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
<rule ref="category/java/bestpractices.xml/MissingOverride" />
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes" />
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public Expression visit(
.setValue(Any.parseFrom(expr.value())))
.build();
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
case INTERVAL_COMPOUND:
{
if (!literal.getIntervalCompound().getIntervalDayToSecond().hasPrecision()) {
throw new RuntimeException(
throw new UnsupportedOperationException(
"Interval compound with deprecated version of interval day (ie. no precision) is not supported");
}
return ExpressionCreator.intervalCompound(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.substrait.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -736,7 +737,7 @@ public static ExtensionCollection load(List<String> resourcePaths) {
try (InputStream stream = ExtensionCollection.class.getResourceAsStream(path)) {
return load(path, stream);
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
})
.collect(Collectors.toList());
Expand All @@ -752,7 +753,7 @@ public static ExtensionCollection load(String namespace, String str) {
ExtensionSignatures doc = objectMapper(namespace).readValue(str, ExtensionSignatures.class);
return buildExtensionCollection(namespace, doc);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand All @@ -764,7 +765,7 @@ public static ExtensionCollection load(String namespace, InputStream stream) {
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException("Failure while parsing " + namespace, ex);
throw new IllegalStateException("Failure while parsing " + namespace, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ protected Extension.Optimization optimizationFromAdvancedExtension(com.google.pr
* io.substrait.proto.AdvancedExtension#getEnhancement()} data
*/
protected Extension.Enhancement enhancementFromAdvancedExtension(com.google.protobuf.Any any) {
throw new RuntimeException("enhancements cannot be ignored by consumers");
throw new IllegalStateException("enhancements cannot be ignored by consumers");
}

/** Override to provide a custom converter for {@link ExtensionLeafRel#getDetail()} data */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public Rel visit(HashJoin hashJoin, EmptyVisitationContext context) throws Runti
List<FieldReference> rightKeys = hashJoin.getRightKeys();

if (leftKeys.size() != rightKeys.size()) {
throw new RuntimeException("Number of left and right keys must be equal.");
throw new IllegalArgumentException("Number of left and right keys must be equal.");
}

builder.addAllLeftKeys(leftKeys.stream().map(this::toProto).collect(Collectors.toList()));
Expand All @@ -321,7 +321,7 @@ public Rel visit(MergeJoin mergeJoin, EmptyVisitationContext context) throws Run
List<FieldReference> rightKeys = mergeJoin.getRightKeys();

if (leftKeys.size() != rightKeys.size()) {
throw new RuntimeException("Number of left and right keys must be equal.");
throw new IllegalArgumentException("Number of left and right keys must be equal.");
}

builder.addAllLeftKeys(leftKeys.stream().map(this::toProto).collect(Collectors.toList()));
Expand Down Expand Up @@ -535,7 +535,7 @@ public Rel visit(Expand expand, EmptyVisitationContext context) throws RuntimeEx
.addAllDuplicates(toProto(sf.getDuplicates())))
.build());
} else {
throw new RuntimeException(
throw new IllegalArgumentException(
"Consistent or Switching fields must be set for the Expand relation.");
}
});
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/substrait/type/YamlRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Stream<SimpleExtension.Function> parse(String name) {
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException("Failure while parsing file " + name, ex);
throw new IllegalStateException("Failure while parsing file " + name, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ StringHolder asStringHolder(Any any) {
try {
return new StringHolder(any.unpack(StringValue.class).getValue());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down
3 changes: 3 additions & 0 deletions examples/substrait-spark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id("java")
id("com.diffplug.spotless") version "7.1.0"
id("substrait.java-conventions")
}

repositories {
Expand Down Expand Up @@ -37,3 +38,5 @@ tasks.named<Test>("test") {
}

java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }

tasks.pmdMain { dependsOn(":core:shadowJar") }
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
if (c.method != null) RuntimeReflection.register(c.method);
});
} catch (Exception e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.substrait.isthmus;

import static io.substrait.isthmus.SqlToSubstrait.EXTENSION_COLLECTION;
import static io.substrait.isthmus.SqlConverterBase.EXTENSION_COLLECTION;

import com.google.common.collect.ImmutableList;
import io.substrait.expression.Expression;
Expand Down Expand Up @@ -415,7 +415,8 @@ private RexNode directedRexNode(Expression.SortField sortField, Context context)
return relBuilder.nullsLast(relBuilder.desc(rexNode));
}
if (sortDirection == Expression.SortDirection.CLUSTERED) {
throw new RuntimeException(String.format("Unexpected Expression.SortDirection: Clustered!"));
throw new UnsupportedOperationException(
String.format("Unexpected Expression.SortDirection: Clustered!"));
}

throw new IllegalArgumentException("Unsupported sort direction: " + sortDirection);
Expand All @@ -428,10 +429,12 @@ public RelNode visit(Fetch fetch, Context context) throws RuntimeException {
long count = optCount.orElse(-1L);
var offset = fetch.getOffset();
if (offset > Integer.MAX_VALUE) {
throw new RuntimeException(String.format("offset is overflowed as an integer: %d", offset));
throw new IllegalArgumentException(
String.format("offset is overflowed as an integer: %d", offset));
}
if (count > Integer.MAX_VALUE) {
throw new RuntimeException(String.format("count is overflowed as an integer: %d", count));
throw new IllegalArgumentException(
String.format("count is overflowed as an integer: %d", count));
}
RelNode node = relBuilder.push(child).limit((int) offset, (int) count).build();
return applyRemap(node, fetch.getRemap());
Expand Down Expand Up @@ -463,7 +466,7 @@ private RelFieldCollation toRelFieldCollation(Expression.SortField sortField, Co
fieldDirection = RelFieldCollation.Direction.CLUSTERED;
nullDirection = RelFieldCollation.NullDirection.UNSPECIFIED;
} else {
throw new RuntimeException(
throw new UnsupportedOperationException(
String.format("Unexpected Expression.SortDirection enum: %s !", sortDirection));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Optional<SqlOperator> getSqlOperatorFromSubstraitFunc(String key, Type ou
if (resolvedOperators.size() == 1) {
return Optional.of(resolvedOperators.get(0));
} else if (resolvedOperators.size() > 1) {
throw new RuntimeException(
throw new IllegalStateException(
String.format(
"Found %d SqlOperators: %s for ScalarFunction %s: ",
resolvedOperators.size(), resolvedOperators, key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void main(String[] args) {
SqlOperator op = (SqlOperator) f.get(null);
return true;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
})
.filter(f -> Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers()))
Expand All @@ -44,7 +44,7 @@ private static SqlOperator toOp(Field f) {
try {
return (SqlOperator) f.get(null);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private Aggregate.Measure functionPicker(Rel input, int field, String fname) {
case "avg":
return b.avg(input, field);
default:
throw new RuntimeException(String.format("no function is associated with %s", fname));
throw new UnsupportedOperationException(
String.format("no function is associated with %s", fname));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.substrait.isthmus;

import static io.substrait.isthmus.SqlToSubstrait.EXTENSION_COLLECTION;
import static io.substrait.isthmus.SqlConverterBase.EXTENSION_COLLECTION;
import static io.substrait.isthmus.SubstraitTypeSystem.YEAR_MONTH_INTERVAL;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.substrait.type.Type;
import io.substrait.type.TypeCreator;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class CustomFunctionTest extends PlanTestBase {
try {
FUNCTIONS_CUSTOM = asString("extensions/functions_custom.yaml");
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static String asString(String resource) throws IOException {
TPCH_CATALOG =
SubstraitCreateStatementParser.processCreateStatementsToCatalog(tpchCreateStatements);
} catch (IOException | SqlParseException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion isthmus/src/test/java/io/substrait/isthmus/RelCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public RelRoot parse(String sql) {
RelRoot root = converter.convertQuery(parsed, true, true);
return root;
} catch (SqlParseException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ColumnAppendDetail unpack(Any any) {
.from(proto.getLiteral()));
return new ColumnAppendDetail(literal);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down Expand Up @@ -208,7 +208,7 @@ public RelNode visit(ExtensionLeaf extensionLeaf, Context context) {
return new ColumnAppenderRel(
relBuilder.getCluster(), traits, literal, Collections.emptyList());
}
throw new RuntimeException("detail was not ColumnAppendDetail");
throw new UnsupportedOperationException("detail was not ColumnAppendDetail");
}

@Override
Expand All @@ -220,7 +220,7 @@ public RelNode visit(ExtensionSingle extensionSingle, Context context) throws Ru
return new ColumnAppenderRel(
input.getCluster(), input.getTraitSet(), literal, List.of(input));
}
throw new RuntimeException("detail was not ColumnAppendDetail");
throw new UnsupportedOperationException("detail was not ColumnAppendDetail");
}

@Override
Expand All @@ -235,7 +235,7 @@ public RelNode visit(ExtensionMulti extensionMulti, Context context) throws Runt
return new ColumnAppenderRel(
inputs.get(0).getCluster(), inputs.get(0).getTraitSet(), literal, inputs);
}
throw new RuntimeException("detail was not ColumnAppendDetail");
throw new UnsupportedOperationException("detail was not ColumnAppendDetail");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class ToLogicalPlan(spark: SparkSession = SparkSession.builder().getOrCreate())
case SExpression.SortDirection.ASC_NULLS_LAST => (Ascending, NullsLast)
case SExpression.SortDirection.DESC_NULLS_LAST => (Descending, NullsLast)
case other =>
throw new RuntimeException(s"Unexpected Expression.SortDirection enum: $other !")
throw new UnsupportedOperationException(
s"Unexpected Expression.SortDirection enum: $other !")
}
SortOrder(expression, direction, nullOrdering, Seq.empty)
}
Expand Down
Loading