Explorar el Código

gh-1375 Access graph results directly if available

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday hace 13 años
padre
commit
299ddf1593

+ 2 - 2
ecl/hqlcpp/hqlcpp.ipp

@@ -988,8 +988,8 @@ public:
     IHqlExpression * createRowSerializer(BuildCtx & ctx, IHqlExpression * record, _ATOM kind);
 
     AliasKind buildExprInCorrectContext(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, bool evaluateLocally);
-    ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * expr, bool doDeclare);
-    ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, GraphLocalisation localisation, bool doDeclare);
+    ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, IHqlExpression * expr, bool doDeclare);
+    ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, GraphLocalisation localisation, bool doDeclare);
         
     void buildDefaultRow(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
     void buildNullRow(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);

+ 7 - 7
ecl/hqlcpp/hqlcppds.cpp

@@ -1182,7 +1182,7 @@ void ChildGraphBuilder::generateGraph(BuildCtx & ctx)
     OwnedHqlExpr query = createActionList(results);
     OwnedHqlExpr resourced = translator.getResourcedChildGraph(graphctx, query, represents, numResults, no_none);
 
-    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(graphctx, PETchild, resourced, true);
+    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(graphctx, PETchild, represents, resourced, true);
     if (!translator.queryOptions().serializeRowsetInExtract)
         extractBuilder->setAllowDestructor();
     translator.beginExtract(graphctx, extractBuilder);
@@ -1231,7 +1231,7 @@ void ChildGraphBuilder::generatePrefetchGraph(BuildCtx & _ctx, OwnedHqlExpr * re
     OwnedHqlExpr query = createActionList(results);
     OwnedHqlExpr resourced = translator.getResourcedChildGraph(ctx, query, represents, numResults, no_none);
 
-    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(ctx, PETchild, resourced, false);
+    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(ctx, PETchild, represents, resourced, false);
     createBuilderAlias(aliasctx, extractBuilder);
     translator.beginExtract(ctx, extractBuilder);
 
@@ -1353,8 +1353,8 @@ unique_id_t ChildGraphBuilder::buildLoopBody(BuildCtx & ctx, IHqlExpression * da
         resourced.setown(appendOwnedOperand(resourced, createAttribute(multiInstanceAtom)));
 
     bool isGlobalThorLoop = translator.targetThor() && !translator.insideChildQuery(ctx);
-    Owned<ParentExtract> extractBuilder = isGlobalThorLoop ? translator.createExtractBuilder(ctx, PETloop, GraphRemote, false)
-                                                           : translator.createExtractBuilder(ctx, PETloop, resourced, false);
+    Owned<ParentExtract> extractBuilder = isGlobalThorLoop ? translator.createExtractBuilder(ctx, PETloop, represents, GraphRemote, false)
+                                                           : translator.createExtractBuilder(ctx, PETloop, represents, resourced, false);
 
     createBuilderAlias(subctx, extractBuilder);
 
@@ -1477,8 +1477,8 @@ unique_id_t ChildGraphBuilder::buildGraphLoopBody(BuildCtx & ctx, IHqlExpression
     }
 
     bool isGlobalThorLoop = translator.targetThor() && !translator.insideChildQuery(ctx);
-    Owned<ParentExtract> extractBuilder = isGlobalThorLoop ? translator.createExtractBuilder(ctx, PETloop, GraphRemote, false)
-                                                           : translator.createExtractBuilder(ctx, PETloop, resourced, false);
+    Owned<ParentExtract> extractBuilder = isGlobalThorLoop ? translator.createExtractBuilder(ctx, PETloop, represents, GraphRemote, false)
+                                                           : translator.createExtractBuilder(ctx, PETloop, represents, resourced, false);
 
     createBuilderAlias(subctx, extractBuilder);
 
@@ -1504,7 +1504,7 @@ unique_id_t ChildGraphBuilder::buildRemoteGraph(BuildCtx & ctx, IHqlExpression *
         query.set(ds);
     OwnedHqlExpr resourced = translator.getResourcedChildGraph(ctx, query, represents, numResults, no_allnodes);
 
-    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(ctx, PETremote, GraphRemote, false);
+    Owned<ParentExtract> extractBuilder = translator.createExtractBuilder(ctx, PETremote, represents, GraphRemote, false);
 
     createBuilderAlias(subctx, extractBuilder);
 

+ 10 - 2
ecl/hqlcpp/hqlhtcpp.cpp

@@ -2470,7 +2470,7 @@ ParentExtract * ActivityInstance::createNestedExtract()
 {
     if (!nestedExtract)
     {
-        nestedExtract.setown(new ParentExtract(translator, PETnested, GraphCoLocal, evalContext));
+        nestedExtract.setown(new ParentExtract(translator, PETnested, NULL, GraphCoLocal, evalContext));
         nestedExtract->beginNestedExtract(startctx);
     }
     return LINK(nestedExtract);
@@ -6054,7 +6054,15 @@ ABoundActivity * HqlCppTranslator::buildActivity(BuildCtx & ctx, IHqlExpression
                 //Use the get graph result activity if we are generating the correct level graph.
                 //otherwise it needs to be serialized from the parent activity
                 {
-                    if (isCurrentActiveGraph(ctx, expr->queryChild(1)))
+                    IHqlExpression * graphId = expr->queryChild(1);
+                    bool canAccessResultDirectly = isCurrentActiveGraph(ctx, graphId);
+                    if (getTargetClusterType() == ThorLCRCluster)
+                    {
+                        ParentExtract * extract = static_cast<ParentExtract*>(ctx.queryFirstAssociation(AssocExtract));
+                        if (extract)
+                            canAccessResultDirectly = extract->areGraphResultsAccessible(graphId);
+                    }
+                    if (canAccessResultDirectly)
                         result = doBuildActivityGetGraphResult(ctx, expr);
                     else
                         result = doBuildActivityChildDataset(ctx, expr);

+ 32 - 7
ecl/hqlcpp/hqlinline.cpp

@@ -730,8 +730,8 @@ bool HqlCppTranslator::isNeverDistributed(IHqlExpression * expr)
 //============================================================================
 
 
-ParentExtract::ParentExtract(HqlCppTranslator & _translator, PEtype _type, GraphLocalisation _localisation, EvalContext * _container)
-: HqlExprAssociation(parentExtractMarkerExpr), translator(_translator), type(_type)
+ParentExtract::ParentExtract(HqlCppTranslator & _translator, PEtype _type, IHqlExpression * _graphId, GraphLocalisation _localisation, EvalContext * _container)
+: HqlExprAssociation(parentExtractMarkerExpr), translator(_translator), type(_type), graphId(_graphId)
 {
     localisation = _localisation;
     container = _container;
@@ -945,6 +945,20 @@ bool ParentExtract::insideChildQuery() const
     return container->insideChildQuery();
 }
 
+bool ParentExtract::areGraphResultsAccessible(IHqlExpression * searchGraphId) const
+{
+    if (graphId == searchGraphId)
+        return true;
+
+    switch (type)
+    {
+    case PETloop:
+        return container->areGraphResultsAccessible(searchGraphId);
+    }
+    return false;
+}
+
+
 void ParentExtract::endCreateExtract(CHqlBoundExpr & boundExtract)
 {
     //NB: This can be called more than once - so need to be careful about any processing that
@@ -1174,14 +1188,14 @@ void ParentExtract::gatherActiveRows(BuildCtx & ctx)
 
 //----------------------------------------------------------------------------
 
-ParentExtract * HqlCppTranslator::createExtractBuilder(BuildCtx & ctx, PEtype type, GraphLocalisation localisation, bool doDeclare)
+ParentExtract * HqlCppTranslator::createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, GraphLocalisation localisation, bool doDeclare)
 {
     ParentExtract * extractor = NULL;
 //  if (localisation == GraphCoLocal)
 //      extract = checkForPreexistingExtract - find a bound association before a row association is found;
     if (!extractor)
     {
-        extractor = new ParentExtract(*this, type, localisation, queryEvalContext(ctx));
+        extractor = new ParentExtract(*this, type, graphId, localisation, queryEvalContext(ctx));
         extractor->beginCreateExtract(ctx, doDeclare);
     }
     else
@@ -1190,12 +1204,12 @@ ParentExtract * HqlCppTranslator::createExtractBuilder(BuildCtx & ctx, PEtype ty
 }
 
 
-ParentExtract * HqlCppTranslator::createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * expr, bool doDeclare)
+ParentExtract * HqlCppTranslator::createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, IHqlExpression * expr, bool doDeclare)
 {
     if (isAlwaysCoLocal())
-        return createExtractBuilder(ctx, type, GraphCoLocal, true);
+        return createExtractBuilder(ctx, type, graphId, GraphCoLocal, true);
     bool isInsideChildQuery = (type == PETchild) || insideChildQuery(ctx);
-    return createExtractBuilder(ctx, type, getGraphLocalisation(expr, isInsideChildQuery), true);
+    return createExtractBuilder(ctx, type, graphId, getGraphLocalisation(expr, isInsideChildQuery), true);
 }
 
 
@@ -1355,6 +1369,17 @@ ActivityInstance * EvalContext::queryActivity()
 }
 
 
+bool EvalContext::areGraphResultsAccessible(IHqlExpression * searchGraphId) const
+{
+    if (parentExtract)
+        return parentExtract->areGraphResultsAccessible(searchGraphId);
+    if (parent)
+        return parent->areGraphResultsAccessible(searchGraphId);
+    return false;
+}
+
+
+
 IHqlExpression * HqlCppTranslator::doCreateGraphLookup(BuildCtx & declarectx, BuildCtx & resolvectx, unique_id_t id, const char * activity, bool isChild)
 {
     StringBuffer s, var;

+ 5 - 1
ecl/hqlcpp/hqlinline.hpp

@@ -26,10 +26,11 @@ class EvalContext;
 // A parent extract represents the set of fields etc. which are used from the parent activity,
 // which are local to the point that the executeChildActivity() is called.  The type indicates
 // the reason it is being created.
+// There should always an EvalContext associated with a ParentExtract
 class ParentExtract : public HqlExprAssociation
 {
 public:
-    ParentExtract(HqlCppTranslator & _translator, PEtype _type, GraphLocalisation _localisation, EvalContext * _container=NULL);
+    ParentExtract(HqlCppTranslator & _translator, PEtype _type, IHqlExpression * _graphId, GraphLocalisation _localisation, EvalContext * _container);
     ~ParentExtract();
 
 //HqlExprAssociation
@@ -57,6 +58,7 @@ public:
 
     bool requiresOnStart() const;
     bool insideChildQuery() const;
+    bool areGraphResultsAccessible(IHqlExpression * searchGraphId) const;
 
 protected:
     void ensureAccessible(BuildCtx & ctx, IHqlExpression * expr, const CHqlBoundExpr & bound, CHqlBoundExpr & tgt, IHqlExpression * colocal);
@@ -79,6 +81,7 @@ protected:
     CHqlBoundExpr boundExtract;     // always a reference to a row. for "extract"
     Owned<BuildCtx> buildctx;       // may be null if nested extract
     PEtype type;
+    IHqlExpression * graphId;
     bool canDestroyExtract;
 };
 
@@ -131,6 +134,7 @@ public://only used by friends
 
     bool requiresOnStart() const;
     bool insideChildQuery() const;
+    bool areGraphResultsAccessible(IHqlExpression * graphId) const;
 
 protected:
     Owned<ParentExtract> parentExtract;         // extract of the parent EvalContext

+ 2 - 2
ecl/hqlcpp/hqllib.cpp

@@ -479,7 +479,7 @@ void HqlCppTranslator::buildLibraryInstanceExtract(BuildCtx & ctx, HqlCppLibrary
 
     BuildCtx beforeBuilderCtx(subctx);
     beforeBuilderCtx.addGroup();
-    Owned<ParentExtract> extractBuilder = createExtractBuilder(subctx, PETlibrary, GraphNonLocal, false);
+    Owned<ParentExtract> extractBuilder = createExtractBuilder(subctx, PETlibrary, NULL, GraphNonLocal, false);
 
     StringBuffer s;
     s.append("rtlRowBuilder & ");
@@ -630,7 +630,7 @@ void HqlCppTranslator::buildLibraryGraph(BuildCtx & ctx, IHqlExpression * expr,
         libraryContext->associateExpression(initctx, &parameter);
     }
 
-    Owned<ParentExtract> extractBuilder = createExtractBuilder(initctx, PETlibrary, GraphRemote, false);
+    Owned<ParentExtract> extractBuilder = createExtractBuilder(initctx, PETlibrary, outputLibraryId, GraphRemote, false);
     beginExtract(initctx, extractBuilder);
 
     BuildCtx evalctx(ctx);

+ 1 - 1
ecl/hqlcpp/hqlsource.cpp

@@ -2365,7 +2365,7 @@ void SourceBuilder::buildGroupAggregateTransformBody(BuildCtx & transformCtx, IH
     Owned<ParentExtract> extractBuilder;
     if (useExtract || (aggregate != mappedAggregate))
     {
-        extractBuilder.setown(translator.createExtractBuilder(transformCtx, PETcallback, GraphCoLocal, true));
+        extractBuilder.setown(translator.createExtractBuilder(transformCtx, PETcallback, NULL, GraphCoLocal, true));
         if (!translator.queryOptions().serializeRowsetInExtract)
             extractBuilder->setAllowDestructor();
         translator.beginExtract(transformCtx, extractBuilder);