You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2019/03/05 23:25:12 UTC

[asterixdb] branch master updated: [NO ISSUE][COMP] Improve error reporting for unknown window functions

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 397f71d  [NO ISSUE][COMP] Improve error reporting for unknown window functions
397f71d is described below

commit 397f71d3e442a593f1a666fdf3b64b85901a5f94
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Mon Mar 4 14:57:46 2019 -0800

    [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 <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../window/win_negative/win_negative.4.query.sqlpp | 28 ++++++++++++++++++++++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  1 +
 .../visitor/SqlppWindowRewriteVisitor.java         |  3 +++
 .../asterix/lang/sqlpp/util/FunctionMapUtil.java   | 18 ++++++++++++++
 4 files changed, 50 insertions(+)

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 @@ public final class SqlppWindowRewriteVisitor extends AbstractSqlppExpressionExtr
                 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 @@ public class FunctionMapUtil {
     }
 
     /**
+     * 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