Union Query with Join throws error
- Dominant language
- Java
- Stars
- 14.1k
- Forks
- 3.8k
- Avg merge
- 2d 58m
- Merged PRs (30d)
- 233
Description
Have been trying to use a right join query with unioned datasource to achieve sort of null filling since timeseries have limited support for returning empty buckets (like it just fills missing buckets within segment's actual min and max time not the query min and max times) but it fails.
### Affected Version
29.0.1
### Description
```
SELECT "t2"."hour", "t1"."Count" FROM (
(SELECT TIME_FLOOR("__time", 'PT1H') AS "hour",
COUNT(*) AS "Count"
FROM "inline_data_day" GROUP BY 1) "t1"
RIGHT JOIN (
SELECT CAST('2023-10-10T00:00:00.000Z' as TIMESTAMP) as "hour"
UNION ALL
SELECT CAST('2023-10-10T01:00:00.000Z' AS TIMESTAMP) as "hour"
UNION ALL
SELECT CAST('2023-10-10T02:00:00.000Z' AS TIMESTAMP) as "hour"
) "t2"
ON "t1"."hour"="t2"."hour"
)
```
This fails with
```
Query could not be planned. A possible reason is [SQL requires union with input of a datasource type that is not supported. Union operation is only supported between regular tables. ]
```
inline_data_day is just
```
__time v count
2023-10-10T00:00:00.000Z a 1
2023-10-10T02:00:00.000Z b 2
2023-10-11T00:00:00.000Z a 1
2023-10-11T02:00:00.000Z b 2
```
Contributor guide
Research direction
Start by reproducing the provided RIGHT JOIN and UNION ALL query against Apache Druid 29.0.1, then trace the planner path that emits the unsupported datasource-type error. Done means the query can be planned and executed with the unioned datasource, including the demonstrated null-filling time buckets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100