Skip to content

Commit

Permalink
Merge pull request #19131 from jackdelv/HPCC-32687
Browse files Browse the repository at this point in the history
HPCC-32687 Output large Decimals correctly

Reviewed-By: Dan S. Camper <[email protected]>
Reviewed-by: Gavin Halliday <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Sep 20, 2024
2 parents f5846f3 + 1d2a926 commit a74bdd8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common/deftype/defvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ const char *DecimalValue::generateCPP(StringBuffer &s, CompilerType compiler)

const char *DecimalValue::getStringValue(StringBuffer &s)
{
char strval[64];
char strval[MAX_DECIMAL_CHARS];
BcdCriticalBlock bcdBlock;
pushDecimalValue();
DecPopCString(sizeof(strval), strval);
Expand Down
12 changes: 6 additions & 6 deletions rtl/eclrtl/rtlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void CFormEncodedWriter::outputReal(double field, const char *fieldname)

void CFormEncodedWriter::outputDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
updateCurrentScalarItemInfo(fieldname);
appendFormUrlEncodedName(out, curIdx, curItemPath, fieldname, flags);

Expand All @@ -1065,7 +1065,7 @@ void CFormEncodedWriter::outputDecimal(const void *field, unsigned size, unsigne

void CFormEncodedWriter::outputUDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
updateCurrentScalarItemInfo(fieldname);
appendFormUrlEncodedName(out, curIdx, curItemPath, fieldname, flags);

Expand Down Expand Up @@ -1446,7 +1446,7 @@ void CommonCSVWriter::outputDecimal(const void* field, unsigned size, unsigned p
return;

StringBuffer v;
char dec[50];
char dec[MAX_DECIMAL_CHARS];
BcdCriticalBlock bcdBlock;
if (DecValid(true, size*2-1, field))
{
Expand All @@ -1465,7 +1465,7 @@ void CommonCSVWriter::outputUDecimal(const void* field, unsigned size, unsigned
return;

StringBuffer v;
char dec[50];
char dec[MAX_DECIMAL_CHARS];
BcdCriticalBlock bcdBlock;
if (DecValid(false, size*2, field))
{
Expand Down Expand Up @@ -2117,7 +2117,7 @@ inline void outputEncodedXmlReal(double field, const char *fieldname, StringBuff

inline void outputEncodedXmlDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname, StringBuffer &out)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
if (fieldname)
out.append('<').append(fieldname).append(" xsi:type=\"xsd:decimal\">");

Expand All @@ -2139,7 +2139,7 @@ inline void outputEncodedXmlDecimal(const void *field, unsigned size, unsigned p

inline void outputEncodedXmlUDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname, StringBuffer &out)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
if (fieldname)
out.append('<').append(fieldname).append(" xsi:type=\"xsd:decimal\">");

Expand Down
8 changes: 4 additions & 4 deletions rtl/eclrtl/rtlxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void outputXmlDecimal(const void *field, unsigned size, unsigned precision, cons
if (DecValid(true, size*2-1, field))
{
Decimal temp;
char dec[50];
char dec[MAX_DECIMAL_CHARS];
temp.setDecimal(size, precision, field);
temp.getCString(sizeof(dec), dec);

Expand All @@ -118,7 +118,7 @@ void outputXmlUDecimal(const void *field, unsigned size, unsigned precision, con
if (DecValid(false, size*2, field))
{
Decimal temp;
char dec[50];
char dec[MAX_DECIMAL_CHARS];
temp.setUDecimal(size, precision, field);
temp.getCString(sizeof(dec), dec);

Expand Down Expand Up @@ -249,7 +249,7 @@ void outputJsonUnicode(unsigned len, const UChar *field, const char *fieldname,

void outputJsonDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname, StringBuffer &out)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
appendJSONNameOrDelimit(out, fieldname);

BcdCriticalBlock bcdBlock;
Expand All @@ -265,7 +265,7 @@ void outputJsonDecimal(const void *field, unsigned size, unsigned precision, con

void outputJsonUDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname, StringBuffer &out)
{
char dec[50];
char dec[MAX_DECIMAL_CHARS];
appendJSONNameOrDelimit(out, fieldname);

BcdCriticalBlock bcdBlock;
Expand Down
1 change: 1 addition & 0 deletions system/include/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ inline bool DeleteFile(const char * name) { return unlink(name)==0; }
#define MAX_DECIMAL_LEADING 32 // Maximum number of leading digits in a decimal field
#define MAX_DECIMAL_PRECISION 32 // Maximum digits in a decimal field
#define MAX_DECIMAL_DIGITS (MAX_DECIMAL_LEADING+MAX_DECIMAL_PRECISION)
#define MAX_DECIMAL_CHARS (MAX_DECIMAL_DIGITS+3) // Maximum digits with sign, decimal point, and null terminator

#define strtok(a,b) j_strtok_deprecated(a,b) // will disappear at some point

Expand Down
34 changes: 34 additions & 0 deletions testing/regress/ecl/decimalOutput.ecl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 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.
############################################################################## */

// Decimals with less than 50 digits are output correctly
x := (DECIMAL48_32) '1234567890123456.12345678901234567890123456789012';
y := (DECIMAL48_16) '12345678901234567890123456789012.1234567890123456';
// For digits >= 50, the output was 50 '*' rather than the actual value
i := (DECIMAL49_32) '12345678901234567.12345678901234567890123456789012';
j := (DECIMAL50_32) '123456789012345678.12345678901234567890123456789012';
OUTPUT(x);
OUTPUT(y);
OUTPUT(i);
OUTPUT(j);

a := (DECIMAL64_32) '12345678901234567890123456789012.12345678901234567890123456789012';
// Max length Decimal with 64 digits and a negative sign
b := (DECIMAL64_32) '-12345678901234567890123456789011.12345678901234567890123456789012';
OUTPUT(a);
OUTPUT(b);
OUTPUT(a + b);
21 changes: 21 additions & 0 deletions testing/regress/ecl/key/decimalOutput.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Dataset name='Result 1'>
<Row><Result_1>1234567890123456.12345678901234567890123456789012</Result_1></Row>
</Dataset>
<Dataset name='Result 2'>
<Row><Result_2>12345678901234567890123456789012.1234567890123456</Result_2></Row>
</Dataset>
<Dataset name='Result 3'>
<Row><Result_3>12345678901234567.12345678901234567890123456789012</Result_3></Row>
</Dataset>
<Dataset name='Result 4'>
<Row><Result_4>123456789012345678.12345678901234567890123456789012</Result_4></Row>
</Dataset>
<Dataset name='Result 5'>
<Row><Result_5>12345678901234567890123456789012.12345678901234567890123456789012</Result_5></Row>
</Dataset>
<Dataset name='Result 6'>
<Row><Result_6>-12345678901234567890123456789011.12345678901234567890123456789012</Result_6></Row>
</Dataset>
<Dataset name='Result 7'>
<Row><Result_7>1</Result_7></Row>
</Dataset>

0 comments on commit a74bdd8

Please sign in to comment.