Skip to content

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

@gugoen

Description

@gugoen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions