Merged asterix_stabilization r529:r543.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_fix_agg@544 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
index a01af41..3b11b0a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
@@ -51,6 +51,7 @@
 import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.BreakSelectIntoConjunctsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ComplexJoinInferenceRule;
+import edu.uci.ics.hyracks.algebricks.rewriter.rules.ComplexUnnestToProductRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ConsolidateAssignsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ConsolidateSelectsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.EliminateSubplanRule;
@@ -120,6 +121,7 @@
         condPushDownAndJoinInference.add(new PushDieUpRule());
         condPushDownAndJoinInference.add(new RemoveRedundantListifyRule());
         condPushDownAndJoinInference.add(new SimpleUnnestToProductRule());
+        condPushDownAndJoinInference.add(new ComplexUnnestToProductRule());
         condPushDownAndJoinInference.add(new ComplexJoinInferenceRule());
         condPushDownAndJoinInference.add(new PushSelectIntoJoinRule());
         condPushDownAndJoinInference.add(new IntroJoinInsideSubplanRule());
diff --git a/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_01.aql b/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_01.aql
new file mode 100644
index 0000000..85ee87a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_01.aql
@@ -0,0 +1,15 @@
+/*
+ * Description    : Tests that non-datascan unnests are rewritten into joins.
+ * Success        : Yes
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/unnest-to-join_01.adm";
+
+for $x in [1,2,3,4,5,6]
+for $y in [4,5,6,7,8,9]
+where $x = $y
+return $y
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_02.aql b/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_02.aql
new file mode 100644
index 0000000..2402eb0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/unnest-to-join_02.aql
@@ -0,0 +1,12 @@
+/*
+ * Description    : Tests that non-datascan unnests in a subplan are rewritten into joins.
+ * Success        : Yes
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/unnest-to-join_02.adm";
+
+some $x in [1,2,3,4,5,6], $y in [4,5,6,7,8,9] satisfies $x = $y
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_01.plan b/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_01.plan
new file mode 100644
index 0000000..d43cc94
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_01.plan
@@ -0,0 +1,10 @@
+-- SINK_WRITE  |UNPARTITIONED|
+  -- STREAM_PROJECT  |UNPARTITIONED|
+    -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+      -- HYBRID_HASH_JOIN [$$0][$$1]  |UNPARTITIONED|
+        -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          -- UNNEST  |UNPARTITIONED|
+            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+        -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          -- UNNEST  |UNPARTITIONED|
+            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_02.plan b/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_02.plan
new file mode 100644
index 0000000..1f56c4f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/unnest-to-join_02.plan
@@ -0,0 +1,11 @@
+-- SINK_WRITE  |UNPARTITIONED|
+  -- STREAM_PROJECT  |UNPARTITIONED|
+    -- AGGREGATE  |UNPARTITIONED|
+      -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+        -- HYBRID_HASH_JOIN [$$0][$$1]  |UNPARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+            -- UNNEST  |UNPARTITIONED|
+              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+            -- UNNEST  |UNPARTITIONED|
+              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterix-app/src/test/resources/runtimets/ignore.txt b/asterix-app/src/test/resources/runtimets/ignore.txt
index 04f6692..d567c45 100644
--- a/asterix-app/src/test/resources/runtimets/ignore.txt
+++ b/asterix-app/src/test/resources/runtimets/ignore.txt
@@ -34,4 +34,5 @@
 quantifiers/somesat_03.aql
 quantifiers/somesat_04.aql
 quantifiers/somesat_05.aql
+quantifiers/everysat_02.aql
 quantifiers/everysat_03.aql
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql
new file mode 100644
index 0000000..caa30d7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql
@@ -0,0 +1,12 @@
+/*
+ * Description      :   Add anything plus null, the result should be null.
+ * Expected Result  :   Success
+ * Date             :   19th July 2012
+ */
+
+write output to nc1:"rttest/constructor_add-null.adm";
+
+let $x := 1
+let $y := 10
+let $z := 20
+return ($x+$y+$z+null)
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm b/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm
@@ -0,0 +1 @@
+null