From e23d735bac7d7ef48b5a0a5af358ca4e4415230b Mon Sep 17 00:00:00 2001 From: HangyuanLiu <460660596@qq.com> Date: Wed, 26 Feb 2020 10:58:18 +0800 Subject: [PATCH] Fix decimal bug in orc load (#2984) --- be/src/exec/orc_scanner.cpp | 18 +++++++++++++++--- be/test/exec/orc_scanner_test.cpp | 2 +- .../orc_scanner/decimal_and_timestamp.orc | Bin 831 -> 830 bytes 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/be/src/exec/orc_scanner.cpp b/be/src/exec/orc_scanner.cpp index 7b35dad512..879ca8c2a4 100644 --- a/be/src/exec/orc_scanner.cpp +++ b/be/src/exec/orc_scanner.cpp @@ -246,9 +246,21 @@ Status ORCScanner::get_next(Tuple* tuple, MemPool* tuple_pool, bool* eof) { } else { decimal_str = ((orc::Decimal128VectorBatch*) cvb)->values[_current_line_of_group].toString(); } - //Orc api will fill in 0 at the end, so size must greater than scale. But 0 is not fill. - std::string v = decimal_str == "0" ? - "0" : (decimal_str.substr(0, decimal_str.size() - scale) + "." + decimal_str.substr(decimal_str.size() - scale)); + + std::string v; + if (decimal_str.size() <= scale) { + // decimal(5,2) : the integer of 0.01 is 1, so we should fill 0 befor integer + v = "0."; + int fill_zero = scale - decimal_str.size(); + while (fill_zero--) { + v += "0"; + } + v += decimal_str; + } else { + //Orc api will fill in 0 at the end, so size must greater than scale + v = decimal_str.substr(0, decimal_str.size() - scale) + "." + decimal_str.substr(decimal_str.size() - scale); + } + str_slot->ptr = reinterpret_cast(tuple_pool->allocate(v.size())); memcpy(str_slot->ptr, v.c_str(), v.size()); str_slot->len = v.size(); diff --git a/be/test/exec/orc_scanner_test.cpp b/be/test/exec/orc_scanner_test.cpp index 60c01902b6..020dd7d5da 100644 --- a/be/test/exec/orc_scanner_test.cpp +++ b/be/test/exec/orc_scanner_test.cpp @@ -746,7 +746,7 @@ TEST_F(OrcScannerTest, normal3) { bool eof = false; ASSERT_TRUE(scanner.get_next(tuple, &tuple_pool, &eof).ok()); ASSERT_EQ(Tuple::to_string(tuple, *_desc_tbl->get_tuple_descriptor(1)), - "(0.123456789 1.12 -1.1234500000 0.12345 0 1 2020-01-14 22:12:19)"); + "(0.123456789 1.12 -1.1234500000 0.12345 0.000 1 2020-01-14 22:12:19)"); scanner.close(); } diff --git a/be/test/exec/test_data/orc_scanner/decimal_and_timestamp.orc b/be/test/exec/test_data/orc_scanner/decimal_and_timestamp.orc index 0f0d9313ea66deea06155b9122ccd12cecd0ab1a..264d6f6c388aba071ec49893c1f799e4917eaada 100644 GIT binary patch delta 215 zcmdnbwvTOt9aGFPMux`;ViAXRj-EZJ^I=NhA^(Lw&4DMUG`n}qo!B|Eb!u;Hm#U@x zaRDExM$cq}OeQtogG(f5n1m-iesEd9=t0Y+H374@eYzcfu3d>{XTE^mlJaMp&R*YQ zT9>`0L}lq6M&S+Y(fy-}67h#^pc9b4CG1 aiG~INB_;+QjY*6K>`h;onf;lAoFxHorgsPc