druid icon indicating copy to clipboard operation
druid copied to clipboard

Join queries with order by clause doesn't work

Open 7Luma opened this issue 2 years ago • 6 comments

Hi! Join queries with order by clause doesn't work

Affected Version

0.23.0, 0.24.0

Description

Queries like (with join and order by clause):

SELECT "T1"."__time"
FROM "SomeTableA" AS "T1"
JOIN "SomeTableB" AS "T2"
ON "T1"."A" = "T2"."B"
ORDER BY "T1"."__time" ASC

Doesn't work at 0.23.0 and 0.24.0 versions of Druid (but works at 0.22.0). "Doesn't work" means that query processing ends with exception on broker node:

Error: Unknown exception
Cannot convert query parts into an actual query
org.apache.druid.sql.calcite.rel.CannotBuildQueryException

More detailed log here: broker.log

7Luma avatar Sep 30 '22 17:09 7Luma

@gianm Can you please share you thoughts on this issue? Or maybe some info/details is missing? It's looks like a significant bug.

JLuma avatar Oct 05 '22 15:10 JLuma

We haven't had a chance to write a unit test demonstrating this problem yet. If you have one you could share, that would certainly accelerate the process, and would be very appreciated! It would go in CalciteJoinQueryTest. If not, that's ok, we will come around to do it on our own.

gianm avatar Oct 06 '22 02:10 gianm

I think https://github.com/apache/druid/pull/12418 caused it. @somu-imply FYI.

abhishekagarwal87 avatar Oct 06 '22 10:10 abhishekagarwal87

I'll add the unit test. Seems like #13173 fixes this. The query under consideration is

select t1.__time 
from foo as t1
JOIN numFoo as t2
on t1.dim2 = t2.dim2
order by t1.__time ASC

I'll update the unit test case with this query

somu-imply avatar Oct 06 '22 17:10 somu-imply

Thanks for looking into it @somu-imply!

gianm avatar Oct 06 '22 19:10 gianm

The test case has been added through #13173

somu-imply avatar Oct 06 '22 23:10 somu-imply