Fix ASTERIXDB-1298

Handle the case that the original join operator in a subplan
operator is a left-outer join such that no null-check
variable needs to be added.

Change-Id: Ibb594e161d7236131a7a6a0a290e76071d4587f4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/630
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Steven Jacobs <sjaco002@ucr.edu>
diff --git a/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1298.aql b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1298.aql
new file mode 100644
index 0000000..996ba05
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1298.aql
@@ -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.
+ */
+
+drop dataverse emergencyTest if exists;
+create dataverse emergencyTest;
+use dataverse emergencyTest;
+
+
+drop dataverse channels if exists;
+create dataverse channels;
+use dataverse channels;
+
+create type userLocation as closed
+{ userId: int, roomNumber: int }
+
+create dataset userLocations(userLocation)
+primary key userId;
+
+create function currentOccupancy($room)
+{
+ let $list := for $location in dataset userLocations
+ where $location.roomNumber = $room
+ return $location.userId return $list
+};
+
+create type subscription as { "id":uuid, "param0":int }
+
+create dataset subscriptions(subscription)
+primary key id autogenerated;
+
+for $sub in dataset subscriptions
+for $result in currentOccupancy($sub.param0)
+return $result;
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1298.plan b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1298.plan
new file mode 100644
index 0000000..c62d34e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1298.plan
@@ -0,0 +1,20 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        -- HYBRID_HASH_JOIN [$$5][$$17]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$5]  |PARTITIONED|
+            -- STREAM_PROJECT  |PARTITIONED|
+              -- ASSIGN  |PARTITIONED|
+                -- STREAM_PROJECT  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$17]  |PARTITIONED|
+            -- STREAM_PROJECT  |PARTITIONED|
+              -- ASSIGN  |PARTITIONED|
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|