ASTERIXDB-1205: fix union queries.
Fixed the AqlExpressionToPlanTranslator for union expression;
Eliminate shared operator references in translated logical plans;
Removed IntroduceUnionRule;
Fixed tuple source for SQL++ join clause;
Added regression tests.
Change-Id: Ib79a899ec4b35ece6f8f9f59b80126fed0c48851
Reviewed-on: https://asterix-gerrit.ics.uci.edu/629
Reviewed-by: Till Westmann <tillw@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.ddl.aql
new file mode 100644
index 0000000..5586ad23c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.ddl.aql
@@ -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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type DBLPType as open {
+ id: int64,
+ dblpid: string,
+ title: string,
+ authors: string,
+ misc: string
+}
+
+create dataset DBLP(DBLPType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.2.update.aql
new file mode 100644
index 0000000..bbee2a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.2.update.aql
@@ -0,0 +1,24 @@
+/*
+ * 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 test;
+
+load dataset DBLP
+using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="asterix_nc1://data/pub-small/dblp-small-id.txt"),("format"="delimited-text"),("delimiter"=":")) pre-sorted;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.3.query.aql
new file mode 100644
index 0000000..f30a7c4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.3.query.aql
@@ -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.
+ */
+/**
+ * This query is to verify the fix of ASTERIXDB-1047.
+ */
+
+use dataverse test;
+
+for $i in (
+ (for $d in dataset DBLP where $d.id = 1 return $d)
+ union
+ (for $d in dataset DBLP where $d.authors = "Alfred V. Aho John E. Hopcroft Jeffrey D. Ullman" return $d)
+)
+order by $i.id
+return $i;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.1.ddl.aql
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.1.ddl.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.2.update.aql
new file mode 100644
index 0000000..042f3ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.2.update.aql
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.3.query.aql
new file mode 100644
index 0000000..82d1430
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205.3.query.aql
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+/**
+ * This query is to verify the fix of ASTERIXDB-1205.
+ */
+
+let $aa := [{"fa":1, "fb":1}, {"fa":2, "fb":1}]
+let $bb := [{"fa":1, "fb":0}, {"fa":1, "fb":1}, {"fa":3, "fb":1}]
+
+for $tt in ($aa union $bb)
+order by $tt.fa, $tt.fb
+return $tt;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aql
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.2.update.aql
new file mode 100644
index 0000000..042f3ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.2.update.aql
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.3.query.aql
new file mode 100644
index 0000000..bee2076
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.3.query.aql
@@ -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.
+ */
+/**
+ * This query is to verify the fix of ASTERIXDB-1205.
+ */
+
+let $aa := [{"fa":1, "fb":1}, {"fa":2, "fb":1}]
+let $bb := [{"fa":1, "fb":0}, {"fa":1, "fb":1}, {"fa":3, "fb":1}]
+let $dd := [{"fa":4, "fb":5}, {"fa":6, "fb":7}]
+let $ccc := $aa union $bb union $dd
+
+for $tt in $ccc
+order by $tt.fa, $tt.fb
+return $tt;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.ddl.aql
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.ddl.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.2.update.aql
new file mode 100644
index 0000000..042f3ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.2.update.aql
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.3.query.aql
new file mode 100644
index 0000000..763aba1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.3.query.aql
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+/**
+ * This query is to verify the fix of ASTERIXDB-1205.
+ */
+
+let $aa := [{"fa":1, "fb":1}, {"fa":2, "fb":1}]
+let $bb := [{"fa":1, "fb":0}, {"fa":1, "fb":1}, {"fa":3, "fb":1}]
+let $ccc := $aa union $bb
+
+for $tt in $ccc
+order by $tt.fa, $tt.fb
+return $tt;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.ddl.aql
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.ddl.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.2.update.aql
new file mode 100644
index 0000000..042f3ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.2.update.aql
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.3.query.aql
new file mode 100644
index 0000000..95d9968
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/query-ASTERIXDB-300/query-ASTERIXDB-300.3.query.aql
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+/**
+ * This query is to verify the fix of ASTERIXDB-300.
+ */
+
+let $a := [
+{"id":1234,"name":"John Doe","age":56,"salary":50000,"dept":"HR"}
+]
+let $b := [
+{"id":3424,"name":"Roger Sanders","age":46,"salary":60000,"dept":"Publishing"}
+]
+
+let $c := $a union $b
+return
+ for $i in $c
+ order by $i.id
+ return $i
+;
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/union/union.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/union/union.3.query.aql
index 4b8b4ab..d112458 100644
--- a/asterix-app/src/test/resources/runtimets/queries/union/union/union.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/union/union/union.3.query.aql
@@ -21,4 +21,4 @@
let $t1 := for $t in dataset FacebookUsers return $t.id
let $t2 := for $s in dataset FacebookMessages return $s.message-id
let $c := $t1 union $t2
-for $res in $c distinct by $res return $res
+for $res in $c distinct by $res order by $res return $res
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/union2/union.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.1.ddl.aql
new file mode 100644
index 0000000..1936ef8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.1.ddl.aql
@@ -0,0 +1,29 @@
+/*
+ * 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 TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type FacebookUserType as open {
+ id: int
+}
+
+create dataset FacebookUsers(FacebookUserType)
+primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/union2/union.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.2.update.aql
new file mode 100644
index 0000000..a6b70a3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.2.update.aql
@@ -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 dataverse TinySocial;
+
+load dataset FacebookUsers using localfs
+(("path"="asterix_nc1://data/tinysocial/fbu.adm"),("format"="adm"));
diff --git a/asterix-app/src/test/resources/runtimets/queries/union/union2/union.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.3.query.aql
new file mode 100644
index 0000000..4b52c77
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/union/union2/union.3.query.aql
@@ -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 dataverse TinySocial;
+
+let $c := dataset("FacebookUsers") union dataset("FacebookUsers")
+for $res in $c order by $res.id return $res
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_04/join_q_04.1.ddl.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_04/join_q_04.1.ddl.sqlpp
index a0795af..7dffaf6 100644
--- a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_04/join_q_04.1.ddl.sqlpp
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_04/join_q_04.1.ddl.sqlpp
@@ -18,6 +18,7 @@
*/
/*
* Description : This test case is to verify the fix for issue51
+ */
drop database test if exists;
create database test;
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.1.ddl.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.1.ddl.sqlpp
new file mode 100644
index 0000000..0a583a4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.1.ddl.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+{
+ number : int64,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int64,
+ name : string,
+ cashBack : int64,
+ age : int64?,
+ address : AddressType?,
+ lastorder : {
+ oid : int64,
+ total : float
+ }
+
+}
+
+create type test.OrderType as
+{
+ oid : int64,
+ cid : int64,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float,
+ items : [int64]
+}
+
+create external table Customers(CustomerType) using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"(("path"="asterix_nc1://data/nontagged/customerData.json"),("format"="adm"));
+
+create external table Orders(OrderType) using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"(("path"="asterix_nc1://data/nontagged/orderData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.2.update.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.2.update.sqlpp
new file mode 100644
index 0000000..6c98c1e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.2.update.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.3.query.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.3.query.sqlpp
new file mode 100644
index 0000000..c7533ae
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_05/join_q_05.3.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;
+
+
+WITH customer AS (SELECT ELEMENT c FROM Customers c),
+ "orders" AS (SELECT ELEMENT o FROM Orders o)
+SELECT c.name AS cust_name,
+ c.age AS cust_age,
+ o.total AS order_total,
+ [o.oid,o.cid] AS orderList
+FROM customer c JOIN orders o ON c.cid = o.cid
+ORDER BY c.name,o.total
+;
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.1.ddl.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.1.ddl.sqlpp
new file mode 100644
index 0000000..821b565
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.1.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+{
+ number : int64,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int64,
+ name : string,
+ cashBack : int64,
+ age : int64?,
+ address : AddressType?,
+ lastorder : {
+ oid : int64,
+ total : float
+ }
+
+}
+
+create external table Customers(CustomerType) using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"(("path"="asterix_nc1://data/nontagged/customerData.json"),("format"="adm"));
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.2.update.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.2.update.sqlpp
new file mode 100644
index 0000000..6c98c1e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.2.update.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.3.query.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.3.query.sqlpp
new file mode 100644
index 0000000..c9e9876
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_06/join_q_06.3.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;
+
+
+WITH customer AS (SELECT ELEMENT c FROM Customers c)
+
+SELECT c.name AS cust_name,
+ c.cashBack AS cust_cashBack
+FROM customer c JOIN [min((SELECT ELEMENT c.cashBack FROM customer c))] as min_cashBack
+ ON c.cashBack = min_cashBack
+ORDER BY c.cid, c.name
+;
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.1.ddl.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.1.ddl.sqlpp
new file mode 100644
index 0000000..821b565
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.1.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+{
+ number : int64,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int64,
+ name : string,
+ cashBack : int64,
+ age : int64?,
+ address : AddressType?,
+ lastorder : {
+ oid : int64,
+ total : float
+ }
+
+}
+
+create external table Customers(CustomerType) using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"(("path"="asterix_nc1://data/nontagged/customerData.json"),("format"="adm"));
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.2.update.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.2.update.sqlpp
new file mode 100644
index 0000000..6c98c1e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.2.update.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.3.query.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.3.query.sqlpp
new file mode 100644
index 0000000..05c71c2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/join_q_07/join_q_07.3.query.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/*
+ * This query is expected to fail because variable c
+ * is undefined for subquery "(SELECT ELEMENT c.cashBack FROM c c)".
+ */
+
+USE test;
+
+
+WITH customer AS (SELECT ELEMENT c FROM Customers c)
+
+SELECT c.name AS cust_name,
+ c.cashBack AS cust_cashBack
+FROM customer c JOIN [min((SELECT ELEMENT c.cashBack FROM c c))] as min_cashBack
+ ON c.cashBack = min_cashBack
+ORDER BY c.cid, c.name
+;
diff --git a/asterix-app/src/test/resources/runtimets/results/custord/join_q_06/join_q_06.1.adm b/asterix-app/src/test/resources/runtimets/results/custord/join_q_06/join_q_06.1.adm
new file mode 100644
index 0000000..bcbe1fb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/custord/join_q_06/join_q_06.1.adm
@@ -0,0 +1 @@
+{ "cust_name": "Jodi Rotruck", "cust_cashBack": 100 }
diff --git a/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.adm b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.adm
new file mode 100644
index 0000000..2a14594
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1047/query-ASTERIXDB-1047.1.adm
@@ -0,0 +1,3 @@
+{ "id": 1, "dblpid": "books/acm/kim95/AnnevelinkACFHK95", "title": "Object SQL - A Language for the Design and Implementation of Object Databases.", "authors": "Jurgen Annevelink Rafiul Ahad Amelia Carlson Daniel H. Fishman Michael L. Heytens William Kent", "misc": "2002-01-03 42-68 1995 Modern Database Systems db/books/collections/kim95.html#AnnevelinkACFHK95" }
+{ "id": 73, "dblpid": "books/aw/AhoHU74", "title": "The Design and Analysis of Computer Algorithms.", "authors": "Alfred V. Aho John E. Hopcroft Jeffrey D. Ullman", "misc": "2002-01-03 Addison-Wesley 1974 0-201-00029-6" }
+{ "id": 75, "dblpid": "books/aw/AhoHU83", "title": "Data Structures and Algorithms.", "authors": "Alfred V. Aho John E. Hopcroft Jeffrey D. Ullman", "misc": "2002-01-03 Addison-Wesley 1983 0-201-00023-7" }
diff --git a/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205-2.1.adm b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205-2.1.adm
new file mode 100644
index 0000000..2ddaa6e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-2/query-ASTERIXDB-1205-2.1.adm
@@ -0,0 +1,5 @@
+{ "fa": 1, "fb": 0 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 2, "fb": 1 }
+{ "fa": 3, "fb": 1 }
diff --git a/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205-3.1.adm b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205-3.1.adm
new file mode 100644
index 0000000..12a9fe6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205-3.1.adm
@@ -0,0 +1,7 @@
+{ "fa": 1, "fb": 0 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 2, "fb": 1 }
+{ "fa": 3, "fb": 1 }
+{ "fa": 4, "fb": 5 }
+{ "fa": 6, "fb": 7 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.adm b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.adm
new file mode 100644
index 0000000..2ddaa6e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-1205/query-ASTERIXDB-1205.1.adm
@@ -0,0 +1,5 @@
+{ "fa": 1, "fb": 0 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 1, "fb": 1 }
+{ "fa": 2, "fb": 1 }
+{ "fa": 3, "fb": 1 }
diff --git a/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.adm b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.adm
new file mode 100644
index 0000000..d580e02
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/query-ASTERIXDB-300/query-ASTERIXDB-300.1.adm
@@ -0,0 +1 @@
+[ { "id": 1234, "name": "John Doe", "age": 56, "salary": 50000, "dept": "HR" }, { "id": 3424, "name": "Roger Sanders", "age": 46, "salary": 60000, "dept": "Publishing" } ]
diff --git a/asterix-app/src/test/resources/runtimets/results/union/union/union.1.adm b/asterix-app/src/test/resources/runtimets/results/union/union/union.1.adm
index 69a9eb0..97b3d1a 100644
--- a/asterix-app/src/test/resources/runtimets/results/union/union/union.1.adm
+++ b/asterix-app/src/test/resources/runtimets/results/union/union/union.1.adm
@@ -1,15 +1,15 @@
-6
-11
-12
-14
1
2
+3
4
-13
-15
+5
+6
+7
8
9
10
-3
-5
-7
+11
+12
+13
+14
+15
diff --git a/asterix-app/src/test/resources/runtimets/results/union/union2/union2.1.adm b/asterix-app/src/test/resources/runtimets/results/union/union2/union2.1.adm
new file mode 100644
index 0000000..70b4777
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/union/union2/union2.1.adm
@@ -0,0 +1,20 @@
+{ "id": 1, "alias": "Margarita", "name": "MargaritaStoddard", "user-since": datetime("2012-08-20T10:10:00.000Z"), "friend-ids": {{ 2, 3, 6, 10 }}, "employment": [ { "organization-name": "Codetechno", "start-date": date("2006-08-06") } ] }
+{ "id": 1, "alias": "Margarita", "name": "MargaritaStoddard", "user-since": datetime("2012-08-20T10:10:00.000Z"), "friend-ids": {{ 2, 3, 6, 10 }}, "employment": [ { "organization-name": "Codetechno", "start-date": date("2006-08-06") } ] }
+{ "id": 2, "alias": "Isbel", "name": "IsbelDull", "user-since": datetime("2011-01-22T10:10:00.000Z"), "friend-ids": {{ 1, 4 }}, "employment": [ { "organization-name": "Hexviafind", "start-date": date("2010-04-27") } ] }
+{ "id": 2, "alias": "Isbel", "name": "IsbelDull", "user-since": datetime("2011-01-22T10:10:00.000Z"), "friend-ids": {{ 1, 4 }}, "employment": [ { "organization-name": "Hexviafind", "start-date": date("2010-04-27") } ] }
+{ "id": 3, "alias": "Emory", "name": "EmoryUnk", "user-since": datetime("2012-07-10T10:10:00.000Z"), "friend-ids": {{ 1, 5, 8, 9 }}, "employment": [ { "organization-name": "geomedia", "start-date": date("2010-06-17"), "end-date": date("2010-01-26") } ] }
+{ "id": 3, "alias": "Emory", "name": "EmoryUnk", "user-since": datetime("2012-07-10T10:10:00.000Z"), "friend-ids": {{ 1, 5, 8, 9 }}, "employment": [ { "organization-name": "geomedia", "start-date": date("2010-06-17"), "end-date": date("2010-01-26") } ] }
+{ "id": 4, "alias": "Nicholas", "name": "NicholasStroh", "user-since": datetime("2010-12-27T10:10:00.000Z"), "friend-ids": {{ 2 }}, "employment": [ { "organization-name": "Zamcorporation", "start-date": date("2010-06-08") } ] }
+{ "id": 4, "alias": "Nicholas", "name": "NicholasStroh", "user-since": datetime("2010-12-27T10:10:00.000Z"), "friend-ids": {{ 2 }}, "employment": [ { "organization-name": "Zamcorporation", "start-date": date("2010-06-08") } ] }
+{ "id": 5, "alias": "Von", "name": "VonKemble", "user-since": datetime("2010-01-05T10:10:00.000Z"), "friend-ids": {{ 3, 6, 10 }}, "employment": [ { "organization-name": "Kongreen", "start-date": date("2010-11-27") } ] }
+{ "id": 5, "alias": "Von", "name": "VonKemble", "user-since": datetime("2010-01-05T10:10:00.000Z"), "friend-ids": {{ 3, 6, 10 }}, "employment": [ { "organization-name": "Kongreen", "start-date": date("2010-11-27") } ] }
+{ "id": 6, "alias": "Willis", "name": "WillisWynne", "user-since": datetime("2005-01-17T10:10:00.000Z"), "friend-ids": {{ 1, 3, 7 }}, "employment": [ { "organization-name": "jaydax", "start-date": date("2009-05-15") } ] }
+{ "id": 6, "alias": "Willis", "name": "WillisWynne", "user-since": datetime("2005-01-17T10:10:00.000Z"), "friend-ids": {{ 1, 3, 7 }}, "employment": [ { "organization-name": "jaydax", "start-date": date("2009-05-15") } ] }
+{ "id": 7, "alias": "Suzanna", "name": "SuzannaTillson", "user-since": datetime("2012-08-07T10:10:00.000Z"), "friend-ids": {{ 6 }}, "employment": [ { "organization-name": "Labzatron", "start-date": date("2011-04-19") } ] }
+{ "id": 7, "alias": "Suzanna", "name": "SuzannaTillson", "user-since": datetime("2012-08-07T10:10:00.000Z"), "friend-ids": {{ 6 }}, "employment": [ { "organization-name": "Labzatron", "start-date": date("2011-04-19") } ] }
+{ "id": 8, "alias": "Nila", "name": "NilaMilliron", "user-since": datetime("2008-01-01T10:10:00.000Z"), "friend-ids": {{ 3 }}, "employment": [ { "organization-name": "Plexlane", "start-date": date("2010-02-28") } ] }
+{ "id": 8, "alias": "Nila", "name": "NilaMilliron", "user-since": datetime("2008-01-01T10:10:00.000Z"), "friend-ids": {{ 3 }}, "employment": [ { "organization-name": "Plexlane", "start-date": date("2010-02-28") } ] }
+{ "id": 9, "alias": "Woodrow", "name": "WoodrowNehling", "user-since": datetime("2005-09-20T10:10:00.000Z"), "friend-ids": {{ 3, 10 }}, "employment": [ { "organization-name": "Zuncan", "start-date": date("2003-04-22"), "end-date": date("2009-12-13") } ] }
+{ "id": 9, "alias": "Woodrow", "name": "WoodrowNehling", "user-since": datetime("2005-09-20T10:10:00.000Z"), "friend-ids": {{ 3, 10 }}, "employment": [ { "organization-name": "Zuncan", "start-date": date("2003-04-22"), "end-date": date("2009-12-13") } ] }
+{ "id": 10, "alias": "Bram", "name": "BramHatch", "user-since": datetime("2010-10-16T10:10:00.000Z"), "friend-ids": {{ 1, 5, 9 }}, "employment": [ { "organization-name": "physcane", "start-date": date("2007-06-05"), "end-date": date("2011-11-05") } ] }
+{ "id": 10, "alias": "Bram", "name": "BramHatch", "user-since": datetime("2010-10-16T10:10:00.000Z"), "friend-ids": {{ 1, 5, 9 }}, "employment": [ { "organization-name": "physcane", "start-date": date("2007-06-05"), "end-date": date("2011-11-05") } ] }
diff --git a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/custord/join_q_04/join_q_04.1.ast b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/custord/join_q_04/join_q_04.1.ast
index e69de29..7509a02 100644
--- a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/custord/join_q_04/join_q_04.1.ast
+++ b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/custord/join_q_04/join_q_04.1.ast
@@ -0,0 +1,36 @@
+DataverseUse test
+TypeDecl AddressType [
+ open RecordType {
+ number : int64,
+ street : string,
+ city : string
+ }
+]
+TypeDecl CustomerType [
+ closed RecordType {
+ cid : int64,
+ name : string,
+ cashBack : int64,
+ age : int64?,
+ address : AddressType?,
+ lastorder : open RecordType {
+ oid : int64,
+ total : float
+ }
+
+ }
+]
+TypeDecl OrderType [
+ open RecordType {
+ oid : int64,
+ cid : int64,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float,
+ items : OrderedList [int64]
+
+ }
+]
+DatasetDecl Customers(CustomerType)is an external dataset
+DatasetDecl Orders(OrderType)is an external dataset
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index a506bd3..a3a1fba 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -177,6 +177,36 @@
<output-dir compare="Text">union</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="union2">
+ <output-dir compare="Text">union2</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="query-ASTERIXDB-300">
+ <output-dir compare="Text">query-ASTERIXDB-300</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="query-ASTERIXDB-1205">
+ <output-dir compare="Text">query-ASTERIXDB-1205</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="query-ASTERIXDB-1205-2">
+ <output-dir compare="Text">query-ASTERIXDB-1205-2</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="query-ASTERIXDB-1205-3">
+ <output-dir compare="Text">query-ASTERIXDB-1205-3</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="union">
+ <compilation-unit name="query-ASTERIXDB-1047">
+ <output-dir compare="Text">query-ASTERIXDB-1047</output-dir>
+ </compilation-unit>
+ </test-case>
</test-group>
<test-case FilePath="flwor">
<compilation-unit name="let33">
diff --git a/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 2965883..d289400 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1298,6 +1298,22 @@
</compilation-unit>
</test-case>
<test-case FilePath="custord">
+ <compilation-unit name="join_q_05">
+ <output-dir compare="Text">join_q_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="custord">
+ <compilation-unit name="join_q_06">
+ <output-dir compare="Text">join_q_06</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="custord">
+ <compilation-unit name="join_q_07">
+ <output-dir compare="Text">join_q_06</output-dir>
+ <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Could not resolve type for function-call: asterix:scan-collection, Args:[%0->$$8],please check whether the used variables has been defined!</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="custord">
<compilation-unit name="load-test">
<output-dir compare="Text">load-test</output-dir>
</compilation-unit>