Fix decimal bug in orc load (#2984)

This commit is contained in:
HangyuanLiu
2020-02-26 10:58:18 +08:00
committed by GitHub
parent 0f98f975c7
commit e23d735bac
3 changed files with 16 additions and 4 deletions

View File

@ -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<char*>(tuple_pool->allocate(v.size()));
memcpy(str_slot->ptr, v.c_str(), v.size());
str_slot->len = v.size();

View File

@ -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();
}