Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions be/src/exec/orc_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,23 @@ Status ORCScanner::get_next(Tuple* tuple, MemPool* tuple_pool, bool* eof) {
} else {
decimal_str = ((orc::Decimal128VectorBatch*) cvb)->values[_current_line_of_group].toString();
}

int negative = decimal_str[0] == '-' ? 1 : 0;
int decimal_scale_length = decimal_str.size() - negative;

std::string v;
if (decimal_str.size() <= scale) {
if (decimal_scale_length <= 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();
v = std::string(negative ? "-0." : "0.");
int fill_zero = scale - decimal_scale_length;
while (fill_zero--) {
v += "0";
}
v += decimal_str;
if (negative) {
v += decimal_str.substr(1, decimal_str.length());
} else {
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);
Expand Down
47 changes: 42 additions & 5 deletions be/test/exec/orc_scanner_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ TEST_F(OrcScannerTest, normal3) {
expr.nodes.push_back(cast_expr);
expr.nodes.push_back(slot_ref);

params.expr_of_dest_slot.emplace(8 + i, expr);
params.expr_of_dest_slot.emplace(9 + i, expr);
params.src_slot_ids.push_back(i);
}

Expand Down Expand Up @@ -606,7 +606,7 @@ TEST_F(OrcScannerTest, normal3) {
expr.nodes.push_back(cast_expr);
expr.nodes.push_back(slot_ref);

params.expr_of_dest_slot.emplace(13, expr);
params.expr_of_dest_slot.emplace(14, expr);
params.src_slot_ids.push_back(5);
}

Expand Down Expand Up @@ -639,7 +639,7 @@ TEST_F(OrcScannerTest, normal3) {
expr.nodes.push_back(cast_expr);
expr.nodes.push_back(slot_ref);

params.expr_of_dest_slot.emplace(14, expr);
params.expr_of_dest_slot.emplace(15, expr);
params.src_slot_ids.push_back(6);
}
{
Expand Down Expand Up @@ -671,9 +671,42 @@ TEST_F(OrcScannerTest, normal3) {
expr.nodes.push_back(cast_expr);
expr.nodes.push_back(slot_ref);

params.expr_of_dest_slot.emplace(15, expr);
params.expr_of_dest_slot.emplace(16, expr);
params.src_slot_ids.push_back(7);
}
{
TExprNode cast_expr;
cast_expr.node_type = TExprNodeType::CAST_EXPR;
cast_expr.type = decimal_type;
cast_expr.__set_opcode(TExprOpcode::CAST);
cast_expr.__set_num_children(1);
cast_expr.__set_output_scale(-1);
cast_expr.__isset.fn = true;
cast_expr.fn.name.function_name = "casttodecimal";
cast_expr.fn.binary_type = TFunctionBinaryType::BUILTIN;
cast_expr.fn.arg_types.push_back(varchar_type);
cast_expr.fn.ret_type = decimal_type;
cast_expr.fn.has_var_args = false;
cast_expr.fn.__set_signature("cast_to_decimal_val(VARCHAR(*))");
cast_expr.fn.__isset.scalar_fn = true;
cast_expr.fn.scalar_fn.symbol = "doris::DecimalOperators::cast_to_decimal_val";

TExprNode slot_ref;
slot_ref.node_type = TExprNodeType::SLOT_REF;
slot_ref.type = varchar_type;
slot_ref.num_children = 0;
slot_ref.__isset.slot_ref = true;
slot_ref.slot_ref.slot_id = 8;
slot_ref.slot_ref.tuple_id = 0;

TExpr expr;
expr.nodes.push_back(cast_expr);
expr.nodes.push_back(slot_ref);

params.expr_of_dest_slot.emplace(17, expr);
params.src_slot_ids.push_back(8);
}

}
params.__set_src_tuple_id(0);
params.__set_dest_tuple_id(1);
Expand Down Expand Up @@ -709,6 +742,8 @@ TEST_F(OrcScannerTest, normal3) {
TSlotDescriptorBuilder().string_type(65535).nullable(true).column_name("col7").column_pos(7).build());
src_tuple_builder.add_slot(
TSlotDescriptorBuilder().string_type(65535).nullable(true).column_name("col8").column_pos(8).build());
src_tuple_builder.add_slot(
TSlotDescriptorBuilder().string_type(65535).nullable(true).column_name("col9").column_pos(9).build());
src_tuple_builder.build(&dtb);

TTupleDescriptorBuilder dest_tuple_builder;
Expand All @@ -728,6 +763,8 @@ TEST_F(OrcScannerTest, normal3) {
TSlotDescriptorBuilder().type(TYPE_DATETIME).column_name("col7").column_pos(7).build());
dest_tuple_builder.add_slot(
TSlotDescriptorBuilder().type(TYPE_DATE).nullable(true).column_name("col8").column_pos(8).build());
dest_tuple_builder.add_slot(
TSlotDescriptorBuilder().decimal_type(27,9).column_name("col9").column_pos(9).build());

dest_tuple_builder.build(&dtb);
t_desc_table = dtb.desc_tbl();
Expand Down Expand Up @@ -755,7 +792,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.000 1 2020-01-14 14:12:19 2020-02-10)");
"(0.123456789 1.12 -1.1234500000 0.12345 0.000 1 2020-01-14 14:12:19 2020-02-10 -0.0014)");
scanner.close();
}

Expand Down
Binary file modified be/test/exec/test_data/orc_scanner/decimal_and_timestamp.orc
Binary file not shown.