Bläddra i källkod

Fix problems with merge implicit sort order

- The implicit sort order should be updated once the tree has been
  normalized, otherwise it might be possible for the scoping on the
  expressions to be incorrect (since replaceSelectors assumes normalized)

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 13 år sedan
förälder
incheckning
e63fe9b7dc
1 ändrade filer med 30 tillägg och 33 borttagningar
  1. 30 33
      ecl/hqlcpp/hqlttcpp.cpp

+ 30 - 33
ecl/hqlcpp/hqlttcpp.cpp

@@ -9057,6 +9057,35 @@ IHqlExpression * HqlScopeTagger::createTransformed(IHqlExpression * expr)
                 reportError("PROJECT() row argument resolved to a dataset.  Missing DATASET() from parameter type?");
             return transformed.getClear();
         }
+    case no_merge:
+        {
+            HqlExprArray children;
+            transformChildren(expr, children);
+            IHqlExpression * sorted = queryProperty(sortedAtom, children);
+            if (!sorted || queryProperty(_implicitSorted_Atom, children))
+            {
+                IHqlExpression * dataset = &children.item(0);
+                removeProperty(children, _implicitSorted_Atom);
+
+                if (sorted)
+                    children.zap(*sorted);
+
+                HqlExprArray sorts;
+                OwnedHqlExpr order = getExistingSortOrder(dataset, expr->hasProperty(localAtom), true);
+                if (order)
+                    unwindChildren(sorts, order);
+                ForEachItemInRev(i, sorts)
+                {
+                    if (sorts.item(i).isAttribute())
+                    {
+                        reportError(HQLWRN_MergeBadSortOrder_Text, true);
+                        sorts.remove(i);
+                    }
+                }
+                children.append(*createExprAttribute(sortedAtom, sorts));
+            }
+            return expr->clone(children);
+        }
     }
 
     return Parent::createTransformed(expr);
@@ -10356,39 +10385,7 @@ IHqlExpression * HqlTreeNormalizer::transformKeyIndex(IHqlExpression * expr)
 IHqlExpression * HqlTreeNormalizer::transformMerge(IHqlExpression * expr)
 {
     HqlExprArray children;
-    bool same = transformChildren(expr, children);
-
-    //MORE: Check sort orders are consistent and add an order attribute,
-    IHqlExpression * dataset = &children.item(0);
-    IHqlExpression * distribution = queryDistribution(dataset);
-
-//  I'm really not sure why the following code was present.
-//  if (distribution && !isSortDistribution(distribution) && !expr->hasProperty(localAtom))
-//      children.append(*createLocalAttribute());
-
-    IHqlExpression * sorted = queryProperty(sortedAtom, children);
-    if (!sorted || queryProperty(_implicitSorted_Atom, children))
-    {
-        if (sorted)
-        {
-            removeProperty(children, _implicitSorted_Atom);
-            children.zap(*sorted);
-        }
-
-        HqlExprArray sorts;
-        OwnedHqlExpr order = getExistingSortOrder(dataset, expr->hasProperty(localAtom), true);
-        if (order)
-            unwindChildren(sorts, order);
-        ForEachItemInRev(i, sorts)
-        {
-            if (sorts.item(i).isAttribute())
-            {
-                translator.reportWarning(HQLWRN_MergeBadSortOrder, HQLWRN_MergeBadSortOrder_Text);
-                sorts.remove(i);
-            }
-        }
-        children.append(*createExprAttribute(sortedAtom, sorts));
-    }
+    transformChildren(expr, children);
 
     HqlExprArray args;
     reorderAttributesToEnd(args, children);