You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by xi...@apache.org on 2019/03/15 17:37:28 UTC

[asterixdb] branch master updated: [NO ISSUE][FUN] Fix type inference in JListAccessor

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

xikui 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 07048a3  [NO ISSUE][FUN] Fix type inference in JListAccessor
07048a3 is described below

commit 07048a3b97dab28bcf7555ec900de0712ce9d710
Author: Xikui Wang <xk...@gmail.com>
AuthorDate: Tue Mar 12 16:37:27 2019 -0700

    [NO ISSUE][FUN] Fix type inference in JListAccessor
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    As the list element type is available, there is no need to deserialize
    element types from the data. Doing so, for example, will cause the
    object type to be fully open type and closed fields to be recognized as
    open fields. This will further cause NPE in UDFs. Modified the upperCase
    test case to check this issue.
    
    Change-Id: I4f437857779e5c0af175c695938fbd7208da244d
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3264
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
---
 .../external-library/upperCase/upperCase.1.ddl.aql | 27 ---------------------
 .../external-library/upperCase/upperCase.2.lib.aql | 19 ---------------
 .../upperCase/upperCase.3.query.aql                | 28 ----------------------
 .../external-library/upperCase/upperCase.4.lib.aql | 19 ---------------
 .../upperCase/upperCase.1.ddl.sqlpp                |  6 ++++-
 .../upperCase/upperCase.3.query.sqlpp              |  6 ++---
 .../external-library/upperCase/upperCase.1.adm     |  6 ++---
 .../src/test/resources/runtimets/testsuite_it.xml  |  5 ----
 .../external/library/java/JObjectAccessors.java    | 13 ++++------
 .../external/library/UpperCaseFunction.java        | 23 ++++++++++++------
 10 files changed, 32 insertions(+), 120 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.1.ddl.aql
deleted file mode 100644
index 2dcd24d..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.1.ddl.aql
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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 externallibtest if exists;
-create dataverse externallibtest;
-use dataverse externallibtest;
-
-create type TextType if not exists as open {
-    id: int32,
-    text: string
-};
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.2.lib.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.2.lib.aql
deleted file mode 100644
index d1e0e87..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.2.lib.aql
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- */
-install externallibtest testlib target/data/externallib/asterix-external-data-testlib.zip
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.3.query.aql
deleted file mode 100644
index 5f0b86c..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.3.query.aql
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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 dataverse externallibtest;
-
-let $i:={"id":1, "text":"lower text"}
-return testlib#toUpper($i);
-
-let $i:=testlib#toUpper({"id":1, "text":"lower text"})
-return $i;
-
-let $i:= {"field1" : testlib#toUpper({"id":1, "text":"lower text"}), "field2": 123}
-return $i;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.4.lib.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.4.lib.aql
deleted file mode 100644
index 86af80f..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/external-library/upperCase/upperCase.4.lib.aql
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- */
-uninstall externallibtest testlib
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.1.ddl.sqlpp
index 8130de2..292e4e1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.1.ddl.sqlpp
@@ -20,7 +20,11 @@ DROP DATAVERSE externallibtest if exists;
 CREATE DATAVERSE  externallibtest;
 USE externallibtest;
 
+create type list_element as open{
+    text: string
+};
+
 create type TextType if not exists as open {
     id: int32,
-    text: string
+    text_list: [list_element]
 };
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.3.query.sqlpp
index f361232..743d39a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.3.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/external-library/upperCase/upperCase.3.query.sqlpp
@@ -18,11 +18,11 @@
  */
 use externallibtest;
 
-let i={"id":1, "text":"lower text"}
+let i={"id":1, "text_list": [{"text":"lower text1"}, {"text":"lower text2"}]}
 select value `testlib#toUpper`(i);
 
-let i=`testlib#toUpper`({"id":1, "text":"lower text"})
+let i=`testlib#toUpper`({"id":1, "text_list":[{"text":"lower text"}]})
 select value i;
 
-let i= {"field1" : `testlib#toUpper`({"id":1, "text":"lower text"}), "field2": 123}
+let i= {"field1" : `testlib#toUpper`({"id":1, "text_list":[{"text":"lower text"}]}), "field2": 123}
 select value i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/external-library/upperCase/upperCase.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/external-library/upperCase/upperCase.1.adm
index e4af2be..2efaa4f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/external-library/upperCase/upperCase.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/external-library/upperCase/upperCase.1.adm
@@ -1,3 +1,3 @@
-{ "id": -1, "text": "LOWER TEXT" }
-{ "id": -1, "text": "LOWER TEXT" }
-{ "field1": { "id": -1, "text": "LOWER TEXT" }, "field2": 123 }
+{ "id": -1, "text_list": [ { "text": "lower text1" }, { "text": "lower text2" } ], "element_n": 2, "capitalized_list": [ "LOWER TEXT1", "LOWER TEXT2" ] }
+{ "id": -1, "text_list": [ { "text": "lower text" } ], "element_n": 1, "capitalized_list": [ "LOWER TEXT" ] }
+{ "field1": { "id": -1, "text_list": [ { "text": "lower text" } ], "element_n": 1, "capitalized_list": [ "LOWER TEXT" ] }, "field2": 123 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_it.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_it.xml
index 2b7d4f0..e77b32b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_it.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_it.xml
@@ -43,11 +43,6 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="external-library">
-      <compilation-unit name="upperCase">
-        <output-dir compare="Text">upperCase</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="external-library">
       <compilation-unit name="keyword_detector">
         <output-dir compare="Text">keyword_detector</output-dir>
       </compilation-unit>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
index 2678a8d..1a6553c 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
@@ -82,8 +82,10 @@ import org.apache.asterix.om.pointables.AFlatValuePointable;
 import org.apache.asterix.om.pointables.AListVisitablePointable;
 import org.apache.asterix.om.pointables.ARecordVisitablePointable;
 import org.apache.asterix.om.pointables.base.IVisitablePointable;
+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.AbstractCollectionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.IAType;
@@ -582,17 +584,12 @@ public class JObjectAccessors {
         public IJObject access(AListVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool,
                 IAType listType, JObjectPointableVisitor pointableVisitor) throws HyracksDataException {
             List<IVisitablePointable> items = pointable.getItems();
-            List<IVisitablePointable> itemTags = pointable.getItemTags();
             JList list = pointable.ordered() ? new JOrderedList(listType) : new JUnorderedList(listType);
             IJObject listItem;
-            int index = 0;
             for (IVisitablePointable itemPointable : items) {
-                IVisitablePointable itemTagPointable = itemTags.get(index);
-                ATypeTag itemTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                        .deserialize(itemTagPointable.getByteArray()[itemTagPointable.getStartOffset()]);
-                final IAType fieldType = TypeTagUtil.getBuiltinTypeByTag(itemTypeTag);
-                typeInfo.reset(fieldType, itemTypeTag);
-                switch (itemTypeTag) {
+                final IAType fieldType = ((AbstractCollectionType) listType).getItemType();
+                typeInfo.reset(fieldType, fieldType.getTypeTag());
+                switch (typeInfo.getTypeTag()) {
                     case OBJECT:
                         listItem = pointableVisitor.visit((ARecordVisitablePointable) itemPointable, typeInfo);
                         break;
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
index 82f77ac..398504a 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
@@ -21,8 +21,10 @@ package org.apache.asterix.external.library;
 import org.apache.asterix.external.api.IExternalScalarFunction;
 import org.apache.asterix.external.api.IFunctionHelper;
 import org.apache.asterix.external.library.java.base.JInt;
+import org.apache.asterix.external.library.java.base.JOrderedList;
 import org.apache.asterix.external.library.java.base.JRecord;
 import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.om.types.BuiltinType;
 
 /**
  * Accepts an input record of type Open{ id: int32, text: string }
@@ -43,16 +45,23 @@ public class UpperCaseFunction implements IExternalScalarFunction {
     @Override
     public void evaluate(IFunctionHelper functionHelper) throws Exception {
         JRecord inputRecord = (JRecord) functionHelper.getArgument(0);
+        JOrderedList textList = (JOrderedList) inputRecord.getValueByName("text_list");
+        JOrderedList capList = new JOrderedList(BuiltinType.ASTRING);
         JInt id = (JInt) inputRecord.getValueByName("id");
-        id.setValue(id.getValue() * -1); // for maintaining uniqueness
-                                         // constraint in the case when
-                                         // output is re-inserted into source
-                                         // dataset
-        JString text = (JString) inputRecord.getValueByName("text");
-        text.setValue(text.getValue().toUpperCase());
+        id.setValue(id.getValue() * -1);
+
+        for (int iter1 = 0; iter1 < textList.getValue().size(); iter1++) {
+            JRecord originalElement = (JRecord) textList.getValue().get(iter1);
+            JString originalText = (JString) originalElement.getValueByName("text");
+            JString capText = new JString(originalText.getValue().toUpperCase());
+            capList.getValue().add(capText);
+        }
+        JInt element_n = new JInt(textList.size());
         JRecord result = (JRecord) functionHelper.getResultObject();
         result.setField("id", id);
-        result.setField("text", text);
+        result.setField("text_list", textList);
+        result.setField("element_n", element_n);
+        result.setField("capitalized_list", capList);
         functionHelper.setResult(result);
     }
 }