-
Notifications
You must be signed in to change notification settings - Fork 762
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
Issue while casting to BIGINT #17388
Comments
you can use cast will throw errors if it fails to cast.
|
If the payload contains "null" (as a string), CAST("null" AS BIGINT) will fail. But if the payload contains a true NULL value, CAST(NULL AS BIGINT) should work without issue. So yes, TRY_CAST is a workaround for handling string "null" gracefully, but NULL::BIGINT should already work correctly if the value is truly NULL. |
We can modify this cast function to support casting a json |
Thanks @b41sh |
@BohuTANG @b41sh One more issue to add ON. Please find the summary of it, summaryExecute the below queries, Create table: Expected Behavior: When running the below query, the record should be returned because test1 is SQL NULL, not the string "null": Another one thing was that when i execute the below query, i get the record but actually when inserting it was SQL null not string null. However, the expected result is not being achieved. Please look into this issue. |
Hi @Shanmugavel-J thanks for your report.
I'm not sure I fully understand what you mean, please let me know if I'm wrong. |
@b41sh Thanks for you response. as you had mentioned that is correct. My bad.. Please find another issue mentioned below, Create query:
Execute the select query: Output:
Ideally the first one should be varchar since the value is "null". The another one which i had posted wasAnother one thing was that when i execute the below query, i get the record but actually when inserting it was SQL null ( Create query:
Select Query: SELECT * FROM TEST WHERE payload:test1 = 'null'; Output:
Ideally in the above result, the Second record shouldn't come because it is variant NULL. the first one should come because it meets the condition string null. |
@Shanmugavel-J Thanks for the reply. For the first issue, the root@0.0.0.0:48000/default> SELECT JSON_TYPEOF(payload:key4), payload:key4 FROM TEST;
┌───────────────────────────────────────────────┐
│ json_typeof(payload:key4) │ payload:key4 │
│ Nullable(String) │ Nullable(Variant) │
├───────────────────────────┼───────────────────┤
│ NULL │ NULL │
│ null │ null │
│ string │ "null" │
└───────────────────────────────────────────────┘
3 rows read in 0.032 sec. Processed 3 rows, 289 B (93.75 rows/s, 8.82 KiB/s) Note that snowflake's For the second issue, it looks like that the example SQL is not correct, because the root@0.0.0.0:48000/default> SELECT * FROM TEST WHERE payload:key4 = 'null';
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ payload │ ts │
│ Nullable(Variant) │ Nullable(Int32) │
├──────────────────────────────────────────────────────────────────────┼─────────────────┤
│ {"key3":"value3","key4":"null","key5":"null","key6":{"test":"test"}} │ NULL │
└────────────────────────────────────────────────────────────────────────────────────────┘
1 row read in 0.037 sec. Processed 3 row, 304 B (81.08 rows/s, 8.02 KiB/s) |
@b41sh Sorry my mistake while pasting. it is I could see two records in my case with the below databend version, |
yes, it will be fixed after PR #17412 merged. |
Summary
Issue: When casting null value from payload(
variant datatype
) it throws error.Execute the below queries,
Create table:
CREATE TABLE TEST(payload variant);
Insert records:
INSERT INTO TEST(payload) VALUES ('{"test":"value","test1":null, "test2": "null", "obj": {"test":"tes"}}');
When executing the below select query it should ideally cast it to NULL,
Select Query:
SELECT payload:test1::BIGINT FROM TEST;
Error i get is
But the below select query get succeded,
Select query:
SELECT null::BIGINT;
The only difference is that when null value comes from payload it fails but when coming from column it passes.
The text was updated successfully, but these errors were encountered: