Browse Source

HPCC-11001 Expand no_select(no_createrow) in more situations

Also update a few places in the code which didn't support attributes on
transforms (tried as an experiment to work around an issue).

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 11 years ago
parent
commit
6f322e2e16
6 changed files with 41 additions and 16 deletions
  1. 2 0
      ecl/hql/hqlatoms.cpp
  2. 2 1
      ecl/hql/hqlatoms.hpp
  3. 2 1
      ecl/hql/hqlexpr.cpp
  4. 31 13
      ecl/hql/hqlopt.cpp
  5. 2 1
      ecl/hql/hqlthql.cpp
  6. 2 0
      ecl/hqlcpp/hqlcppds.cpp

+ 2 - 0
ecl/hql/hqlatoms.cpp

@@ -72,6 +72,7 @@ IAtom * activeFailureAtom;
 IAtom * activeNlpAtom;
 IAtom * afterAtom;
 IAtom * algorithmAtom;
+IAtom * _aliased_Atom;
 IAtom * allAtom;
 IAtom * allocatorAtom;
 IAtom * alreadyVisitedAtom;
@@ -485,6 +486,7 @@ MODULE_INIT(INIT_PRIORITY_HQLATOM)
     MAKEATOM(activeNlp);
     MAKEATOM(after);
     MAKEATOM(algorithm);
+    MAKESYSATOM(aliased);
     MAKEATOM(all);
     MAKEATOM(allocator);
     MAKEATOM(alreadyVisited);

+ 2 - 1
ecl/hql/hqlatoms.hpp

@@ -73,8 +73,9 @@ extern HQL_API IAtom * activeAtom;
 extern HQL_API IAtom * activeFailureAtom;
 extern HQL_API IAtom * activeNlpAtom;
 extern HQL_API IAtom * afterAtom;
-extern HQL_API IAtom * allAtom;
 extern HQL_API IAtom * algorithmAtom;
+extern HQL_API IAtom * _aliased_Atom;
+extern HQL_API IAtom * allAtom;
 extern HQL_API IAtom * allocatorAtom;
 extern HQL_API IAtom * _alreadyAssignedNestedTag_Atom;
 extern HQL_API IAtom * alreadyVisitedAtom;

+ 2 - 1
ecl/hql/hqlexpr.cpp

@@ -15221,8 +15221,9 @@ bool recordTypesMatchIgnorePayload(IHqlExpression *left, IHqlExpression *right)
 
 IHqlExpression * queryTransformSingleAssign(IHqlExpression * transform)
 {
-    if (transform->numChildren() != 1)
+    if ((transform->numChildren() == 0) || queryRealChild(transform, 1))
         return NULL;
+
     IHqlExpression * assign = transform->queryChild(0);
     if (assign->getOperator() == no_assignall)
     {

+ 31 - 13
ecl/hql/hqlopt.cpp

@@ -2390,17 +2390,28 @@ IHqlExpression * CTreeOptimizer::doCreateTransformed(IHqlExpression * transforme
                             IHqlExpression * cur = match;
                             while (isCast(cur))
                                 cur = cur->queryChild(0);
-                            switch (cur->getOperator())
+                            if (cur->isPure())
                             {
-                            case no_createrow:
-                            case no_constant:
-                            case no_select:
-                            case no_null:
-                            case no_getresult:
-                            case no_getgraphresult:
-                                DBGLOG("Optimizer: Extract value %s from %s", queryNode0Text(match), queryNode1Text(transformed));
-                                noteUnused(child);
-                                return match.getClear();
+                                //This test should not be required, but it avoids problems with elements from rows
+                                //being used conditionally within transforms.  See HPCC-11018 for details.
+                                if (isIndependentOfScope(match))
+                                {
+                                    DBGLOG("Optimizer: Extract value %s from %s", queryNode0Text(cur), queryNode1Text(transformed));
+                                    noteUnused(child);
+                                    return match.getClear();
+                                }
+                                switch (cur->getOperator())
+                                {
+                                case no_createrow:
+                                case no_constant:
+                                case no_select:
+                                case no_null:
+                                case no_getresult:
+                                case no_getgraphresult:
+                                    DBGLOG("Optimizer: Extract value %s from %s", queryNode0Text(match), queryNode1Text(transformed));
+                                    noteUnused(child);
+                                    return match.getClear();
+                                }
                             }
                         }
                     }
@@ -3342,9 +3353,16 @@ IHqlExpression * CTreeOptimizer::doCreateTransformed(IHqlExpression * transforme
                     ForEachChild(idxt, transformExpr)
                     {
                         IHqlExpression * cur = transformExpr->queryChild(idxt);
-                        IHqlExpression * tgt = cur->queryChild(0);
-                        IHqlExpression * src = cur->queryChild(1);
-                        assigns.append(*createAssign(LINK(tgt), expandFields(mapper, src, child, grandchild, &monitor)));
+                        if (cur->getOperator() == no_assign)
+                        {
+                            IHqlExpression * tgt = cur->queryChild(0);
+                            IHqlExpression * src = cur->queryChild(1);
+                            assigns.append(*createAssign(LINK(tgt), expandFields(mapper, src, child, grandchild, &monitor)));
+                        }
+                        else
+                        {
+                            assigns.append(*LINK(cur));
+                        }
                     }
                     OwnedHqlExpr expandedTransform = transformExpr->clone(assigns);
                     args.append(*LINK(expandedTransform));

+ 2 - 1
ecl/hql/hqlthql.cpp

@@ -2084,7 +2084,8 @@ void HqltHql::toECL(IHqlExpression *expr, StringBuffer &s, bool paren, bool inTy
             {
                 if (idx) s.append(", ");
                 IHqlExpression *child = expr->queryChild(idx);
-                getTypeString(child->queryChild(0)->queryType(), s);
+                if (!child->isAttribute())
+                    getTypeString(child->queryChild(0)->queryType(), s);
 
                 toECL(child, s.append(' '), child->getPrecedence() < 0, inType);
             }

+ 2 - 0
ecl/hqlcpp/hqlcppds.cpp

@@ -4042,6 +4042,8 @@ void HqlCppTranslator::doBuildRowAssignAggregateClear(BuildCtx & ctx, IReference
     for (idx = 0; idx < numAggregates; idx++)
     {
         IHqlExpression * cur = transform->queryChild(idx);
+        if (cur->isAttribute())
+            continue;
         Owned<IReferenceSelector> curTarget = createSelfSelect(ctx, target, cur->queryChild(0), self);
         IHqlExpression * src = cur->queryChild(1);