[NO ISSUE][COMP] Improve error reporting for unknown window functions
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Raise error early when an unknown window function is found
Change-Id: I04983a17fc569ff96770a8da06fe98715002fdcb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3246
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.4.query.sqlpp
new file mode 100644
index 0000000..59a0127
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_negative/win_negative.4.query.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description : Test error message for an unknown window function
+ * : with identifier resolution
+ * Expected Res : FAILURE
+ */
+
+from (
+ from range(1, 2) x, range(1, 2) y select x, y
+) t
+select unknown_func(x) over (partition by y)
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 6f530ac..834b435 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9325,6 +9325,7 @@
<expected-error>ASX0002: Type mismatch</expected-error>
<expected-error>ASX1101: Unexpected ORDER BY clause in window expression</expected-error>
<expected-error>ASX1037: Invalid query parameter compiler.windowmemory</expected-error>
+ <expected-error>ASX1102: Expected window or aggregate function, got: unknown_func</expected-error>
<source-location>false</source-location>
</compilation-unit>
</test-case>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppWindowRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppWindowRewriteVisitor.java
index 0d744b3..b18cc02 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppWindowRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppWindowRewriteVisitor.java
@@ -80,6 +80,9 @@
throw new CompilationException(ErrorCode.COMPILATION_ERROR, winExpr.getSourceLocation(), "");
}
winExpr.setExprList(newExprList);
+ } else if (!FunctionMapUtil.isCoreAggregateFunction(signature)) {
+ throw new CompilationException(ErrorCode.COMPILATION_EXPECTED_WINDOW_FUNCTION, winExpr.getSourceLocation(),
+ signature.getName());
}
return winExpr;
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
index a6fa730..b220d8d 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
@@ -88,6 +88,24 @@
}
/**
+ * Whether a function signature is a SQL++ core aggregate function.
+ *
+ * @param fs,
+ * the function signature.
+ * @return true if the function signature is a SQL++ core aggregate,
+ * false otherwise.
+ */
+ public static boolean isCoreAggregateFunction(FunctionSignature fs) {
+ String internalName = getInternalCoreAggregateFunctionName(fs);
+ if (internalName != null) {
+ FunctionIdentifier fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, internalName, fs.getArity());
+ IFunctionInfo finfo = FunctionUtil.getFunctionInfo(fi);
+ return finfo != null && BuiltinFunctions.getAggregateFunction(finfo.getFunctionIdentifier()) != null;
+ }
+ return false;
+ }
+
+ /**
* Maps a user invoked function signature to a system internal function signature.
*
* @param fs