>From Shahrzad Shirazi <[email protected]>:

Shahrzad Shirazi has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21179?usp=email )

Change subject: [ASTERIXDB-3767][COMP] Enable external access for 
object_transform arg
......................................................................

[ASTERIXDB-3767][COMP] Enable external access for object_transform arg

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

Detail:
Add transformAnnotation to all object_transform arguments to ensure
correct results for the function. This is currently supported only for
record constructors.

Ext-ref: MB-70606

Change-Id: Ia6ea4f69ff62b57144818baaabd3a4d1a620fc9b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21179
Tested-by: Jenkins <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
Integration-Tests: Ali Alsuliman <[email protected]>
Tested-by: Ali Alsuliman <[email protected]>
Reviewed-by: Shahrzad Shirazi <[email protected]>
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
M 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.1.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.2.update.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.3.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.4.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.3.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.4.adm
8 files changed, 216 insertions(+), 0 deletions(-)

Approvals:
  Shahrzad Shirazi: Looks good to me, but someone else must approve
  Ali Alsuliman: Looks good to me, approved; Verified; Verified
  Jenkins: Verified




diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index 9460138..ff14463 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -1103,6 +1103,12 @@
             throw new 
CompilationException(ErrorCode.COMPILATION_ILLEGAL_USE_OF_FILTER_CLAUSE, 
sourceLoc);
         }

+        if 
(BuiltinFunctions.RECORD_TRANSFORM.equals(f.getFunctionIdentifier())) {
+            for (int i = 0; i < args.size(); i++) {
+                annotateTransformRecord(args.get(i).getValue());
+            }
+        }
+
         // Put hints into function call expr.
         if (fcall.hasHints()) {
             f.putAnnotations(fcall.getHints());
@@ -1117,6 +1123,24 @@
         return new Pair<>(op, v);
     }

+    /** Annotates {@code expr} and every nested record-constructor reachable 
via field values. */
+    private static void annotateTransformRecord(ILogicalExpression expr) {
+        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+            return;
+        }
+        AbstractFunctionCallExpression call = (AbstractFunctionCallExpression) 
expr;
+        FunctionIdentifier fid = call.getFunctionIdentifier();
+        if (!BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR.equals(fid)
+                && !BuiltinFunctions.CLOSED_RECORD_CONSTRUCTOR.equals(fid)) {
+            return;
+        }
+        call.putAnnotation(isTransformRecordAnnotation.INSTANCE);
+        List<Mutable<ILogicalExpression>> a = call.getArguments();
+        for (int i = 1; i < a.size(); i += 2) {
+            annotateTransformRecord(a.get(i).getValue());
+        }
+    }
+
     protected ILogicalExpression translateVariableRef(VariableExpr varExpr) 
throws CompilationException {
         LogicalVariable var = context.getVar(varExpr.getVar().getId());
         if (var == null) {
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 3e94601..4eea44f 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
@@ -202,6 +202,11 @@
     </compilation-unit>
   </test-case>
   <test-case FilePath="objects">
+    <compilation-unit name="object_transform">
+      <output-dir compare="Text">object_transform</output-dir>
+    </compilation-unit>
+  </test-case>
+  <test-case FilePath="objects">
     <compilation-unit name="object_values">
       <output-dir compare="Text">object_values</output-dir>
     </compilation-unit>
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.1.ddl.sqlpp
new file mode 100644
index 0000000..787bc27
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.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 UserType2 AS {
+userId: int
+};
+
+
+
+CREATE DATASET UserTypes2(UserType2) PRIMARY KEY userId;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.2.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.2.update.sqlpp
new file mode 100644
index 0000000..1160d47
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.2.update.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 object_put under different queries.
+ * Expected Res : Success
+ */
+Use test;
+
+INSERT INTO UserTypes2([
+{
+"userId": 3,
+"email": "[email protected]",
+"username": "carol",
+"isActive": true,
+"roles": [
+{ "roleId": "role1", "roleName": "moderator" }
+],
+"c_purchase_history": {
+"c_recent_orders": [
+{ "orderId": "101"} ,
+{ "orderId": "102" } ,
+{ "orderId": "103"}
+]
+}
+}
+]);
+
+INSERT INTO UserTypes2([
+{
+"userId": 4,
+"email": "[email protected]",
+"username": "carol",
+"isActive": true,
+"roles": [
+{ "roleId": "role1", "roleName": "moderator" }
+],
+"items":
+{ "orderId": "101"}
+}
+]);
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.3.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.3.query.sqlpp
new file mode 100644
index 0000000..b5e5bdf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.3.query.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+
+SET `import-private-functions` "true";
+
+
+
+UPSERT INTO UserTypes2 (
+SELECT VALUE `object-transform`(
+{"items":{"a":3}},
+col1
+)
+FROM UserTypes2 col1
+);
+
+
+select * from UserTypes2;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.4.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.4.query.sqlpp
new file mode 100644
index 0000000..72e3152
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_transform/object_transform.4.query.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+
+SET `import-private-functions` "true";
+
+UPSERT INTO UserTypes2 AS c (
+SELECT
+  VALUE `object-transform`(
+    {
+      "c_purchase_history": {
+        "c_recent_orders": (
+          SELECT VALUE
+            CASE WHEN pos = 2
+              THEN `object-transform`(
+                {
+                  "cro_shipping_info": {
+                    "cro_si_address": {"cro_si_state": "CA"}
+                  }
+                },
+                cro
+              )
+              ELSE cro
+            END
+          FROM c.c_purchase_history.c_recent_orders AS cro AT pos
+        )
+      }
+    },
+    c
+  )
+FROM UserTypes2 AS c
+WHERE c.userId = 3
+);
+
+select * from UserTypes2
+where userId = 3
+order by userId;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.3.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.3.adm
new file mode 100644
index 0000000..d63a7b2
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.3.adm
@@ -0,0 +1,2 @@
+{ "UserTypes2": { "userId": 4, "items": { "a": 3, "orderId": "101" }, "email": 
"[email protected]", "username": "carol", "isActive": true, "roles": [ { 
"roleId": "role1", "roleName": "moderator" } ] } }
+{ "UserTypes2": { "userId": 3, "items": { "a": 3 }, "email": 
"[email protected]", "username": "carol", "isActive": true, "roles": [ { 
"roleId": "role1", "roleName": "moderator" } ], "c_purchase_history": { 
"c_recent_orders": [ { "orderId": "101" }, { "orderId": "102" }, { "orderId": 
"103" } ] } } }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.4.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.4.adm
new file mode 100644
index 0000000..363fad2
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_transform/object_transform.4.adm
@@ -0,0 +1 @@
+{ "UserTypes2": { "userId": 3, "c_purchase_history": { "c_recent_orders": [ { 
"orderId": "101" }, { "cro_shipping_info": { "cro_si_address": { 
"cro_si_state": "CA" } }, "orderId": "102" }, { "orderId": "103" } ] }, 
"items": { "a": 3 }, "email": "[email protected]", "username": "carol", 
"isActive": true, "roles": [ { "roleId": "role1", "roleName": "moderator" } ] } 
}

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

Gerrit-MessageType: merged
Gerrit-Project: asterixdb
Gerrit-Branch: lumina
Gerrit-Change-Id: Ia6ea4f69ff62b57144818baaabd3a4d1a620fc9b
Gerrit-Change-Number: 21179
Gerrit-PatchSet: 7
Gerrit-Owner: Shahrzad Shirazi <[email protected]>
Gerrit-Reviewer: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Shahrzad Shirazi <[email protected]>

Reply via email to