Gustavo de Morais created FLINK-40233:
-----------------------------------------
Summary: JSON functions return NULL when sharing a parsed input
Key: FLINK-40233
URL: https://issues.apache.org/jira/browse/FLINK-40233
Project: Flink
Issue Type: Bug
Components: Table SQL / API
Affects Versions: 2.3.0
Reporter: Gustavo de Morais
Assignee: Gustavo de Morais
When two JSON functions share the same input in one query, the second call can
wrongly return NULL.
The parse result is cached and reused to avoid re-parsing the same input. But
if an earlier JSON call short-circuits and returns NULL before parsing (for
example a NULL path argument), the cache is marked as populated while the parse
never actually ran. The second function then reuses an empty parse result and
returns NULL.
{code:java}
SELECT json_value(v, cast(null as string)), json_length(v)
FROM (values('{"a":1, "b":2}')) AS t(v);
-- returns (NULL, NULL), expected (NULL, 2)
SELECT json_value(v, cast(null as string)), json_value(v, '$.a')
FROM (values('{"a":1, "b":2}')) AS t(v);
-- returns (NULL, NULL), expected (NULL, 1)
SELECT json_value(v, cast(null as string)), json_query(v, '$.a')
FROM (values('{"a":{"b":1}, "b":2}')) AS t(v);
-- returns (NULL, NULL), expected (NULL, {"b":1}) {code}
The reusable-parse tracking in {{CodeGeneratorContext}} records the input as
already parsed even though the first call exited before parsing it.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)