Browse Source

HPCC-9600 Use library classes for exists and count

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 12 years ago
parent
commit
53d7de7527

+ 4 - 0
ecl/hqlcpp/hqlcatom.cpp

@@ -445,7 +445,9 @@ IIdAtom * memcmpId;
 IIdAtom * memcpyId;
 IIdAtom * memsetId;
 IIdAtom * newWhenActionArgId;
+IIdAtom * newCountAggregateArgId;
 IIdAtom * newDegroupArgId;
+IIdAtom * newExistsAggregateArgId;
 IIdAtom * newFunnelArgId;
 IIdAtom * newGraphLoopResultWriteArgId;
 IIdAtom * newLocalResultReadArgId;
@@ -1088,7 +1090,9 @@ MODULE_INIT(INIT_PRIORITY_HQLATOM-1)
     MAKEID(memcpy);
     MAKEID(memset);
     MAKEID(newWhenActionArg);
+    MAKEID(newCountAggregateArg);
     MAKEID(newDegroupArg);
+    MAKEID(newExistsAggregateArg);
     MAKEID(newFunnelArg);
     MAKEID(newGraphLoopResultWriteArg);
     MAKEID(newLocalResultReadArg);

+ 2 - 0
ecl/hqlcpp/hqlcatom.hpp

@@ -445,7 +445,9 @@ extern IIdAtom * memcmpId;
 extern IIdAtom * memcpyId;
 extern IIdAtom * memsetId;
 extern IIdAtom * newWhenActionArgId;
+extern IIdAtom * newCountAggregateArgId;
 extern IIdAtom * newDegroupArgId;
+extern IIdAtom * newExistsAggregateArgId;
 extern IIdAtom * newFunnelArgId;
 extern IIdAtom * newGraphLoopResultWriteArgId;
 extern IIdAtom * newLocalResultReadArgId;

+ 2 - 0
ecl/hqlcpp/hqlcppsys.ecl

@@ -762,7 +762,9 @@ const char * cppSystemText[]  = {
     "   setownMethod(boolean _allocator) : omethod,entrypoint='setown';",
 
     "   boolean newWhenActionArg(boolean _meta) : include, pseudoentrypoint='new CLibraryWhenActionArg';",
+    "   boolean newCountAggregateArg(boolean _meta) : include, pseudoentrypoint='new CLibraryCountAggregateArg';",
     "   boolean newDegroupArg(boolean _meta) : include, pseudoentrypoint='new CLibraryDegroupArg';",
+    "   boolean newExistsAggregateArg(boolean _meta) : include, pseudoentrypoint='new CLibraryExistsAggregateArg';",
     "   boolean newFunnelArg(boolean _ordered, boolean _sequential, boolean _meta) : include, pseudoentrypoint='new CLibraryFunnelArg';",
     "   boolean newGraphLoopResultWriteArg(boolean _meta) : include, pseudoentrypoint='new CLibraryGraphLoopResultWriteArg';",
     "   boolean newLocalResultReadArg(unsigned4 _sequence, boolean meta) : include, pseudoentrypoint='new CLibraryLocalResultReadArg';",

+ 17 - 1
ecl/hqlcpp/hqlhtcpp.cpp

@@ -2267,7 +2267,7 @@ void ActivityInstance::buildPrefix()
     classGroupStmt = classctx.addGroupPass(sourceFileSequence);
 
     classctx.associate(*this);
-    classctx.addGroup();
+    classGroup = classctx.addGroup();
 
     if (!implementationClassName)
     {
@@ -2346,6 +2346,11 @@ void ActivityInstance::buildPrefix()
         s.clear().append("// use library for ").append(className);
         classctx.addQuoted(s);
         assertex(isExternal());
+
+        nestedctx.set(classctx);
+        createctx.set(classctx);
+        startctx.set(createctx);
+        initialGroupMarker = classGroup->numChildren();
     }
 }
 
@@ -2356,6 +2361,10 @@ void ActivityInstance::buildSuffix()
     if (onCreateStmt && (calcTotalChildren(onCreateStmt) == onCreateMarker))
         onCreateStmt->setIncluded(false);
 
+    //Paranoid check to ensure that library classes aren't used when member functions were required
+    if (implementationClassName && (initialGroupMarker != classGroup->numChildren()))
+        throwUnexpectedX("Implementation class created, but member functions generated");
+
     const HqlCppOptions & options = translator.queryOptions();
     if (classStmt && (options.spotComplexClasses || options.showActivitySizeInGraph))
     {
@@ -13094,6 +13103,7 @@ ABoundActivity * HqlCppTranslator::doBuildActivityAggregate(BuildCtx & ctx, IHql
     const char *activity;
     ThorActivityKind kind = TAKaggregate;
     node_operator specialOp = no_none;
+    IIdAtom * implementationClassId = NULL;
     if (passThrough)
     {
         activity = "ThroughAggregate";
@@ -13114,11 +13124,15 @@ ABoundActivity * HqlCppTranslator::doBuildActivityAggregate(BuildCtx & ctx, IHql
         {
             kind = TAKexistsaggregate;
             activity = "ExistsAggregate";
+            if (options.minimizeActivityClasses)
+                implementationClassId = newExistsAggregateArgId;
         }
         else if (specialOp == no_countgroup)
         {
             kind = TAKcountaggregate;
             activity = "CountAggregate";
+            if (options.minimizeActivityClasses)
+                implementationClassId = newCountAggregateArgId;
         }
         else
             specialOp = no_none;
@@ -13126,6 +13140,8 @@ ABoundActivity * HqlCppTranslator::doBuildActivityAggregate(BuildCtx & ctx, IHql
 
 
     Owned<ActivityInstance> instance = new ActivityInstance(*this, ctx, kind, expr, activity);
+    if (implementationClassId)
+        instance->setImplementationClass(implementationClassId);
     if (passThrough)
     {
         StringBuffer graphLabel;

+ 2 - 0
ecl/hqlcpp/hqlhtcpp.ipp

@@ -206,7 +206,9 @@ public:
     Owned<ParentExtract> parentExtract;
     Owned<EvalContext> parentEvalContext;
     IHqlStmt *  onCreateStmt;
+    IHqlStmt * classGroup;
     unsigned    onCreateMarker;
+    unsigned    initialGroupMarker;
     HqlExprArray constructorArgs;
     HqlExprCopyArray names;
     LocationArray locations;

+ 22 - 0
rtl/include/eclhelper_base.hpp

@@ -1,3 +1,4 @@
+
 /*##############################################################################
 #    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
 #
@@ -3472,6 +3473,27 @@ protected:
     IOutputMetaData * meta;
 };
 
+class CLibraryCountAggregateArg : public CThorCountAggregateArg
+{
+public:
+    inline CLibraryCountAggregateArg(IOutputMetaData * _meta) : meta(_meta) {}
+
+    virtual IOutputMetaData * queryOutputMeta() { return meta; }
+
+protected:
+    IOutputMetaData * meta;
+};
+
+class CLibraryExistsAggregateArg : public CThorExistsAggregateArg
+{
+public:
+    inline CLibraryExistsAggregateArg(IOutputMetaData * _meta) : meta(_meta) {}
+
+    virtual IOutputMetaData * queryOutputMeta() { return meta; }
+
+protected:
+    IOutputMetaData * meta;
+};
 
 class EclProcess : public RtlCInterface, implements IEclProcess
 {