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 @@ -75,6 +75,7 @@
import java.util.Set;

import static org.apache.calcite.rel.RelDistributions.EMPTY;
import static org.apache.calcite.util.Static.RESOURCE;

/**
* Utilities for converting {@link org.apache.calcite.rel.RelNode}
Expand Down Expand Up @@ -678,7 +679,7 @@ SqlOperator toOp(Map<String, Object> map) {
if (class_ != null) {
return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
}
return null;
throw RESOURCE.noOperator(name, kind, syntax).ex();
}

SqlAggFunction toAggregation(Map<String, Object> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,4 +931,7 @@ ExInst<CalciteException> invalidTypesForComparison(String clazzName0, String op,

@BaseMessage("Different length for bitwise operands: the first: {0,number,#}, the second: {1,number,#}")
ExInst<CalciteException> differentLengthForBitwiseOperands(int l0, int l1);

@BaseMessage("No operator for ''{0}'' with kind: ''{1}'', syntax: ''{2}'' during JSON deserialization")
ExInst<CalciteException> noOperator(String name, String kind, String syntax);
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,5 @@ InvalidInputForExtractValue=Invalid input for EXTRACTVALUE: xml: ''{0}'', xpath
InvalidInputForExtractXml=Invalid input for EXTRACT xpath: ''{0}'', namespace: ''{1}''
InvalidInputForExistsNode=Invalid input for EXISTSNODE xpath: ''{0}'', namespace: ''{1}''
DifferentLengthForBitwiseOperands=Different length for bitwise operands: the first: {0,number,#}, the second: {1,number,#}
NoOperator=No operator for ''{0}'' with kind: ''{1}'', syntax: ''{2}'' during JSON deserialization
# End CalciteResource.properties
27 changes: 27 additions & 0 deletions core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Unit test for {@link org.apache.calcite.rel.externalize.RelJson}.
Expand Down Expand Up @@ -1131,6 +1132,32 @@ private RelNode mockCountOver(String table,
assertThat(s, isLinux(expected));
}

@Test void testDeserializeInvalidOperatorName() {
final FrameworkConfig config = RelBuilderTest.config().build();
final RelBuilder builder = RelBuilder.create(config);
final RelNode rel = builder
.scan("EMP")
.project(
builder.field("JOB"),
builder.field("SAL"))
.aggregate(
builder.groupKey("JOB"),
builder.max("max_sal", builder.field("SAL")),
builder.min("min_sal", builder.field("SAL")))
.project(
builder.field("max_sal"),
builder.field("min_sal"))
.build();
final RelJsonWriter jsonWriter = new RelJsonWriter();
rel.explain(jsonWriter);
// mock a non exist SqlOperator
String relJson = jsonWriter.asString().replace("\"name\": \"MAX\"", "\"name\": \"MAXS\"");
assertThrows(RuntimeException.class,
() -> deserializeAndDumpToTextFormat(getSchema(rel), relJson),
"org.apache.calcite.runtime.CalciteException: "
+ "No operator for 'MAXS' with kind: 'MAX', syntax: 'FUNCTION' during JSON deserialization");
}

private RelNode createSortPlan(RelDistribution distribution) {
final FrameworkConfig config = RelBuilderTest.config().build();
final RelBuilder builder = RelBuilder.create(config);
Expand Down