This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new 44990bd10 ORC-1881: [C++] Populate dstBatch's scale and precision in
DecimalConvertColumnReader
44990bd10 is described below
commit 44990bd100b8987b3a614e32c9bbd479d0a418d6
Author: zhaokuo03 <[email protected]>
AuthorDate: Tue Apr 22 18:30:58 2025 +0900
ORC-1881: [C++] Populate dstBatch's scale and precision in
DecimalConvertColumnReader
### What changes were proposed in this pull request?
Set dstBatch's decimal and precision when
`DecimalConvertColumnReader::next`.
Fix ORC-1881.
### Why are the changes needed?
During decimal-to-decimal conversion in `SchemaEvolution`, the target
decimal's scale and precision are incorrectly initialized to zero, producing a
corrupted `ColumnVectorBatch`.
### How was this patch tested?
Unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #2194 from kecookier/fix-decimal-2-decimal.
Authored-by: zhaokuo03 <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
c++/src/ConvertColumnReader.cc | 2 ++
c++/test/TestConvertColumnReader.cc | 4 ++++
2 files changed, 6 insertions(+)
diff --git a/c++/src/ConvertColumnReader.cc b/c++/src/ConvertColumnReader.cc
index a9003bc16..c0f88246e 100644
--- a/c++/src/ConvertColumnReader.cc
+++ b/c++/src/ConvertColumnReader.cc
@@ -579,6 +579,8 @@ namespace orc {
const auto& srcBatch = *SafeCastBatchTo<const
FileTypeBatch*>(data.get());
auto& dstBatch = *SafeCastBatchTo<ReadTypeBatch*>(&rowBatch);
+ dstBatch.precision = toPrecision_;
+ dstBatch.scale = toScale_;
for (uint64_t i = 0; i < numValues; ++i) {
if (!rowBatch.hasNulls || rowBatch.notNull[i]) {
convertDecimalToDecimal(dstBatch, i, srcBatch);
diff --git a/c++/test/TestConvertColumnReader.cc
b/c++/test/TestConvertColumnReader.cc
index 7c5f05bd3..6096fe457 100644
--- a/c++/test/TestConvertColumnReader.cc
+++ b/c++/test/TestConvertColumnReader.cc
@@ -651,6 +651,10 @@ namespace orc {
auto& readC2 =
dynamic_cast<Decimal128VectorBatch&>(*readStructBatch.fields[1]);
auto& readC3 =
dynamic_cast<Decimal64VectorBatch&>(*readStructBatch.fields[2]);
auto& readC4 =
dynamic_cast<Decimal128VectorBatch&>(*readStructBatch.fields[3]);
+ EXPECT_TRUE(9 == readC1.precision && 5 == readC1.scale);
+ EXPECT_TRUE(20 == readC2.precision && 5 == readC2.scale);
+ EXPECT_TRUE(10 == readC3.precision && 3 == readC3.scale);
+ EXPECT_TRUE(19 == readC4.precision && 3 == readC4.scale);
EXPECT_EQ(TEST_CASES, readBatch->numElements);
for (int i = 0; i < TEST_CASES / 2; i++) {
size_t idx = static_cast<size_t>(i);