Fix for ASTERIXDB-1018, ASTERIXDB-1017, ASTERIXDB-1019,
ASTERIXDB-1020, ASTERIXDB-1029, ASTERIXDB-1030, ASTERIXDB-1034

1. Inline SubplanOperator input and hence remove SubplanOperator.

2. Use boolean return from initFromSubTree to confirm that the
result should actually be used in IntroduceJoinAccessMethodRule
Prevent accidental attempted cast of null variable
in AbstractIntroduceAccessMethodrule.

Change-Id: Ifc1f844ac6e06e00da3f1618235b6ce9bfd48e9f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/489
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1017-recursive-2.aql b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1017-recursive-2.aql
new file mode 100644
index 0000000..da7d535
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1017-recursive-2.aql
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+create type CHPReport as
+{ "rid":uuid, "epicenter":point, "radius":double }
+
+create type userLocation as
+{ "id":uuid, "user-id":int64, "location":point }
+
+create type tornadoShelter as
+{ "tsid":uuid, "location":point }
+
+create type sub as closed
+{ "id":int, "param0":int64 }
+
+create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
+primary key id;
+
+create dataset tornadoShelters(tornadoShelter)
+primary key tsid autogenerated;
+
+create dataset userLocations(userLocation)
+primary key id autogenerated;
+
+create dataset CHPReports(CHPReport)
+primary key rid autogenerated;
+
+
+create function NearbySheltersDuringTornadoDanger($userid) {
+   for $emergency in dataset CHPReports
+   let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
+   where (some $user in dataset userLocations satisfies $user.user-id = $userid
+          and spatial-intersect($dangerzone, $user.location))
+   return
+   { "shelter locations":for $shelter in dataset tornadoShelters return $shelter.location}
+};
+
+create function findShelters($sub){
+    for $result in NearbySheltersDuringTornadoDanger($sub.param0)
+    return { "subscription-id":$sub.subscription-id,"execution-time":current-datetime(),"result":$result }
+};
+
+for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
+for $r in findShelters($sub)
+return $r;