>From Ali Alsuliman <[email protected]>:

Ali Alsuliman has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21146?usp=email )

Change subject: [ASTERIXDB-3758][COMP] Fix nested UPDATE on arrays to handle 
non-record element replacement
......................................................................

[ASTERIXDB-3758][COMP] Fix nested UPDATE on arrays to handle non-record element 
replacement

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


Ext-ref: MB-70853



Change-Id: I72c9aa078a93c4a4eecc35ac65d0d65137f48fdb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21146
Reviewed-by: Ali Alsuliman <[email protected]>
Tested-by: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
---
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.24.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.25.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.26.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.27.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.28.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.29.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.25.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.26.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.27.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.28.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.29.adm
M 
asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppChangeExprToSelectExprVisitor.java
12 files changed, 215 insertions(+), 3 deletions(-)

Approvals:
  Jenkins: Verified; Verified
  Ali Alsuliman: Looks good to me, approved

Objections:
  Anon. E. Moose #1000171: Violations found




diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.24.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.24.ddl.sqlpp
new file mode 100644
index 0000000..4825054
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.24.ddl.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+CREATE TYPE UserType2 AS {
+  userId: int,
+  email: string,
+  username: string,
+  isActive: boolean
+};
+
+CREATE DATASET UserTypes2(UserType2)
+PRIMARY KEY userId;
+
+INSERT INTO UserTypes2([
+  {
+    "userId": 3,
+    "email": "[email protected]",
+    "username": "carol",
+    "isActive": true,
+    "roles": [
+      { "roleId": "role1", "roleName": "moderator" },
+      { "roleId": "role2", "roleName": "reviewer" },
+      { "roleId": "role3", "roleName": "reviewer" },
+      { "roleId": "role4", "roleName": "reviewer" }
+    ]
+  }
+]);
+
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.25.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.25.query.sqlpp
new file mode 100644
index 0000000..26189af
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.25.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+UPDATE UserTypes2 AS u
+(update u.roles as p at o
+set p="pp"
+where o=2 )
+WHERE u.userId= 3
+returning u;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.26.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.26.query.sqlpp
new file mode 100644
index 0000000..2f65d9d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.26.query.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.
+ */
+
+
+Use test;
+
+UPDATE UserTypes2 AS u
+(update u.roles as p at o
+set p=5)
+WHERE u.userId= 3
+returning u;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.27.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.27.query.sqlpp
new file mode 100644
index 0000000..7b950a5
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.27.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+UPDATE UserTypes2 AS u
+(update u.roles as p at o
+set p=null
+where o=2)
+WHERE u.userId= 3
+returning u;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.28.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.28.query.sqlpp
new file mode 100644
index 0000000..61378c9
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.28.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+UPDATE UserTypes2 AS u
+(update u.roles as p at o
+set p.a=3
+where o=3)
+WHERE u.userId= 3
+returning u;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.29.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.29.query.sqlpp
new file mode 100644
index 0000000..ea218dd
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/update-statements/simple-case/simple-case.29.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+UPDATE UserTypes2 AS u
+(update u.roles as p at o
+set p=44
+where o=3 or o=4)
+WHERE u.userId= 3
+returning u;
+
+
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.25.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.25.adm
new file mode 100644
index 0000000..3b23377
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.25.adm
@@ -0,0 +1 @@
+{ "userId": 3, "email": "[email protected]", "username": "carol", "isActive": 
true, "roles": [ { "roleId": "role1", "roleName": "moderator" }, "pp", { 
"roleId": "role3", "roleName": "reviewer" }, { "roleId": "role4", "roleName": 
"reviewer" } ] }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.26.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.26.adm
new file mode 100644
index 0000000..52bf88c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.26.adm
@@ -0,0 +1 @@
+{ "userId": 3, "email": "[email protected]", "username": "carol", "isActive": 
true, "roles": [ 5, 5, 5, 5 ] }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.27.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.27.adm
new file mode 100644
index 0000000..38ceb3e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.27.adm
@@ -0,0 +1 @@
+{ "userId": 3, "email": "[email protected]", "username": "carol", "isActive": 
true, "roles": [ 5, null, 5, 5 ] }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.28.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.28.adm
new file mode 100644
index 0000000..de66769
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.28.adm
@@ -0,0 +1 @@
+{ "userId": 3, "email": "[email protected]", "username": "carol", "isActive": 
true, "roles": [ 5, null, { "a": 3 }, 5 ] }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.29.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.29.adm
new file mode 100644
index 0000000..f56b3cf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/update-statements/simple-case/simple-case.29.adm
@@ -0,0 +1 @@
+{ "userId": 3, "email": "[email protected]", "username": "carol", "isActive": 
true, "roles": [ 5, null, 44, 44 ] }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppChangeExprToSelectExprVisitor.java
 
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppChangeExprToSelectExprVisitor.java
index 7d068e9..0d1527c 100644
--- 
a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppChangeExprToSelectExprVisitor.java
+++ 
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppChangeExprToSelectExprVisitor.java
@@ -198,9 +198,13 @@
             dataTransformRecord = 
substituteVariableInExpression(dataTransformRecord, originalVarName,
                     currentContextVariable, changeExpr);
             changeExpr.setPriorExpr(projectExpr);
-            projectExpr = new CallExpr(new 
FunctionSignature(BuiltinFunctions.RECORD_TRANSFORM),
-                    new ArrayList<>(Arrays.asList(dataTransformRecord, 
projectExpr)));
-            ((CallExpr) 
projectExpr).setSourceLocation(rewrittenFirstExpr.getSourceLocation());
+            if (dataTransformRecord.getKind() == 
Expression.Kind.RECORD_CONSTRUCTOR_EXPRESSION) {
+                projectExpr = new CallExpr(new 
FunctionSignature(BuiltinFunctions.RECORD_TRANSFORM),
+                        new ArrayList<>(Arrays.asList(dataTransformRecord, 
projectExpr)));
+                ((CallExpr) 
projectExpr).setSourceLocation(rewrittenFirstExpr.getSourceLocation());
+            } else {
+                projectExpr = dataTransformRecord;
+            }
         }

         SelectElement selectElement = new SelectElement(projectExpr);

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21146?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: I72c9aa078a93c4a4eecc35ac65d0d65137f48fdb
Gerrit-Change-Number: 21146
Gerrit-PatchSet: 13
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