Quellcode durchsuchen

Better support for WHEN actions.

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday vor 13 Jahren
Ursprung
Commit
a30042ecee

+ 1 - 0
ecl/eclagent/eclgraph.cpp

@@ -207,6 +207,7 @@ static IHThorActivity * createActivity(IAgentContext & agent, unsigned activityI
     case TAKemptyaction:
     case TAKifaction:
     case TAKwhen_dataset:
+    case TAKwhen_action:
         return createDummyActivity(agent, activityId, subgraphId, arg, kind);
     case TAKhashdedup:
         return createHashDedupActivity(agent, activityId, subgraphId, (IHThorHashDedupArg &)arg, kind);

+ 4 - 0
ecl/hql/hqlgram.y

@@ -8683,6 +8683,10 @@ sideEffectOptions
                         {
                             $$.setExpr(createAttribute(failureAtom), $2);
                         }
+    | ',' PARALLEL
+                        {
+                            $$.setExpr(createAttribute(parallelAtom), $2);
+                        }
     ;
 
 limitOptions

+ 2 - 1
ecl/hqlcpp/hqlcpp.ipp

@@ -1536,7 +1536,7 @@ public:
     bool buildNWayInputs(CIArrayOf<ABoundActivity> & inputs, BuildCtx & ctx, IHqlExpression * input);
 
 //Activities.   
-    ABoundActivity * doBuildActivityAction(BuildCtx & ctx, IHqlExpression * expr, bool isRoot, bool expandChildren);
+    ABoundActivity * doBuildActivityAction(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
     ABoundActivity * doBuildActivityAggregate(BuildCtx & ctx, IHqlExpression * expr);
     ABoundActivity * doBuildActivityApply(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
     ABoundActivity * doBuildActivityAssert(BuildCtx & ctx, IHqlExpression * expr);
@@ -1631,6 +1631,7 @@ public:
     ABoundActivity * doBuildActivitySetGraphResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
     ABoundActivity * doBuildActivitySetGraphLoopResult(BuildCtx & ctx, IHqlExpression * expr);
     ABoundActivity * doBuildActivitySetResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
+    ABoundActivity * doBuildActivitySideEffect(BuildCtx & ctx, IHqlExpression * expr, bool isRoot, bool expandChildren);
     ABoundActivity * doBuildActivitySpill(BuildCtx & ctx, IHqlExpression * expr);
     ABoundActivity * doBuildActivitySplit(BuildCtx & ctx, IHqlExpression * expr);
     ABoundActivity * doBuildActivityHTTP(BuildCtx & ctx, IHqlExpression * expr, bool isSink, bool isRoot);

+ 29 - 5
ecl/hqlcpp/hqlhtcpp.cpp

@@ -1883,7 +1883,6 @@ ActivityInstance::ActivityInstance(HqlCppTranslator & _translator, BuildCtx & ct
         }
         else
         {
-
             if (executedRemotely)
             {
                 GraphLocalisation localisation = queryActivityLocalisation(dataset);
@@ -5900,7 +5899,7 @@ ABoundActivity * HqlCppTranslator::buildActivity(BuildCtx & ctx, IHqlExpression
             case no_call:
             case no_externalcall:
                 if (expr->isAction())
-                    result = doBuildActivityAction(ctx, expr, isRoot, false);
+                    result = doBuildActivityAction(ctx, expr, isRoot);
                 else if (hasStreamedModifier(expr->queryType()))
                 {
                     result = doBuildActivityStreamedCall(ctx, expr);
@@ -5989,7 +5988,10 @@ ABoundActivity * HqlCppTranslator::buildActivity(BuildCtx & ctx, IHqlExpression
                     result = doBuildActivityWorkunitRead(ctx, expr);
                 break;
             case no_fail:
-                result = doBuildActivityAction(ctx, expr, isRoot, !expr->isAction());
+                if (expr->isAction())
+                    result = doBuildActivityAction(ctx, expr, isRoot);
+                else
+                    result = doBuildActivitySideEffect(ctx, expr, isRoot, true);
                 break;
             case no_null:
                 if (expr->isDatarow())
@@ -6266,7 +6268,7 @@ ABoundActivity * HqlCppTranslator::buildActivity(BuildCtx & ctx, IHqlExpression
                 break;
             default:
                 if (expr->isAction())
-                    return doBuildActivityAction(ctx, expr, isRoot, false);
+                    return doBuildActivityAction(ctx, expr, isRoot);
                 if (expr->isDatarow())
                 {
                     OwnedHqlExpr row = createDatasetFromRow(LINK(expr));
@@ -16739,8 +16741,9 @@ ABoundActivity * HqlCppTranslator::doBuildActivityNull(BuildCtx & ctx, IHqlExpre
 
 //---------------------------------------------------------------------------
 
-ABoundActivity * HqlCppTranslator::doBuildActivityAction(BuildCtx & ctx, IHqlExpression * expr, bool isRoot, bool expandChildren)
+ABoundActivity * HqlCppTranslator::doBuildActivitySideEffect(BuildCtx & ctx, IHqlExpression * expr, bool isRoot, bool expandChildren)
 {
+    //Something that is treated like an input, but causes something else to happen - e.g., a failure
     StringBuffer s;
     Owned<ActivityInstance> instance = new ActivityInstance(*this, ctx, TAKsideeffect, expr,"Action");
 
@@ -16772,6 +16775,27 @@ ABoundActivity * HqlCppTranslator::doBuildActivityAction(BuildCtx & ctx, IHqlExp
     return instance->getBoundActivity();
 }
 
+
+ABoundActivity * HqlCppTranslator::doBuildActivityAction(BuildCtx & ctx, IHqlExpression * expr, bool isRoot)
+{
+    StringBuffer s;
+    Owned<ActivityInstance> instance = new ActivityInstance(*this, ctx, TAKsimpleaction, expr, "Action");
+
+    //-----------------
+    instance->graphLabel.set(getOpString(expr->getOperator()));         // label node as "fail"
+    buildActivityFramework(instance, isRoot);
+
+    buildInstancePrefix(instance);
+
+    BuildCtx funcctx(instance->startctx);
+    funcctx.addQuotedCompoundOpt("virtual void action()");
+    buildStmt(funcctx, expr);
+
+    buildInstanceSuffix(instance);
+
+    return instance->getBoundActivity();
+}
+
 //---------------------------------------------------------------------------
 // if (ctx->currentWorkflowId() == number)
 //    doCode();

+ 1 - 0
ecl/hqlcpp/hqlttcpp.cpp

@@ -831,6 +831,7 @@ YesNoOption HqlThorBoundaryTransformer::calcNormalizeThor(IHqlExpression * expr)
             return isNew ? OptionYes : OptionMaybe;
         }
     case NO_AGGREGATE:
+    case no_executewhen:
         return OptionYes;
     case NO_ACTION_REQUIRES_GRAPH:
         {

+ 7 - 5
ecl/regress/when6.ecl

@@ -1,4 +1,5 @@
-/*##############################################################################
+<Archive>
+<!--
 
     Copyright (C) 2011 HPCC Systems.
 
@@ -14,8 +15,8 @@
 
     You should have received a copy of the GNU Affero General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
-############################################################################## */
-
+-->
+<Query>
 r := {unsigned f1, unsigned f2, unsigned f3, unsigned f4 };
 
 r t(unsigned a, unsigned b, unsigned c, unsigned d) := TRANSFORM
@@ -35,9 +36,10 @@ simple := dedup(ds, f1);
 
 osum := output(TABLE(simple, { sum(group, f1) }, f3));
 
-x1 := when(simple, osum);
+x1 := when(simple, osum, parallel);
 
 o1 := output(TABLE(x1, { f1 }));
 o2 := output(TABLE(simple, { count(group) }, f3));
 when(o1, o2, success);
-//when(o1, o2);
+</Query>
+</Archive>

+ 45 - 0
ecl/regress/when7.eclxml

@@ -0,0 +1,45 @@
+<Archive>
+<!--
+
+    Copyright (C) 2011 HPCC Systems.
+
+    All rights reserved. This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<Query>
+r := {unsigned f1, unsigned f2, unsigned f3, unsigned f4 };
+
+r t(unsigned a, unsigned b, unsigned c, unsigned d) := TRANSFORM
+    SELF.f1 := a;
+    SELF.f2 := b;
+    SELF.f3 := c;
+    SELF.f4 := d;
+END;
+
+ds := dataset([
+        t(1,2,3,4),
+        t(1,4,2,5),
+        t(9,3,4,5),
+        t(3,4,2,9)]);
+
+simple := dedup(ds, f1);
+
+osum := output(TABLE(simple, { sum(group, f1) }, f3));
+
+x1 := when(simple, osum);
+
+o1 := output(TABLE(x1, { f1 }));
+o2 := output(TABLE(simple, { count(group) }, f3));
+when(o1, o2);
+</Query>
+</Archive>

+ 49 - 0
ecl/regress/when8.eclxml

@@ -0,0 +1,49 @@
+<Archive>
+<!--
+
+    Copyright (C) 2011 HPCC Systems.
+
+    All rights reserved. This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<Query>
+r := {unsigned f1, unsigned f2, unsigned f3, unsigned f4 };
+
+r t(unsigned a, unsigned b, unsigned c, unsigned d) := TRANSFORM
+    SELF.f1 := a;
+    SELF.f2 := b;
+    SELF.f3 := c;
+    SELF.f4 := d;
+END;
+
+ds := dataset([
+        t(1,2,3,4),
+        t(1,4,2,5),
+        t(9,3,4,5),
+        t(3,4,2,9)]);
+
+simple := dedup(ds, f1);
+
+osum := output(TABLE(simple, { sum(group, f1) }, f3));
+
+trueValue := true : stored('trueValue');
+
+osumx := IF(trueValue, osum, FAIL('Should not be called'));
+
+x1 := when(simple, osumx);
+
+o1 := output(TABLE(x1, { f1 }));
+o2 := output(TABLE(simple, { count(group) }, f3));
+when(o1, o2);
+</Query>
+</Archive>