This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 0bec957071 [CALCITE-5921] SqlOperatorFixture.checkFails and
checkAggFails don't check runtime failure
0bec957071 is described below
commit 0bec957071468a2e54a22519290ac101a752fcad
Author: Mihai Budiu <[email protected]>
AuthorDate: Sat Oct 14 21:17:32 2023 -0700
[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check
runtime failure
Signed-off-by: Mihai Budiu <[email protected]>
---
.../apache/calcite/runtime/CalciteResource.java | 2 +-
.../org/apache/calcite/runtime/SqlFunctions.java | 25 +++++++++-------
.../calcite/runtime/CalciteResource.properties | 2 +-
.../calcite/sql/test/SqlOperatorFixture.java | 2 +-
.../java/org/apache/calcite/sql/test/SqlTests.java | 12 +++++---
.../calcite/test/SqlOperatorFixtureImpl.java | 2 ++
.../org/apache/calcite/test/SqlOperatorTest.java | 34 +++++++++++-----------
.../org/apache/calcite/test/SqlRuntimeTester.java | 4 +--
8 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index dabc84ba1f..ee03bfe959 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -298,7 +298,7 @@ public interface CalciteResource {
@BaseMessage("Date literal ''{0}'' out of range")
ExInst<SqlValidatorException> dateLiteralOutOfRange(String a0);
- @BaseMessage("Input arguments of {0} out of range: {1,number,#}; should be
in the range of {2}")
+ @BaseMessage("Input arguments of {0} out of range: {1,number,#.#}; should be
in the range of {2}")
ExInst<CalciteException> inputArgumentsOfFunctionOutOfRange(String a0,
Number a1, String a2);
@BaseMessage("String literal continued on same line")
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 8a0e04c6d1..4ac14126fa 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -860,17 +860,22 @@ public class SqlFunctions {
assert map != null;
Set<String> keys = map.keySet();
Collection<String> values = map.values();
- switch (JsonScope.valueOf(jsonScope)) {
- case JSON_KEYS:
- return keys.contains(substr);
- case JSON_KEYS_AND_VALUES:
- return keys.contains(substr) || values.contains(substr);
- case JSON_VALUES:
- return values.contains(substr);
- default:
- throw new IllegalArgumentException("json_scope argument must be one of:
\"JSON_KEYS\", "
- + "\"JSON_VALUES\", \"JSON_KEYS_AND_VALUES\".");
+ try {
+ switch (JsonScope.valueOf(jsonScope)) {
+ case JSON_KEYS:
+ return keys.contains(substr);
+ case JSON_KEYS_AND_VALUES:
+ return keys.contains(substr) || values.contains(substr);
+ case JSON_VALUES:
+ return values.contains(substr);
+ default:
+ break;
+ }
+ } catch (IllegalArgumentException ignored) {
+ // Happens when jsonScope is not one of the legal enum values
}
+ throw new IllegalArgumentException("json_scope argument must be one of:
\"JSON_KEYS\", "
+ + "\"JSON_VALUES\", \"JSON_KEYS_AND_VALUES\".");
}
/** SQL <code>CONTAINS_SUBSTR(expr, substr)</code> operator. */
diff --git
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index c1f28de6e8..5475f2dafd 100644
---
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -102,7 +102,7 @@ OperandNotComparable=Operands {0} not comparable to each
other
TypeNotComparableEachOther=Types {0} not comparable to each other
NumberLiteralOutOfRange=Numeric literal ''{0}'' out of range
DateLiteralOutOfRange=Date literal ''{0}'' out of range
-InputArgumentsOfFunctionOutOfRange=Input arguments of {0} out of range:
{1,number,#}; should be in the range of {2}
+InputArgumentsOfFunctionOutOfRange=Input arguments of {0} out of range:
{1,number,#.#}; should be in the range of {2}
StringFragsOnSameLine=String literal continued on same line
AliasMustBeSimpleIdentifier=Table or column alias must be a simple identifier
CharLiteralAliasNotValid=Expecting alias, found character literal
diff --git
a/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.java
b/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.java
index 5eb94dcbc1..3ae3a3e2bb 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.java
@@ -96,7 +96,7 @@ public interface SqlOperatorFixture extends AutoCloseable {
// Error messages when an invalid time unit is given as
// input to extract for a particular input type.
String INVALID_EXTRACT_UNIT_CONVERTLET_ERROR =
- "Extract.*from.*type data is not supported";
+ "Was not expecting value '.*' for enumeration.*";
String INVALID_EXTRACT_UNIT_VALIDATION_ERROR =
"Cannot apply 'EXTRACT' to arguments of type .*'\n.*";
diff --git a/testkit/src/main/java/org/apache/calcite/sql/test/SqlTests.java
b/testkit/src/main/java/org/apache/calcite/sql/test/SqlTests.java
index 0296486c06..3c5deb5216 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/test/SqlTests.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/test/SqlTests.java
@@ -249,6 +249,10 @@ public abstract class SqlTests {
int actualEndLine = 100;
int actualEndColumn = 99;
+ if (ex instanceof ExceptionInInitializerError) {
+ ex = ((ExceptionInInitializerError) ex).getException();
+ }
+
// Search for an CalciteContextException somewhere in the stack.
CalciteContextException ece = null;
for (Throwable x = ex; x != null; x = x.getCause()) {
@@ -294,10 +298,10 @@ public abstract class SqlTests {
actualMessage = actualException.getMessage();
}
} else {
- final String message = ex.getMessage();
- if (message != null) {
+ actualMessage = ex.getMessage();
+ if (actualMessage != null) {
java.util.regex.Matcher matcher =
- LINE_COL_TWICE_PATTERN.matcher(message);
+ LINE_COL_TWICE_PATTERN.matcher(actualMessage);
if (matcher.matches()) {
actualLine = Integer.parseInt(matcher.group(1));
actualColumn = Integer.parseInt(matcher.group(2));
@@ -305,7 +309,7 @@ public abstract class SqlTests {
actualEndColumn = Integer.parseInt(matcher.group(4));
actualMessage = matcher.group(5);
} else {
- matcher = LINE_COL_PATTERN.matcher(message);
+ matcher = LINE_COL_PATTERN.matcher(actualMessage);
if (matcher.matches()) {
actualLine = Integer.parseInt(matcher.group(1));
actualColumn = Integer.parseInt(matcher.group(2));
diff --git
a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorFixtureImpl.java
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorFixtureImpl.java
index 0f7a4d0e1d..b2ba7bb29e 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorFixtureImpl.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorFixtureImpl.java
@@ -163,6 +163,7 @@ class SqlOperatorFixtureImpl implements SqlOperatorFixture {
SqlValidator validator = factory.createValidator();
SqlNode n = parseAndValidate(validator, sql);
assertNotNull(n);
+ tester.checkFails(factory, sap, expectedError, runtime);
} else {
checkQueryFails(StringAndPos.of(sql),
expectedError);
@@ -185,6 +186,7 @@ class SqlOperatorFixtureImpl implements SqlOperatorFixture {
SqlValidator validator = factory.createValidator();
SqlNode n = parseAndValidate(validator, sql);
assertNotNull(n);
+ tester.checkAggFails(factory, expr, inputValues, expectedError, runtime);
} else {
checkQueryFails(StringAndPos.of(sql), expectedError);
}
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index bfc14daab7..a9a24cfe92 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -1438,10 +1438,10 @@ public class SqlOperatorTest {
/** Test case for
* <a
href="https://issues.apache.org/jira/browse/CALCITE-4861">[CALCITE-4861]
* Optimization of chained CAST calls leads to unexpected behavior</a>. */
- @Test void testChainedCast() {
+ @Test @Disabled("CALCITE-5990") void testChainedCast() {
final SqlOperatorFixture f = fixture();
f.checkFails("CAST(CAST(CAST(123456 AS TINYINT) AS INT) AS BIGINT)",
- "Value out of range. Value:\"123456\"", true);
+ ".*Value 123456 out of range", true);
}
@Test void testCase() {
@@ -1866,10 +1866,10 @@ public class SqlOperatorTest {
f.checkFails("code_points_to_bytes(array[-1])",
"Input arguments of CODE_POINTS_TO_BYTES out of range: -1;"
- + " should be in the range of [0, 255]", true);
+ + " should be in the range of \\[0, 255\\]", true);
f.checkFails("code_points_to_bytes(array[2147483648, 1])",
"Input arguments of CODE_POINTS_TO_BYTES out of range: 2147483648;"
- + " should be in the range of [0, 255]", true);
+ + " should be in the range of \\[0, 255\\]", true);
f.checkString("code_points_to_bytes(array[65, 66, 67, 68])", "41424344",
"VARBINARY NOT NULL");
f.checkString("code_points_to_bytes(array[255, 254, 65, 64])", "fffe4140",
@@ -1899,10 +1899,10 @@ public class SqlOperatorTest {
f.checkFails("code_points_to_string(array[-1])",
"Input arguments of CODE_POINTS_TO_STRING out of range: -1;"
- + " should be in the range of [0, 0xD7FF] and [0xE000, 0x10FFFF]",
true);
+ + " should be in the range of \\[0, 0xD7FF\\] and \\[0xE000,
0x10FFFF\\]", true);
f.checkFails("code_points_to_string(array[2147483648, 1])",
"Input arguments of CODE_POINTS_TO_STRING out of range: 2147483648;"
- + " should be in the range of [0, 0xD7FF] and [0xE000, 0x10FFFF]",
true);
+ + " should be in the range of \\[0, 0xD7FF\\] and \\[0xE000,
0x10FFFF\\]", true);
f.checkString("code_points_to_string(array[65, 66, 67, 68])", "ABCD",
"VARCHAR NOT NULL");
@@ -3808,7 +3808,7 @@ public class SqlOperatorTest {
// some negative tests
f.checkFails("'yd' similar to '[x-ze-a]d'",
- "Illegal character range near index 6\n"
+ ".*Illegal character range near index 6\n"
+ "\\[x-ze-a\\]d\n"
+ " \\^",
true); // illegal range
@@ -3816,10 +3816,10 @@ public class SqlOperatorTest {
// Slightly different error message from JDK 13 onwards
final String expectedError =
TestUtil.getJavaMajorVersion() >= 13
- ? "Illegal repetition near index 22\n"
+ ? ".*Illegal repetition near index 22\n"
+ "\\[\\:LOWER\\:\\]\\{2\\}\\[\\:DIGIT\\:\\]\\{,5\\}\n"
+ " \\^"
- : "Illegal repetition near index 20\n"
+ : ".*Illegal repetition near index 20\n"
+ "\\[\\:LOWER\\:\\]\\{2\\}\\[\\:DIGIT\\:\\]\\{,5\\}\n"
+ " \\^";
f.checkFails("'yd3223' similar to '[:LOWER:]{2}[:DIGIT:]{,5}'",
@@ -7229,13 +7229,13 @@ public class SqlOperatorTest {
f.checkNull("atanh(cast(null as integer))");
f.checkNull("atanh(cast(null as double))");
f.checkFails("atanh(1)",
- "Input arguments of ATANH out of range: 1; should be in the range of
(-1, 1)",
+ "Input arguments of ATANH out of range: 1; should be in the range of
\\(-1, 1\\)",
true);
f.checkFails("atanh(-1)",
- "Input arguments of ATANH out of range: -1; should be in the range
of (-1, 1)",
+ "Input arguments of ATANH out of range: -1; should be in the range
of \\(-1, 1\\)",
true);
f.checkFails("atanh(-1.5)",
- "Input arguments of ATANH out of range: -1.5; should be in the range
of (-1, 1)",
+ "Input arguments of ATANH out of range: -1.5; should be in the range
of \\(-1, 1\\)",
true);
};
f0.forEachLibrary(list(SqlLibrary.ALL), consumer);
@@ -8497,7 +8497,7 @@ public class SqlOperatorTest {
f.checkFails("lpad('12345', -3)",
"Second argument for LPAD/RPAD must not be negative", true);
f.checkFails("lpad('12345', 3, '')",
- "Third argument (pad pattern) for LPAD/RPAD must not be empty", true);
+ "Third argument \\(pad pattern\\) for LPAD/RPAD must not be empty",
true);
f.checkString("lpad(x'aa', 4, x'bb')", "bbbbbbaa", "VARBINARY NOT NULL");
f.checkString("lpad(x'aa', 4)", "202020aa", "VARBINARY NOT NULL");
f.checkString("lpad(x'aaaaaa', 2)", "aaaa", "VARBINARY NOT NULL");
@@ -8507,7 +8507,7 @@ public class SqlOperatorTest {
f.checkFails("lpad(x'aa', -3)",
"Second argument for LPAD/RPAD must not be negative", true);
f.checkFails("lpad(x'aa', 3, x'')",
- "Third argument (pad pattern) for LPAD/RPAD must not be empty", true);
+ "Third argument \\(pad pattern\\) for LPAD/RPAD must not be empty",
true);
}
@Test void testRpadFunction() {
@@ -8522,7 +8522,7 @@ public class SqlOperatorTest {
f.checkFails("rpad('12345', -3)",
"Second argument for LPAD/RPAD must not be negative", true);
f.checkFails("rpad('12345', 3, '')",
- "Third argument (pad pattern) for LPAD/RPAD must not be empty", true);
+ "Third argument \\(pad pattern\\) for LPAD/RPAD must not be empty",
true);
f.checkString("rpad(x'aa', 4, x'bb')", "aabbbbbb", "VARBINARY NOT NULL");
f.checkString("rpad(x'aa', 4)", "aa202020", "VARBINARY NOT NULL");
@@ -8533,7 +8533,7 @@ public class SqlOperatorTest {
f.checkFails("rpad(x'aa', -3)",
"Second argument for LPAD/RPAD must not be negative", true);
f.checkFails("rpad(x'aa', 3, x'')",
- "Third argument (pad pattern) for LPAD/RPAD must not be empty", true);
+ "Third argument \\(pad pattern\\) for LPAD/RPAD must not be empty",
true);
}
@Test void testContainsSubstrFunc() {
@@ -9110,7 +9110,7 @@ public class SqlOperatorTest {
// test with illegal argument
f.checkFails("format_number(12332.123456, -1)",
- "Illegal arguments for 'FORMAT_NUMBER' function:"
+ "Illegal arguments for FORMAT_NUMBER function:"
+ " negative decimal value not allowed",
true);
diff --git
a/testkit/src/main/java/org/apache/calcite/test/SqlRuntimeTester.java
b/testkit/src/main/java/org/apache/calcite/test/SqlRuntimeTester.java
index b130e828eb..2017cd9304 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlRuntimeTester.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlRuntimeTester.java
@@ -36,9 +36,7 @@ class SqlRuntimeTester extends AbstractSqlTester {
@Override public void checkFails(SqlTestFactory factory, StringAndPos sap,
String expectedError, boolean runtime) {
- final StringAndPos sap2 =
- StringAndPos.of(runtime ? buildQuery2(factory, sap.addCarets())
- : buildQuery(sap.addCarets()));
+ final StringAndPos sap2 = StringAndPos.of(buildQuery(sap.addCarets()));
assertExceptionIsThrown(factory, sap2, expectedError, runtime);
}