浏览代码

HPCC-20928 Avoid hoisting SUM where argument depends on the context

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 6 年之前
父节点
当前提交
116fbdd288
共有 3 个文件被更改,包括 52 次插入1 次删除
  1. 1 1
      ecl/hqlcpp/hqlttcpp.cpp
  2. 39 0
      testing/regress/ecl/complexhoist.ecl
  3. 12 0
      testing/regress/ecl/key/complexhoist.xml

+ 1 - 1
ecl/hqlcpp/hqlttcpp.cpp

@@ -8392,7 +8392,7 @@ IHqlExpression * NewScopeMigrateTransformer::createTransformed(IHqlExpression *
                     if ((rootOp == no_select) || (rootOp == no_field))
                         break;
 
-                    if (isIndependentOfScope(datasetExpr) && !isContextDependent(expr))
+                    if (isIndependentOfScope(expr) && !isContextDependent(expr))
                     {
                         return hoist(expr, transformed);
                     }

+ 39 - 0
testing/regress/ecl/complexhoist.ecl

@@ -0,0 +1,39 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
+
+    Licensed 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.
+############################################################################## */
+
+//HOIST(dataset({unsigned i}) ds) := NOFOLD(SORT(NOFOLD(ds), i));
+HOIST( ds) := MACRO
+//NOFOLD(SORT(NOFOLD(ds), i))
+//NOFOLD(ds)
+ds
+ENDMACRO;
+
+dsOuter := HOIST(DATASET([1,2,3,4,5,6,7,8,9], { unsigned i }));
+dsInner1 := HOIST(DATASET([11,12,13,14,15,16,17,18,19], { unsigned i }));
+dsInner2 := HOIST(DATASET([21,22,23,24,25,26,27,28,29], { unsigned i }));
+
+innerSum1(unsigned x) := SUM(dsInner1, i * x);
+outerSum1(unsigned x) := SUM(dsOuter, x * innerSum1(i));
+innerSum2(unsigned x) := SUM(dsInner2, i * outerSum1(i));
+outerSum2 := SUM(dsOuter, innerSum2(i));
+
+sequential(
+output(innerSum1(1));
+output(outerSum1(1));
+output(innerSum2(1));
+output(outerSum2);
+);

+ 12 - 0
testing/regress/ecl/key/complexhoist.xml

@@ -0,0 +1,12 @@
+<Dataset name='Result 1'>
+ <Row><Result_1>135</Result_1></Row>
+</Dataset>
+<Dataset name='Result 2'>
+ <Row><Result_2>6075</Result_2></Row>
+</Dataset>
+<Dataset name='Result 3'>
+ <Row><Result_3>34536375</Result_3></Row>
+</Dataset>
+<Dataset name='Result 4'>
+ <Row><Result_4>310827375</Result_4></Row>
+</Dataset>