Explorar o código

HPCC-24638 Fix generating functions with decimal return types

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday %!s(int64=4) %!d(string=hai) anos
pai
achega
afb6210a2d

+ 17 - 0
ecl/hqlcpp/hqlcpp.cpp

@@ -6050,6 +6050,23 @@ void HqlCppTranslator::doBuildCall(BuildCtx & ctx, const CHqlBoundTarget * tgt,
         }
         returnByReference = true;
         break;
+    case type_decimal:
+        {
+            OwnedHqlExpr result;
+            if (tgt)
+            {
+                doneAssign = true;
+                result.set(tgt->expr);
+            }
+            else
+            {
+                result.setown(ctx.getTempDeclare(retType, NULL));
+            }
+            args.append(*createValue(no_reference, result->getType(), LINK(result)));
+            localBound.expr.set(result);
+            returnByReference = true;
+            break;
+        }
     case type_set:
         {
             translateSetReturn = !newFormatSet;

+ 4 - 0
ecl/hqlcpp/hqlhtcpp.cpp

@@ -3216,6 +3216,10 @@ void HqlCppTranslator::doBuildFunctionReturn(BuildCtx & ctx, ITypeInfo * type, I
         target.expr.setown(createVariable("__result", makeReferenceModifier(LINK(type))));
         returnByReference = true;
         break;
+    case type_decimal:
+        target.expr.setown(createVariable("__result", makeReferenceModifier(LINK(type))));
+        returnByReference = true;
+        break;
     }
 
     if (returnByReference)

+ 4 - 0
ecl/hqlcpp/hqlwcpp.cpp

@@ -1019,6 +1019,10 @@ void HqlCppWriter::generateFunctionReturnType(StringBuffer & params, ITypeInfo *
             }
             break;
         }
+    case type_decimal:
+        out.append("void");
+        params.append("byte __result[").append(retType->getSize()).append(']');
+        break;
     case type_transform:
         out.append("size32_t");
         params.append("ARowBuilder & __self");

+ 21 - 0
ecl/regress/issue24638.ecl

@@ -0,0 +1,21 @@
+Layout_Test := RECORD
+  DECIMAL32_10 DecimalField;
+  REAL8 RealField;
+END;
+
+FieldValFunc(Layout_Test le,UNSIGNED2 FN) := DEFINE CASE(FN,1 => le.DecimalField,2 => le.RealField,0);
+
+FieldValFunc(DATASET([{1.234, 2.5}], Layout_Test)[1], 1);
+
+
+createDecimal(real x) := DEFINE (decimal32_31)x;
+
+pi := 3.14159265;
+output(NOFOLD(pi));
+
+one := 1 : stored('one');
+oneD := createDecimal(one);
+output(oneD + oneD);
+
+//Check that it preserves 27 significant digits...
+output(createDecimal(pi) + createDecimal(pi/1.0e9)  + createDecimal(pi/1.0e18));

+ 12 - 0
testing/regress/ecl/key/outofline.xml

@@ -0,0 +1,12 @@
+<Dataset name='Result 1'>
+ <Row><Result_1>1.234</Result_1></Row>
+</Dataset>
+<Dataset name='Result 2'>
+ <Row><Result_2>3.14159265</Result_2></Row>
+</Dataset>
+<Dataset name='Result 3'>
+ <Row><Result_3>2</Result_3></Row>
+</Dataset>
+<Dataset name='Result 4'>
+ <Row><Result_4>3.14159265314159265314159265</Result_4></Row>
+</Dataset>

+ 38 - 0
testing/regress/ecl/outofline.ecl

@@ -0,0 +1,38 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2020 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.
+############################################################################## */
+
+Layout_Test := RECORD
+  DECIMAL32_10 DecimalField;
+  REAL8 RealField;
+END;
+
+FieldValFunc(Layout_Test le,UNSIGNED2 FN) := DEFINE CASE(FN,1 => le.DecimalField,2 => le.RealField,0);
+
+FieldValFunc(DATASET([{1.234, 2.5}], Layout_Test)[1], 1);
+
+
+createDecimal(real x) := DEFINE (decimal32_31)x;
+
+pi := 3.14159265;
+output(NOFOLD(pi));
+
+one := 1 : stored('one');
+oneD := createDecimal(one);
+output(oneD + oneD);
+
+//Check that it preserves 27 significant digits...
+output(createDecimal(pi) + createDecimal(pi/1.0e9)  + createDecimal(pi/1.0e18));