ソースを参照

Merge pull request #10642 from ghalliday/issue18633

HPCC-18633 Fix case/choose mapping int->variable length string

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 年 前
コミット
84228fce6c

+ 2 - 2
ecl/hqlcpp/hqlcppcase.cpp

@@ -466,7 +466,7 @@ IHqlExpression * HqlCppCaseInfo::buildIndexedMap(BuildCtx & ctx, const CHqlBound
             if (replaceIndex >= num)
                 translator.reportWarning(CategoryIgnored, HQLWRN_CaseCanNeverMatch, "CASE entry %d can never match the test condition", replaceIndex);
             else
-                values.replace(*LINK(mapTo),replaceIndex);
+                values.replace(*ensureExprType(mapTo, resultType),replaceIndex);
         }
 
         //Now replace the placeholders with the default values.
@@ -1137,7 +1137,7 @@ bool HqlCppCaseInfo::canBuildArrayLookup(const CHqlBoundExpr & test)
         }
     }
 
-    if (condType->isInteger())
+    if (condType->isInteger() && !isUnknownSize(resultType))
     {
         unsigned __int64 range = getIntValue(highestCompareExpr, 0) - getIntValue(lowestCompareExpr, 0) + 1;
         if (pairs.ordinality() * 100 >= range  * RANGE_DENSITY_THRESHOLD)

+ 41 - 0
testing/regress/ecl/issue18633.ecl

@@ -0,0 +1,41 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2017 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.
+############################################################################## */
+
+NotLength(STRING s) := 'Length was not in:'+s;
+
+Layout_out := RECORD
+      UNSIGNED FieldsChecked_WithErrors;
+      UNSIGNED FieldsChecked_NoErrors;
+      UNSIGNED Fields_dummyfield_LengthErrors;
+END;
+
+dsTest := DATASET([{2, 0, 1}], Layout_out);
+
+
+ScrubsOrbitLayout := RECORD
+  STRING    ErrorMessage;
+  UNSIGNED8 rulecnt;
+END;
+
+ScrubsOrbitLayout xNorm(dsTest L, INTEGER c) := TRANSFORM
+      SELF.ErrorMessage := CHOOSE(c, 'Fields with errors', 'Fields without errors', NotLength('1..'));
+      SELF.rulecnt := CHOOSE(c, L.FieldsChecked_WithErrors, L.FieldsChecked_NoErrors, L.Fields_dummyfield_LengthErrors);
+END;
+
+dsScrubs := NORMALIZE(dsTest, 3, xNorm(LEFT, COUNTER));
+
+OUTPUT(dsScrubs);

+ 5 - 0
testing/regress/ecl/key/issue18633.xml

@@ -0,0 +1,5 @@
+<Dataset name='Result 1'>
+ <Row><errormessage>Fields with errors   </errormessage><rulecnt>2</rulecnt></Row>
+ <Row><errormessage>Fields without errors</errormessage><rulecnt>0</rulecnt></Row>
+ <Row><errormessage>Length was not in:1..</errormessage><rulecnt>1</rulecnt></Row>
+</Dataset>