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

Query with JSON_QUERY/JSON_VALUE using parameters across a join fails to be planned #16560

Open
tls-applied opened this issue Jun 5, 2024 · 0 comments

Comments

@tls-applied
Copy link

tls-applied commented Jun 5, 2024

Description

Sample query:

SELECT
  JSON_VALUE(a.data, b.path)
FROM (
    VALUES
      (PARSE_JSON('{"x": 1}'))
  ) a(data)
  CROSS JOIN (
    VALUES
      ('$.x')
  ) b(path)

Relevant errors:

2024-06-05T21:36:40,185 WARN [sql[67983b92-e41d-4933-be2e-a172b0f43148]] org.apache.druid.sql.calcite.planner.QueryHandler - Query not supported. Please check Broker logs for additional details. SQL was: SELECT
  JSON_VALUE(a.data, b.path)
FROM
  (
    VALUES
      (PARSE_JSON('{"x": 1}'))
  ) a(data)
  CROSS JOIN (
    VALUES
      ('$.x')
  ) b(path)
LIMIT 11 (org.apache.calcite.plan.RelOptPlanner$CannotPlanException: There are not enough rules to produce a node with desired properties: convention=DRUID, sort=[].
Missing conversion is LogicalSort[convention: NONE -> DRUID]
There is 1 empty subset: rel#53574:Subset#5.DRUID.[], the relevant part of the original plan is as follows
53572:LogicalSort(fetch=[11])
  53570:LogicalProject(subset=[rel#53571:Subset#4.NONE.[]], EXPR$0=[CAST(JSON_VALUE_VARCHAR($0, $1)):VARCHAR(2000)])
    53568:LogicalJoin(subset=[rel#53569:Subset#3.NONE.[]], condition=[true], joinType=[inner])
      53565:LogicalProject(subset=[rel#53566:Subset#1.NONE.[]], EXPR$0=[PARSE_JSON('{"x": 1}')])
        53537:LogicalValues(subset=[rel#53564:Subset#0.NONE.[0]], tuples=[[{ 0 }]])
      53539:LogicalValues(subset=[rel#53567:Subset#2.NONE.[0]], tuples=[[{ '$.x' }]])

Root: rel#53574:Subset#5.DRUID.[]
Original rel:
LogicalSort(subset=[rel#53574:Subset#5.DRUID.[]], fetch=[11]): rowcount = 1.0, cumulative cost = {1.0 rows, 4.0 cpu, 0.0 io}, id = 53572
  LogicalProject(subset=[rel#53571:Subset#4.NONE.[]], EXPR$0=[CAST(JSON_VALUE_VARCHAR($0, $1)):VARCHAR(2000)]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 53570
    LogicalJoin(subset=[rel#53569:Subset#3.NONE.[]], condition=[true], joinType=[inner]): rowcount = 1.0, cumulative cost = {1.0 rows, 0.0 cpu, 0.0 io}, id = 53568
      LogicalProject(subset=[rel#53566:Subset#1.NONE.[]], EXPR$0=[PARSE_JSON('{"x": 1}')]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 53565
        LogicalValues(subset=[rel#53564:Subset#0.NONE.[0]], tuples=[[{ 0 }]]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 53537
      LogicalValues(subset=[rel#53567:Subset#2.NONE.[0]], tuples=[[{ '$.x' }]]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 53539
)

This query works on a newer version of Druid (29.0.1) so may be expected to fail on the affected version. Is there a way to work around it?

Affected Version

26.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant