[Bug](serde) fix serialize column to jsonb when meet boolean and decimal_v3 (#19011)

* [Bug](serde) fix serialize column to jsonb when meet boolean and decimal_v3

* add comment to explain why use uint8
This commit is contained in:
lihangyu
2023-04-25 10:48:13 +08:00
committed by GitHub
parent 4ef43f5374
commit d555bae290
5 changed files with 50 additions and 39 deletions

View File

@ -107,7 +107,8 @@ void DataTypeDecimalSerDe<T>::write_one_cell_to_jsonb(const IColumn& column, Jso
*reinterpret_cast<const Decimal128::NativeType*>(data_ref.data);
result.writeInt128(val);
} else if constexpr (std::is_same_v<T, Decimal<Int128I>>) {
Decimal64::NativeType val = *reinterpret_cast<const Decimal64::NativeType*>(data_ref.data);
Decimal128I::NativeType val =
*reinterpret_cast<const Decimal128I::NativeType*>(data_ref.data);
result.writeInt128(val);
} else if constexpr (std::is_same_v<T, Decimal<Int32>>) {
Decimal32::NativeType val = *reinterpret_cast<const Decimal32::NativeType*>(data_ref.data);

View File

@ -185,7 +185,7 @@ template <typename T>
void DataTypeNumberSerDe<T>::read_one_cell_from_jsonb(IColumn& column,
const JsonbValue* arg) const {
auto& col = reinterpret_cast<ColumnType&>(column);
if constexpr (std::is_same_v<T, Int8>) {
if constexpr (std::is_same_v<T, Int8> || std::is_same_v<T, UInt8>) {
col.insert_value(static_cast<const JsonbInt8Val*>(arg)->val());
} else if constexpr (std::is_same_v<T, Int16> || std::is_same_v<T, UInt16>) {
col.insert_value(static_cast<const JsonbInt16Val*>(arg)->val());
@ -210,7 +210,11 @@ void DataTypeNumberSerDe<T>::write_one_cell_to_jsonb(const IColumn& column,
int row_num) const {
result.writeKey(col_id);
StringRef data_ref = column.get_data_at(row_num);
if constexpr (std::is_same_v<T, Int8>) {
// TODO: Casting unsigned integers to signed integers may result in loss of data precision.
// However, as Doris currently does not support unsigned integers, only the boolean type uses
// uint8_t for representation, making the cast acceptable. In the future, we should add support for
// both unsigned integers in Doris types and the JSONB types.
if constexpr (std::is_same_v<T, Int8> || std::is_same_v<T, UInt8>) {
int8_t val = *reinterpret_cast<const int8_t*>(data_ref.data);
result.writeInt8(val);
} else if constexpr (std::is_same_v<T, Int16> || std::is_same_v<T, UInt16>) {

View File

@ -79,6 +79,10 @@ void JsonbSerializeUtil::jsonb_to_block(const TupleDescriptor& desc, const char*
SlotDescriptor* slot = desc.slots()[j];
JsonbValue* slot_value = doc->find(slot->col_unique_id());
MutableColumnPtr dst_column = dst.get_by_position(j).column->assume_mutable();
if (!slot_value || slot_value->isNull()) {
dst_column->insert_default();
continue;
}
dst.get_data_type(j)->get_serde()->read_one_cell_from_jsonb(*dst_column, slot_value);
}
}