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

[Bug] Doris 2.1 throws an exception when parsing a case-when statement using the json_parse function #34579

Open
2 of 3 tasks
gugoen opened this issue May 9, 2024 · 0 comments

Comments

@gugoen
Copy link

gugoen commented May 9, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Version

2.1

What's Wrong?

After updating from 2.0 to 2.1, I found that using a normal SQL statement would result in an error. I simplified the error logic in one SQL statement, and the main issue with the error is that using json_parse in a case when statement would throw an exception.

The following SQL (Case-1):

with a as (
  select '101' id, 'a' as v_key, '{"k":"k1","v":"v1"}' v_json union all
  select '101' id, 'a' as v_key, '{"k":"k2","v":"v2"}' v_json union all
  select '101' id, 'b' as v_key, '{"k":"k3","v":"v3"}' v_json union all
  select '101' id, 'c' as v_key, '{"k":"k4","v":"v4"}' v_json union all
  select '102' id, 'a' as v_key, '{"k":"k5","v":"v5"}' v_json
)
SELECT id,
    CASE v_key WHEN 'a' THEN JSON_PARSE_ERROR_TO_NULL( CONCAT( '[', CONCAT_WS( ',', SPLIT_BY_STRING( v_json, '|+|' )), ']' )) ELSE NULL END AS a,
    CASE v_key WHEN 'b' THEN JSON_PARSE_ERROR_TO_NULL( CONCAT( '[', CONCAT_WS( ',', SPLIT_BY_STRING( v_json, '|+|' )), ']' )) ELSE NULL END AS b
FROM a
;

Throw exception:

> 1105 - errCode = 2, detailMessage = (172.16.128.95)[INTERNAL_ERROR]Function if get failed, expr is VectorizedFnCall[if](arguments=VectorizedFnCall[eq](arguments=String, String,return=UInt8), VectorizedFnCall[jsonb_parse_error_to_null](arguments=VectorizedFnCall[concat](arguments=String, VectorizedFnCall[concat_ws](arguments=String, VectorizedFnCall[split_by_string](arguments=String, String,return=Array(Nullable(String))),return=String), String,return=String),return=Nullable(JSONB)), Nullable(JSONB),return=Nullabl

You can remove the CONCAT statement and simplify it as follows (Case-2):

with a as (
  select '101' id, 'a' as v_key, '{"k":"k1","v":"v1"}' v_json union all
  select '101' id, 'a' as v_key, '{"k":"k2","v":"v2"}' v_json union all
  select '101' id, 'b' as v_key, '{"k":"k3","v":"v3"}' v_json union all
  select '101' id, 'c' as v_key, '{"k":"k4","v":"v4"}' v_json union all
  select '102' id, 'a' as v_key, '{"k":"k5","v":"v5"}' v_json
)
SELECT id,
    CASE v_key WHEN 'a' THEN JSON_PARSE(v_json) ELSE NULL END AS a,
    CASE v_key WHEN 'b' THEN JSON_PARSE(v_json) ELSE NULL END AS b
FROM a
;

Still throwing exceptions:

> 1105 - errCode = 2, detailMessage = (172.16.128.97)[INTERNAL_ERROR]Function if get failed, expr is VectorizedFnCall[if](arguments=VectorizedFnCall[eq](arguments=String, String,return=UInt8), VectorizedFnCall[jsonb_parse](arguments=String,return=JSONB), Nullable(JSONB),return=Nullable(Decimal(27, 9))) and return type is Nullable(Decimal(27, 9)).

The same SQL can run normally in 2.0, and the output of case-1 is as follows:

+-----+-----------------------+-----------------------+
| id  | a                     | b                     |
+-----+-----------------------+-----------------------+
| 101 | [{"k":"k1","v":"v1"}] | NULL                  |
| 101 | [{"k":"k2","v":"v2"}] | NULL                  |
| 101 | NULL                  | [{"k":"k3","v":"v3"}] |
| 101 | NULL                  | NULL                  |
| 102 | [{"k":"k5","v":"v5"}] | NULL                  |
+-----+-----------------------+-----------------------+
5 rows in set (0.11 sec)

What You Expected?

Solve it

How to Reproduce?

No response

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

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

No branches or pull requests

1 participant