>From Peeyush Gupta <[email protected]>:

Peeyush Gupta has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17488 )


Change subject: [ASTERIXDB-3166][FUN] Error with get_object_fields with open 
list type
......................................................................

[ASTERIXDB-3166][FUN] Error with get_object_fields with open list type

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

Details:
get_object_fields function causes null pointer exception when used
on a dataset containing an open list type.

Change-Id: Ie413d286738f571df81e2f450a3fb0b132dc5521
---
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.1.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.3.query.sqlpp
M 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/objects/get-object-fields/open-list-type/open-list-type.3.adm
M 
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.2.update.sqlpp
6 files changed, 108 insertions(+), 3 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/88/17488/1

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
index 77fc7c5..1756378 100644
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
@@ -82,6 +82,11 @@
       <output-dir compare="Text">missing-fields</output-dir>
     </compilation-unit>
   </test-case>
+  <test-case FilePath="objects/get-object-fields">
+    <compilation-unit name="open-list-type">
+      <output-dir compare="Text">open-list-type</output-dir>
+    </compilation-unit>
+  </test-case>
   <test-case FilePath="objects/get-object-field-value">
     <compilation-unit name="documentation-example">
       <output-dir compare="Text">documentation-example</output-dir>
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.1.ddl.sqlpp
new file mode 100644
index 0000000..3874fc6
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.1.ddl.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * 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  : Testing get-object-fields where some schema (complex) fields 
are missing or null
+ */
+
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+
+USE test;
+
+CREATE TYPE t1 AS {
+  id: string
+};
+
+
+CREATE DATASET ds1(t1) PRIMARY KEY id;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.2.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.2.update.sqlpp
new file mode 100644
index 0000000..8a9a59e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.2.update.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+USE test;
+
+INSERT INTO ds1([{"id": "xyz", "some_list":["a","b"]}]);
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.3.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.3.query.sqlpp
new file mode 100644
index 0000000..d45f083
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/get-object-fields/open-list-type/open-list-type.3.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+USE test;
+
+SELECT VALUE get_object_fields(d) FROM ds1 d;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/get-object-fields/open-list-type/open-list-type.3.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/get-object-fields/open-list-type/open-list-type.3.adm
new file mode 100644
index 0000000..7288b9a
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/get-object-fields/open-list-type/open-list-type.3.adm
@@ -0,0 +1 @@
+[ { "field-name": "id", "field-type": "string", "is-open": false }, { 
"field-name": "some_list", "field-type": "array", "is-open": true, "list": [ { 
"field-type": "string" }, { "field-type": "string" } ] } ]
\ No newline at end of file
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
index 25dd73e..413081c 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
@@ -37,6 +37,7 @@
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.om.types.AbstractCollectionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
@@ -78,6 +79,9 @@
             
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);

     private final static ARecordType openType = 
DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE;
+    private final static AOrderedListType openOrderedListType = 
DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE;
+    private final static AUnorderedListType openUnOrderedListType =
+            DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE;

     public void processRecord(ARecordPointable recordAccessor, ARecordType 
recType, DataOutput out, int level)
             throws IOException {
@@ -151,14 +155,15 @@
             // write nested or list types
             if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG || tag == 
ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
                     || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
-                IAType fieldType = null;
                 ArrayBackedValueStorage tmpValue = getTempBuffer();
                 tmpValue.reset();
                 recordAccessor.getOpenFieldValue(recType, i, 
tmpValue.getDataOutput());
                 if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
-                    addNestedField(tmpValue, fieldType, fieldRecordBuilder, 
level + 1);
+                    addNestedField(tmpValue, openType, fieldRecordBuilder, 
level + 1);
+                } else if (tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                    addListField(tmpValue, openOrderedListType, 
fieldRecordBuilder, level + 1);
                 } else {
-                    addListField(tmpValue, fieldType, fieldRecordBuilder, 
level + 1);
+                    addListField(tmpValue, openUnOrderedListType, 
fieldRecordBuilder, level + 1);
                 }
             }


--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17488
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ie413d286738f571df81e2f450a3fb0b132dc5521
Gerrit-Change-Number: 17488
Gerrit-PatchSet: 1
Gerrit-Owner: Peeyush Gupta <[email protected]>
Gerrit-MessageType: newchange

Reply via email to