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 0f0d9313ea..264d6f6c38 100644 Binary files a/be/test/exec/test_data/orc_scanner/decimal_and_timestamp.orc and b/be/test/exec/test_data/orc_scanner/decimal_and_timestamp.orc differ