Skip to content

Add json->sql deserialisation and execution.#6919

Merged
Mytherin merged 16 commits intoduckdb:masterfrom
Maxxen:core/json-deserialization
Apr 7, 2023
Merged

Add json->sql deserialisation and execution.#6919
Mytherin merged 16 commits intoduckdb:masterfrom
Maxxen:core/json-deserialization

Conversation

@Maxxen
Copy link
Member

@Maxxen Maxxen commented Mar 30, 2023

This is a continuation of #6647 and adds three new functions:

  • json_deserialize_sql(JSON): convert a json serialized sql select statement back into an (equivalent) sql statement string.
  • json_execute_serialized_sql(JSON): execute a json serialized sql select statement directly as a table function - basically as if it were a subquery.
  • PRAGMA json_execute_serialized_sql(VARCHAR): execute a json serialized sql select statement as if it were a top level statement through a pragma instead. Basically deserialises the given json back into a sql string which is then executed normally.

I have tested this by hacking in a json ser/de roundtrip in the DeserializedStatementVerifier, and it passes the entire duckdb unit test suite, so I am reasonably confident that this implementation is correct and serializes e.g. all the types, expressions and values correctly, but I will add a proper deserialization/serialization verification pass when I add the binary FormatDe/Serializer in core duckdb.

@Maxxen Maxxen requested a review from Mytherin March 31, 2023 09:52
Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good. Some minor comments below.

@Maxxen Maxxen requested a review from Mytherin April 6, 2023 21:08
@Maxxen
Copy link
Member Author

Maxxen commented Apr 7, 2023

yo-yo @Mytherin

@Mytherin Mytherin merged commit fa2d0f5 into duckdb:master Apr 7, 2023
@Mytherin
Copy link
Collaborator

Mytherin commented Apr 7, 2023

Thanks! LGTM. Next up replacing the existing (de)serialize methods nad unifying all the (de)serialize infrastructure :)

void JsonDeserializer::ThrowTypeError(yyjson_val *val, const char *expected) {
auto actual = yyjson_get_type_desc(val);
auto &parent = Current();
if (yyjson_is_obj(parent.val)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two branches don't throw anything, and the string msg is discarded right away. Is that a bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, nice catch! I've pushed a fix in #8291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants