Bläddra i källkod

Merge pull request #3708 from ghalliday/issue3208

HPCC-3208 Report a warning if a scalar output is used in an APPLY

Reviewed-By: Renato Golin <rengolin@hpccsystems.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 år sedan
förälder
incheckning
4d647e0736
4 ändrade filer med 46 tillägg och 3 borttagningar
  1. 2 0
      ecl/hqlcpp/hqlcerrors.hpp
  2. 19 2
      ecl/hqlcpp/hqlttcpp.cpp
  3. 3 1
      ecl/hqlcpp/hqlttcpp.ipp
  4. 22 0
      ecl/regress/issue3208.ecl

+ 2 - 0
ecl/hqlcpp/hqlcerrors.hpp

@@ -204,6 +204,7 @@
 #define HQLERR_OutsideGroupAggregate            4182
 #define HQLERR_ResourceAddAfterFinalManifest    4183
 #define HQLERR_SkipInsideCreateRow              4184
+#define HQLERR_ScalarOutputWithinApply          4185
 
 //Warnings....
 #define HQLWRN_PersistDataNotLikely             4500
@@ -480,6 +481,7 @@
 #define HQLERR_OutsideGroupAggregate_Text       "%s used outside of a TABLE aggregation"
 #define HQLERR_ResourceAddAfterFinalManifest_Text "%s resource added after manifest was finalized"
 #define HQLERR_SkipInsideCreateRow_Text         "SKIP inside a ROW(<transform>) not supported.  It is only allowed in a DATASET transform."
+#define HQLERR_ScalarOutputWithinApply_Text     "A scalar output within an APPLY is undefined and may fail.  Use OUTPUT(dataset,EXTEND) instead."
 
 //Warnings.
 #define HQLWRN_CannotRecreateDistribution_Text  "Cannot recreate the distribution for a persistent dataset"

+ 19 - 2
ecl/hqlcpp/hqlttcpp.cpp

@@ -1223,8 +1223,9 @@ static void normalizeResultFormat(WorkflowArray & workflow, const HqlCppOptions
 //---------------------------------------------------------------------------
 
 static HqlTransformerInfo sequenceNumberAllocatorInfo("SequenceNumberAllocator");
-SequenceNumberAllocator::SequenceNumberAllocator() : NewHqlTransformer(sequenceNumberAllocatorInfo)
+SequenceNumberAllocator::SequenceNumberAllocator(HqlCppTranslator & _translator) : NewHqlTransformer(sequenceNumberAllocatorInfo), translator(_translator)
 {
+    applyDepth = 0;
     sequence = 0;
 }
 
@@ -1354,6 +1355,22 @@ IHqlExpression * SequenceNumberAllocator::createTransformed(IHqlExpression * exp
     {
     case no_actionlist:
         return doTransformRootExpr(expr);
+    case no_apply:
+        {
+            HqlExprArray args;
+            args.append(*transform(expr->queryChild(0)));
+            applyDepth++;
+            args.append(*transform(expr->queryChild(1)));
+            applyDepth--;
+            OwnedHqlExpr ret = completeTransform(expr, args);
+            return attachSequenceNumber(ret);
+        }
+    case no_outputscalar:
+        if (applyDepth)
+        {
+            translator.WARNINGAT(expr, HQLERR_ScalarOutputWithinApply);
+        }
+        break;
     }
     Owned<IHqlExpression> transformed = NewHqlTransformer::createTransformed(expr);
     return attachSequenceNumber(transformed.get());
@@ -1412,7 +1429,7 @@ IHqlExpression * SequenceNumberAllocator::attachSequenceNumber(IHqlExpression *
 void HqlCppTranslator::allocateSequenceNumbers(HqlExprArray & exprs)
 {
     HqlExprArray sequenced;
-    SequenceNumberAllocator transformer;
+    SequenceNumberAllocator transformer(*this);
     transformer.transformRoot(exprs, sequenced);
     replaceArray(exprs, sequenced);
     maxSequence = transformer.getMaxSequence();

+ 3 - 1
ecl/hqlcpp/hqlttcpp.ipp

@@ -155,7 +155,7 @@ private:
 class SequenceNumberAllocator : public NewHqlTransformer
 {
 public:
-    SequenceNumberAllocator();
+    SequenceNumberAllocator(HqlCppTranslator & _translator);
 
     virtual IHqlExpression * createTransformed(IHqlExpression * expr);
     virtual ANewTransformInfo * createTransformInfo(IHqlExpression * expr) { return CREATE_NEWTRANSFORMINFO(SequenceNumberInfo, expr); }
@@ -172,6 +172,8 @@ protected:
     IHqlExpression * attachSequenceNumber(IHqlExpression * expr);
 
 protected:
+    HqlCppTranslator & translator; // should really be an error handler - could do with refactoring.
+    unsigned applyDepth;
     unsigned sequence;
     MapOwnedHqlToOwnedHql namedMap;
 };

+ 22 - 0
ecl/regress/issue3208.ecl

@@ -0,0 +1,22 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+test := DATASET([1,2,3,4], {INTEGER N});
+
+APPLY(test,
+    OUTPUT(n)
+    ) ;