From 507fa42a6f3a07c92d7df584bb439757351d9cd0 Mon Sep 17 00:00:00 2001 From: James McMullan Date: Thu, 3 Oct 2024 09:39:54 -0400 Subject: [PATCH] HPCC4J-562 Odd unsigned decimals incorrect scale (#765) Signed-off-by: James McMullan James.McMullan@lexisnexis.com --- .../org/hpccsystems/dfs/client/BinaryRecordReader.java | 10 +++++++++- dfsclient/src/test/resources/generate-datasets.ecl | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dfsclient/src/main/java/org/hpccsystems/dfs/client/BinaryRecordReader.java b/dfsclient/src/main/java/org/hpccsystems/dfs/client/BinaryRecordReader.java index 565a59454..58470fdd8 100644 --- a/dfsclient/src/main/java/org/hpccsystems/dfs/client/BinaryRecordReader.java +++ b/dfsclient/src/main/java/org/hpccsystems/dfs/client/BinaryRecordReader.java @@ -830,7 +830,15 @@ private BigDecimal getUnsignedDecimal(int numDigits, int precision, int dataLen) BigDecimal ret = new BigDecimal(0); int idx = 0; - int curDigit = numDigits - 1; + int curDigit = numDigits; + + // If the # of digits is odd the top most nibble is unused and we don't want to include it + // in the scale calculations below. Due to how the scale calculation works below this means + // we decrement the starting value of curDigit in the case of even length decimals + if ((numDigits % 2) == 0) + { + curDigit--; + } while (idx < dataLen) { diff --git a/dfsclient/src/test/resources/generate-datasets.ecl b/dfsclient/src/test/resources/generate-datasets.ecl index 9daadec07..49a2f55a8 100644 --- a/dfsclient/src/test/resources/generate-datasets.ecl +++ b/dfsclient/src/test/resources/generate-datasets.ecl @@ -9,7 +9,10 @@ childRec := {STRING8 childField1, INTEGER8 childField2, REAL8 childField3}; rec := { INTEGER8 int8, UNSIGNED8 uint8, INTEGER4 int4, UNSIGNED4 uint4, INTEGER2 int2, UNSIGNED2 uint2, REAL8 r8, REAL4 r4, - DECIMAL16_8 dec16, UDECIMAL16_8 udec16, + DECIMAL16_8 dec16, + DECIMAL15_8 dec15, + UDECIMAL16_8 udec16, + UDECIMAL15_8 udec15, QSTRING qStr, STRING8 fixStr8, STRING str, @@ -32,7 +35,9 @@ ds := DATASET(totalrecs1, transform(rec, self.r8 := (REAL)(random() % unique_values); self.r4 := (REAL)(random() % unique_values); self.dec16 := (REAL)(random() % unique_values); + self.dec15 := (REAL)(random() % unique_values); self.udec16 := (REAL)(random() % unique_values); + self.udec15 := (REAL)(random() % unique_values); self.qStr := (STRING)(random() % unique_values); self.fixStr8 := (STRING)(random() % unique_values); self.str := (STRING)(random() % unique_values);