Skip to content
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

Add array index number to output when casting from json to array. #7397

Closed
wants to merge 2 commits into from

Conversation

dnwpark
Copy link
Contributor

@dnwpark dnwpark commented May 24, 2024

Given the query SELECT <array<int64>>to_json('[1, 2, "asdf"]'), produces the error:

InvalidValueError: while casting 'std::json' to 'array<std::int64>', in array elements, at index 2, expected JSON number or null; got JSON string

@dnwpark
Copy link
Contributor Author

dnwpark commented May 24, 2024

Adding error_message_context in fini_expression is super dubious imo

@dnwpark dnwpark requested a review from msullivan May 24, 2024 22:32
@msullivan
Copy link
Member

Adding error_message_context in fini_expression is super dubious imo

Why is that necessary?

@dnwpark
Copy link
Contributor Author

dnwpark commented May 30, 2024

In _compile_call_args there is a check to ensure that all args have a known multiplicity. The multiplicity is added in fini_expression. I suppose the other alternative is to add an override to infer_multiplicity on TypeCast.

@msullivan
Copy link
Member

msullivan commented May 30, 2024 via email

@dnwpark dnwpark force-pushed the error-json-to-array-index branch from 06e32b7 to 7377855 Compare May 31, 2024 14:54
@dnwpark
Copy link
Contributor Author

dnwpark commented Jun 4, 2024

Benchmarking against three queries:

Simple null - 10000 times

client.query(
    "SELECT <array<int64>>to_json(<str>$input)",
    input='[null]'
)
  • master: 8.927s
  • With array indexes: 13.453s

Long array - 1000 times

client.query(
    "SELECT <array<int64>>to_json(<str>$input)",
    input='['+','.join(str(i) for i in range(1000))+',null'+']'
)
  • master: 4.647s
  • With array indexes: 10.134s

Long and deep array - 1000 times

client.query(
    "SELECT <array<tuple<array<tuple<array<int64>>>>>>to_json(<str>$input)",
    input='['+','.join('[[[[1,2,3],[4,5,6],[7,8,9]]]]' for i in range(1000))+',[[[[1,2,null]]]]'+']'
)
  • master: 9.406s
  • With array indexes: 90.841s

@dnwpark
Copy link
Contributor Author

dnwpark commented Jun 4, 2024

@msullivan non-trivial cases seem convincingly much slower.

@dnwpark dnwpark closed this Jun 4, 2024
@msullivan
Copy link
Member

Great work experimenting with this, though!

@msullivan msullivan deleted the error-json-to-array-index branch June 5, 2024 02:09
@msullivan
Copy link
Member

Also, we support json arguments directly too

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.

2 participants