ASTERIXDB-1754: fix NPE in CopyLimitDownRule.

Change-Id: Ia9e26912a048c680aa9db7a12cd3933a7acbde37
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1399
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.ddl.sqlpp
new file mode 100644
index 0000000..7eb1cd1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.ddl.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * 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 test;
+
+create type CustomerType as
+{
+  cid : bigint
+}
+
+create type OrderType as
+{
+  oid : bigint
+}
+
+create external dataset Customers(CustomerType) using localfs((`path`=`asterix_nc1://data/nontagged/customerData.json`),(`format`=`adm`));
+
+create external dataset Orders(OrderType) using localfs((`path`=`asterix_nc1://data/nontagged/orderData.json`),(`format`=`adm`));
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.2.query.sqlpp
new file mode 100644
index 0000000..74e50e3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.2.query.sqlpp
@@ -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.
+ */
+
+USE test;
+
+SELECT c.name AS cust_name,
+       c.age AS cust_age,
+       o.total AS order_total
+FROM Customers c, Orders o
+WHERE c.cid = o.cid AND c.age != o.total
+LIMIT 1
+;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.adm
new file mode 100644
index 0000000..c18fb3d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/custord/query-ASTERIXDB-1754/query-ASTERIXDB-1754.1.adm
@@ -0,0 +1 @@
+{ "cust_name": "Jodi Alex", "cust_age": 19, "order_total": 7.206 }
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 57be018..bd3266e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1411,6 +1411,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="custord">
+      <compilation-unit name="query-ASTERIXDB-1754">
+        <output-dir compare="Text">query-ASTERIXDB-1754</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="custord">
       <compilation-unit name="load-test">
         <output-dir compare="Text">load-test</output-dir>
       </compilation-unit>
diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
index a68ed6c..372af26 100644
--- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
+++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
@@ -103,6 +103,7 @@
             limitCloneOp.setPhysicalOperator(new StreamLimitPOperator());
             limitCloneOp.getInputs().add(new MutableObject<ILogicalOperator>(unsafeOp));
             limitCloneOp.setExecutionMode(unsafeOp.getExecutionMode());
+            OperatorPropertiesUtil.computeSchemaRecIfNull((AbstractLogicalOperator) unsafeOp);
             limitCloneOp.recomputeSchema();
             unsafeOpRef.setValue(limitCloneOp);
             context.computeAndSetTypeEnvironmentForOperator(limitCloneOp);