-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[feature](jsonb) Add decimal type in JsonbDocument #51766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
run buildall |
TPC-H: Total hot run time: 34268 ms
|
TPC-DS: Total hot run time: 193862 ms
|
ClickBench: Total hot run time: 28.66 s
|
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
@@ -756,6 +767,99 @@ class JsonbIntVal : public JsonbValue { | |||
} | |||
}; | |||
|
|||
template <typename T> | |||
requires std::same_as<T, vectorized::Decimal256> || std::same_as<T, vectorized::Decimal128V3> | |||
class JsonbDecimalVal : public JsonbValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把Decimal继承NumberValT吧?NumberValT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NumberValT <DecimalField>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该不太行,我们的decimal field 没有precision 信息。。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外,就是如果后面有人去改了decimal field 里的东西会直接影响这里的持久化,所以最好不要让他跟decimal field 有关系
be/src/util/jsonb_document.h
Outdated
T_Decimal256 = 0x0F, // Decimal256 | ||
T_Date = 0x10, // v2 only | ||
T_DateTime = 0x11, // v2 only | ||
T_Time = 0x12, // v2 only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要Ip类型吗
be/src/util/jsonb_document.h
Outdated
@@ -133,6 +137,11 @@ enum class JsonbType : char { | |||
T_Array = 0x0B, | |||
T_Int128 = 0x0C, | |||
T_Float = 0x0D, | |||
T_Decimal = 0x0E, // DecimalV3 only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decimal32/Decimal64 都变成Decimal128吗
我看没有改 |
be/src/util/jsonb_document.h
Outdated
@@ -133,6 +137,11 @@ enum class JsonbType : char { | |||
T_Array = 0x0B, | |||
T_Int128 = 0x0C, | |||
T_Float = 0x0D, | |||
T_Decimal = 0x0E, // DecimalV3 only | |||
T_Decimal256 = 0x0F, // Decimal256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么decimal256 和 decimalv3 是两个?
run buildall |
run buildall |
TPC-H: Total hot run time: 33701 ms
|
TPC-DS: Total hot run time: 186269 ms
|
ClickBench: Total hot run time: 28.86 s
|
be/src/util/jsonb_utils.cpp
Outdated
// If enable_json_decimal_as_string is true, we output decimal as string | ||
// to avoid precision loss. | ||
os_.put('"'); | ||
os_.write(value_str.data(), value_str.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just keep this branch ? string_to_float will lost precision, and user maybe confused?
be/src/util/jsonb_document.h
Outdated
} | ||
|
||
private: | ||
uint32_t _precision; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is uint_8 enough for _precision and _scale?
be/src/util/jsonb_writer.h
Outdated
return JsonbDocument::checkAndCreateDocument(getOutput()->getBuffer(), | ||
getOutput()->getSize()); | ||
JsonbDocument* doc = nullptr; | ||
auto st = JsonbDocument::checkAndCreateDocument(getOutput()->getBuffer(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use THROW_IF_ERROR
be/src/util/jsonb_utils.cpp
Outdated
template <JsonbDecimalType T> | ||
void JsonbToJson::decimal_to_json(const T& value, const uint32_t precision, const uint32_t scale) { | ||
auto value_str = value.to_string(precision, scale); | ||
if (config::enable_json_decimal_as_string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要加这种config,没什么意义。
jsonb ---> json string, 对于decimal 我们的预定义行为就是转成number,或者说float。 如果用户认为应该是string,那么应该用户自己去处理一下jsonb 里的decimal,提前转成string。我们不要把一些用户能自己做的事情,或者可选的事情,变成我们这里的开关。
be/src/util/jsonb_document.h
Outdated
sizeof(uint32_t) * 2); // decimal128 | ||
} | ||
case JsonbType::T_Decimal256: { | ||
return (sizeof(type_) + sizeof(vectorized::Decimal256::NativeType) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种逻辑应该移动到decimal的jsonb value 里来维护,否则后面有人去把scale 改成uint8,直接废了
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
run buildall |
TPC-H: Total hot run time: 33906 ms
|
TPC-DS: Total hot run time: 185414 ms
|
ClickBench: Total hot run time: 29.88 s
|
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
run buildall |
} | ||
case JsonbType::T_Null: | ||
case JsonbType::T_True: | ||
case JsonbType::T_False: | ||
default: | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的default 为什么不是抛异常?而是返回一个0?
TPC-H: Total hot run time: 34055 ms
|
void JsonbToJson::decimal_to_json(const T& value, const uint32_t precision, const uint32_t scale) { | ||
auto value_str = value.to_string(precision, scale); | ||
|
||
StringParser::ParseResult result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要先转string,然后再转float?我们decimal 转float 没有直接的方法?cast 里是怎么实现的?
TPC-DS: Total hot run time: 188464 ms
|
ClickBench: Total hot run time: 29.54 s
|
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
run buildall |
What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)