Skip to content

Commit 61d30bf

Browse files
zhaokuo03wgtmac
authored andcommitted
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 #2197 from kecookier/backport-2194-branch-2.0. Authored-by: zhaokuo03 <zhaokuo03@meituan.com> Signed-off-by: Gang Wu <ustcwg@gmail.com>
1 parent 6f04a2e commit 61d30bf

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

c++/src/ConvertColumnReader.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ namespace orc {
558558

559559
const auto& srcBatch = *SafeCastBatchTo<const FileTypeBatch*>(data.get());
560560
auto& dstBatch = *SafeCastBatchTo<ReadTypeBatch*>(&rowBatch);
561+
dstBatch.precision = toPrecision;
562+
dstBatch.scale = toScale;
561563
for (uint64_t i = 0; i < numValues; ++i) {
562564
if (!rowBatch.hasNulls || rowBatch.notNull[i]) {
563565
convertDecimalToDecimal(dstBatch, i, srcBatch);

c++/test/TestConvertColumnReader.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@ namespace orc {
650650
auto& readC2 = dynamic_cast<Decimal128VectorBatch&>(*readStructBatch.fields[1]);
651651
auto& readC3 = dynamic_cast<Decimal64VectorBatch&>(*readStructBatch.fields[2]);
652652
auto& readC4 = dynamic_cast<Decimal128VectorBatch&>(*readStructBatch.fields[3]);
653+
EXPECT_TRUE(9 == readC1.precision && 5 == readC1.scale);
654+
EXPECT_TRUE(20 == readC2.precision && 5 == readC2.scale);
655+
EXPECT_TRUE(10 == readC3.precision && 3 == readC3.scale);
656+
EXPECT_TRUE(19 == readC4.precision && 3 == readC4.scale);
653657
EXPECT_EQ(TEST_CASES, readBatch->numElements);
654658
for (int i = 0; i < TEST_CASES / 2; i++) {
655659
size_t idx = static_cast<size_t>(i);

0 commit comments

Comments
 (0)