Steven Jacobs has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/2703
Change subject: [COMP][ASTERIXDB-2400] Fix UNION handling in InlineAllNtsInSubplanVisitor ...................................................................... [COMP][ASTERIXDB-2400] Fix UNION handling in InlineAllNtsInSubplanVisitor Makes the visitor correctly allow substitution of the input ops for the output op in future operators Added test Change-Id: I8b7e3e24749ed88e27d6cd38be5584ea748f39fc --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml 8 files changed, 184 insertions(+), 2 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/03/2703/1 diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java index a98a9f4..4d646f3 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java @@ -562,8 +562,8 @@ // Update the variable mappings List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varTriples = op.getVariableMappings(); for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varTriples) { - updateInputToOutputVarMapping(triple.third, triple.first, false); - updateInputToOutputVarMapping(triple.second, triple.first, false); + updateInputToOutputVarMapping(triple.first, triple.third, false); + updateInputToOutputVarMapping(triple.second, triple.third, false); } return op; } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp new file mode 100644 index 0000000..d3162f4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.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 : Test for issue ASTERIXDB-2400 + * Expected Res : Success + * Date : Jun 2018 + */ + +drop dataverse test if exists; +create dataverse test; +use test; + +create type sub as { + subscriptionId: uuid +}; + +create dataset subscriptions(sub) primary key subscriptionId; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp new file mode 100644 index 0000000..c4ba876 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp @@ -0,0 +1,72 @@ +/* + * 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 : Test for issue ASTERIXDB-2400 + * Expected Res : Success + * Date : Jun 2018 + */ +use test; + +upsert into subscriptions as record( +(let v = (select value s from subscriptions s where param0 = "HenryGale") +select value (CASE (array_count(v) > 0) +WHEN true THEN +{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0, +"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL + select value val from [{"brokerSubscriptionId":create_uuid(), + "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)} +ELSE +{"subscriptionId":create_uuid(), "param0": "HenryGale", +"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse": + "dataverse1","brokerName":"broker1","created":current_datetime()}]} +END +)) +); + +upsert into subscriptions as record( +(let v = (select value s from subscriptions s where param0 = "HenryGale") +select value (CASE (array_count(v) > 0) +WHEN true THEN +{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0, +"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL + select value val from [{"brokerSubscriptionId":create_uuid(), + "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)} +ELSE +{"subscriptionId":create_uuid(), "param0": "HenryGale", +"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse": + "dataverse1","brokerName":"broker1","created":current_datetime()}]} +END +)) +); + +upsert into subscriptions as record( +(let v = (select value s from subscriptions s where param0 = "HenryGale") +select value (CASE (array_count(v) > 0) +WHEN true THEN +{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0, +"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL + select value val from [{"brokerSubscriptionId":create_uuid(), + "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)} +ELSE +{"subscriptionId":create_uuid(), "param0": "HenryGale", +"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse": + "dataverse1","brokerName":"broker1","created":current_datetime()}]} +END +)) +); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp new file mode 100644 index 0000000..0677150 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp @@ -0,0 +1,44 @@ +/* + * 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 : Test for issue ASTERIXDB-2400 + * Expected Res : Success + * Date : Jun 2018 + */ +use test; + +upsert into subscriptions as record( +(let v = (select value s from subscriptions s where param0 = "HenryGale") +select value (CASE (array_count(v) > 0) + +WHEN true THEN +{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0, +"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL + select value val from [{"brokerSubscriptionId":create_uuid(), + "brokerDataverse":"dataverse1","brokerName":"broker3","created":current_datetime()}] val)} +ELSE +{"subscriptionId":create_uuid(), "param0": "HenryGale", +"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse":"dataverse1", + "brokerName":"broker3","created":current_datetime()}]} +END +)) +) returning +(let subs = record.brokerSubscriptions +select value brokerName from subs +order by created DESC limit 1)[0]; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp new file mode 100644 index 0000000..51889d2 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp @@ -0,0 +1,26 @@ +/* + * 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 : Test for issue ASTERIXDB-2400 + * Expected Res : Success + * Date : Jun 2018 + */ +use test; + +select value array_count(brokerSubscriptions) from subscriptions; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm new file mode 100644 index 0000000..4dbe13c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm @@ -0,0 +1 @@ +"broker3" \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm @@ -0,0 +1 @@ +4 \ No newline at end of file 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 2ce8668..4376ca6 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -9748,6 +9748,11 @@ <output-dir compare="Text">multiple-secondaries</output-dir> </compilation-unit> </test-case> + <test-case FilePath="upsert"> + <compilation-unit name="upsert-case-returning"> + <output-dir compare="Text">upsert-case-returning</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="json-parser"> <test-case FilePath="json-parser"> -- To view, visit https://asterix-gerrit.ics.uci.edu/2703 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8b7e3e24749ed88e27d6cd38be5584ea748f39fc Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Steven Jacobs <sjaco...@ucr.edu>