Repository: asterixdb
Updated Branches:
  refs/heads/master 8b6578add -> 7722e5d4d


[ASTERIXDB-2159][API] ValidateUtil throws NPE

- user model changes: no
- storage format changes: no
- interface change: no

Details:

Fix a case where ValidateUtil throws an NPE instead of using error codes.

Change-Id: If467e484e01e9085f2eb8a943a4178b44a384a02
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2137
Sonar-Qube: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Contrib: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Dmitry Lychagin <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/7722e5d4
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/7722e5d4
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/7722e5d4

Branch: refs/heads/master
Commit: 7722e5d4d27120685b7a2b0076899409746c2027
Parents: 8b6578a
Author: Ian Maxon <[email protected]>
Authored: Wed Nov 8 16:42:43 2017 -0800
Committer: Ian Maxon <[email protected]>
Committed: Fri Nov 10 15:19:52 2017 -0800

----------------------------------------------------------------------
 .../asterix/translator/util/ValidateUtil.java   |  4 +++
 .../load-with-autogenerated-no-field.1.ddl.aql  | 34 ++++++++++++++++++++
 ...oad-with-autogenerated-pk_txt_01.1.ddl.sqlpp | 34 ++++++++++++++++++++
 .../src/test/resources/runtimets/testsuite.xml  |  6 ++++
 .../resources/runtimets/testsuite_sqlpp.xml     |  6 ++++
 5 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7722e5d4/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
index d262bb8..cda9dd3 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
@@ -118,6 +118,10 @@ public class ValidateUtil {
             }
             List<String> fieldName = partitioningExprs.get(0);
             IAType fieldType = recType.getSubFieldType(fieldName);
+            if (fieldType == null) {
+                String unTypeField = fieldName.get(0) == null ? "" : 
fieldName.get(0);
+                throw new 
CompilationException(ErrorCode.COMPILATION_FIELD_NOT_FOUND, unTypeField);
+            }
             partitioningExprTypes.add(fieldType);
             ATypeTag pkTypeTag = fieldType.getTypeTag();
             if (pkTypeTag != ATypeTag.UUID) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7722e5d4/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/load-with-autogenerated-no-field/load-with-autogenerated-no-field.1.ddl.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/load-with-autogenerated-no-field/load-with-autogenerated-no-field.1.ddl.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/load-with-autogenerated-no-field/load-with-autogenerated-no-field.1.ddl.aql
new file mode 100644
index 0000000..a0764a0
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/load-with-autogenerated-no-field/load-with-autogenerated-no-field.1.ddl.aql
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+// try to create autogenerated key on field not mentioned in type, should fail
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type DBLPType as open {
+  id: uuid,
+  dblpid: string,
+  title: string,
+  authors: string,
+  misc: string
+}
+
+create dataset DBLP(DBLPType) primary key not_id autogenerated;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7722e5d4/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/load-with-autogenerated-no-field/load-with-autogenerated-pk_txt_01.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/load-with-autogenerated-no-field/load-with-autogenerated-pk_txt_01.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/load-with-autogenerated-no-field/load-with-autogenerated-pk_txt_01.1.ddl.sqlpp
new file mode 100644
index 0000000..b04d413
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/load-with-autogenerated-no-field/load-with-autogenerated-pk_txt_01.1.ddl.sqlpp
@@ -0,0 +1,34 @@
+/*
+ * 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 test if exists;
+create  dataverse test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : uuid,
+  title : string,
+  authors : string
+};
+
+create dataset DBLP(DBLPType) primary key not_id autogenerated ;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7722e5d4/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 47560f6..8987a7f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -1941,6 +1941,12 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
+      <compilation-unit name="load-with-autogenerated-no-field">
+        <output-dir 
compare="Text">load-with-autogenerated-no-field</output-dir>
+        <expected-error>ASX1014: Field "not_id" is not found 
[CompilationException]</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dml">
       <compilation-unit name="load-with-index">
         <output-dir compare="Text">load-with-index</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7722e5d4/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
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 f0ad1a4..484e395 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1887,6 +1887,12 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
+      <compilation-unit name="load-with-autogenerated-no-field">
+        <output-dir 
compare="Text">load-with-autogenerated-no-field</output-dir>
+        <expected-error>org.apache.asterix.common.exceptions.AsterixException: 
ASX1014: Field "not_id" is not found</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dml">
       <compilation-unit name="insert-return-records">
         <output-dir compare="Text">insert-return-records</output-dir>
       </compilation-unit>

Reply via email to