incubator-doris Why does DECIMALV2 cast to PackedInt128 in RawValue::print_value()?

dfty9e19  于 2022-04-22  发布在  Java
关注(0)|答案(2)|浏览(161)

incubator-doris/be/src/runtime/raw_value.cpp

Lines 168 to 170 in eefad13

| | case TYPE_DECIMALV2: |
| | stream << reinterpret_cast<const PackedInt128>(value)->value; |
| | break; |

Why not to use DecimalV2Value, to enhance readability?

eit6fx6z

eit6fx6z1#

cause decimal_v2 use int128_t, C++ compiler will do some optimized for it. But the DecimalV2 value is not ensured to be aligned, which will cause crash.

jckbn6z7

jckbn6z72#

cause decimal_v2 use int128_t, C++ compiler will do some optimized for it. But the DecimalV2 value is not ensured to be aligned, which will cause crash.

But it's printing a const void* value.
And I've seen some reinterpret_cast to DecimalV2Value, e.g.

incubator-doris/be/src/exec/tablet_sink.cpp

Lines 851 to 853 in eefad13

| | case TYPE_DECIMALV2: { |
| | DecimalV2Value dec_val(reinterpret_cast<const PackedInt128*>(slot)->value); |
| | if (dec_val.greater_than_scale(desc->type().scale)) { |

So it's wrong to do like this?

相关问题