-
Notifications
You must be signed in to change notification settings - Fork 410
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
support json_valid
and json_keys
#8491
support json_valid
and json_keys
#8491
Conversation
json_valid
and json_keys
json_valid
and json_keys
/run-all-tests |
dbms/src/Functions/FunctionsJson.h
Outdated
{ | ||
auto cur_offset = tmp_buffer.offset(); | ||
JsonBinary::appendStringRef(tmp_buffer, key); | ||
auto after_offset = tmp_buffer.offset(); |
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.
I‘m a little confused that looks like key
is already a StringRef/string_view based on the real data in data_from
, why here need to deep copy it to tmp_buffer
and construct new StringRef based on tmp_buffer
?
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.
ok..
add a new function buildKeyArrayInBuffer
for std::vector<std::string_view> keys
dbms/src/Functions/FunctionsJson.h
Outdated
ColumnUInt8::Container & vec_null_map = col_null_map->getData(); | ||
|
||
{ | ||
JsonBinary::JsonBinaryWriteBuffer write_buffer(data_to, data_from.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.
I'm a little worried that it will reserve too many memories for the 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.
Maybe we can use two loops, first is to extract the keys from orignal json column, then use another loop to do the copy? The intermediate result should not be too large if we keep the key_binaries as StringRef refering the orignal data in data_from
?
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.
This could be inconvenient, especially when dealing with nullmap.
Typically, keys are very small, how about automatically resize instead of reserve?
https://github.com/pingcap/tiflash/pull/8491/files#diff-52627c7f14d286918db163406a85acac41a1ad79c22184768379ebe163c1131aR1664-R1665
eea1e6e
to
7648ecf
Compare
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.
Others LGTM
dbms/src/Functions/FunctionsJson.h
Outdated
throw Exception( | ||
fmt::format("Illegal json path expression of function {}", getName()), | ||
ErrorCodes::ILLEGAL_COLUMN); | ||
auto path_expr_containor = std::make_unique<JsonPathExprRefContainer>(path_expr); |
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.
typo here: path_expr_container
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.
ok, updated.
dbms/src/Functions/FunctionsJson.h
Outdated
throw Exception( | ||
fmt::format("Illegal json path expression of function {}", getName()), | ||
ErrorCodes::ILLEGAL_COLUMN); | ||
auto path_expr_containor = std::make_unique<JsonPathExprRefContainer>(path_expr); |
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.
typo, path_expr_container
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.
ok, updated.
std::vector<JsonPathExprRefContainerPtr> path_expr_containor_vec(1); | ||
path_expr_containor_vec[0] = std::move(path_expr_containor); | ||
|
||
const auto & json_val = json_source->getWhole(); |
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.
If actual extract codes can be extracted as a common function, it would look better.
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.
good point, updated.
dbms/src/TiDB/Decode/JsonBinary.cpp
Outdated
@@ -389,12 +391,12 @@ JsonBinary JsonBinary::getArrayElement(size_t index) const | |||
return getValueEntry(HEADER_SIZE + index * VALUE_ENTRY_SIZE); | |||
} | |||
|
|||
String JsonBinary::getObjectKey(size_t index) const | |||
std::string_view JsonBinary::getObjectKey(size_t index) const |
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.
Since JsonBinary
already use StringRef
to represent the string reference, and there is no significant difference between StringRef
and string_view
, why not use StringRef
here?
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.
ok, used StringRef
instead.
offsets_to, | ||
vec_null_map); | ||
} | ||
else if (path_col->isColumnConst()) |
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.
If json_col
is constant and path_col
is not constant, will doExecuteCommon
handle it correctly?
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.
/run-all-tests |
1 similar comment
/run-all-tests |
/run-all-tests |
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.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: windtalker, yibin87 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
What problem does this PR solve?
Issue Number: close #8490
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note