[NO ISSUE][COMP] Clean up error messages for unresolvable identifiers
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Cleanup error messages for unresolvable identifiers
- Add negative test case for unresolvable identifier in SQL aggregate function
Change-Id: I82efc98f7661eaacaded1ce86a27f0a8f4bd4d87
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2744
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.1.ddl.sqlpp
new file mode 100644
index 0000000..a5b4314
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.1.ddl.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+drop dataverse gby if exists;
+create dataverse gby;
+
+use gby;
+
+create type testType as open {
+ id : string
+};
+
+create dataset customers(testType) primary key id;
+create dataset orders(testType) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.2.query.sqlpp
new file mode 100644
index 0000000..1d0c963
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-07-negative/sugar-07-negative.2.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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 undefined variable reference in SQL aggregate function
+ */
+
+use gby;
+
+select c_id, min(IDENT)
+from customers c, orders o
+where c.c_id = o.c_id
+group by c.c_id
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 fd53ea4..6b2ccb2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1591,7 +1591,7 @@
<test-case FilePath="custord">
<compilation-unit name="join_q_09">
<output-dir compare="Text">join_q_01</output-dir>
- <expected-error>Cannot resolve ambiguous alias reference for undefined identifier age</expected-error>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier age</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="custord">
@@ -1660,7 +1660,7 @@
<test-case FilePath="dapd">
<compilation-unit name="q2-3">
<output-dir compare="Text">q2</output-dir>
- <expected-error>Cannot resolve ambiguous alias reference for undefined identifier sig_id</expected-error>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier sig_id</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="dapd">
@@ -3011,13 +3011,13 @@
<test-case FilePath="group-by">
<compilation-unit name="sugar-02">
<output-dir compare="Text">core-02</output-dir>
- <expected-error>Cannot resolve ambiguous alias reference for undefined identifier deptId</expected-error>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier deptId</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="group-by">
<compilation-unit name="sugar-02-2">
<output-dir compare="Text">core-02</output-dir>
- <expected-error>Cannot resolve ambiguous alias reference for undefined identifier deptId</expected-error>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier deptId</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="group-by">
@@ -3056,6 +3056,12 @@
</compilation-unit>
</test-case>
<test-case FilePath="group-by">
+ <compilation-unit name="sugar-07-negative">
+ <output-dir compare="Text">core-01</output-dir>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier IDENT</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="group-by">
<compilation-unit name="null">
<output-dir compare="Text">null</output-dir>
</compilation-unit>
@@ -5704,7 +5710,7 @@
<test-case FilePath="resolution">
<compilation-unit name="conflict-fields-dataset">
<output-dir compare="Text">conflict-field-dataset</output-dir>
- <expected-error>Cannot resolve ambiguous alias reference for undefined identifier samptable</expected-error>
+ <expected-error>Cannot resolve ambiguous alias reference for identifier samptable</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="resolution">
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index d600762..46326e1 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -141,8 +141,8 @@
1070 = Metadata error. %1$s
1071 = A dataverse with this name %1$s already exists.
1072 = A dataset with this name %1$s already exists.
-1073 = Cannot resolve alias reference for undefined identifier %1$s in %2$s
-1074 = Cannot resolve ambiguous alias reference for undefined identifier %1$s in %2$s
+1073 = Cannot resolve alias reference for undefined identifier %1$s
+1074 = Cannot resolve ambiguous alias reference for identifier %1$s
1075 = Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.
1076 = Cannot find dataset %1$s because there is no dataverse declared, nor an alias with name %1$s!
1077 = Cannot find dataset %1$s in dataverse %2$s nor an alias with name %1$s!
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByAggregationSugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByAggregationSugarVisitor.java
index e133bad..2663837 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByAggregationSugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByAggregationSugarVisitor.java
@@ -293,8 +293,8 @@
faOuter.setSourceLocation(usedVar.getSourceLocation());
varExprMap.put(usedVar, faOuter);
} else {
- throw new CompilationException(ErrorCode.UNDEFINED_IDENTIFIER, usedVar.getSourceLocation(),
- usedVar.getVar().getValue(), String.valueOf(fieldVars));
+ throw new CompilationException(ErrorCode.AMBIGUOUS_IDENTIFIER, usedVar.getSourceLocation(),
+ SqlppVariableUtil.toUserDefinedVariableName(usedVar.getVar().getValue()).getValue());
}
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
index 20071e3..b5fd996 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
@@ -128,7 +128,7 @@
default:
// More than one possibilities.
throw new CompilationException(ErrorCode.AMBIGUOUS_IDENTIFIER, sourceLoc,
- SqlppVariableUtil.toUserDefinedVariableName(varName).getValue(), String.valueOf(localVars));
+ SqlppVariableUtil.toUserDefinedVariableName(varName).getValue());
}
}