This message was deleted.
# general
s
This message was deleted.
a
try setting
inSubQueryThreshold
to 0 in your query context and see if that helps
g
Actually, I saw that fix. But I also need to parse the query before sending it to Druid using the same calcite parser Druid uses.
a
so its your parser taking time? may I ask why do you need to parse the query? once parsed, does druid get the sql query or the native json query?
g
Yes, the parsing is taking quite some time ~40+ seconds. I need to parse the query because I need to introduce extra where clauses based on permissions. So, I parse the query to create SqlNodes then convert it back to sql and send it to druid.
b
A workaround is to use *MV_OVERLAP*(myCol, ARRAY['myVal1', 'myVal2',...]). Not sure this will work forever, although it should imo. Planner doesn't try a million variations, just sends it on.
g
I tried
MV_CONTAINS
before and that didn’t work. Will Try
MV_OVERLAP
.
Also
Copy code
select l from mytable
INNER JOIN (values ('a'), ('b')  ... <thousands_of_values>)  t(v) on mytable.l = t.v
seems to work.
b
Nice, that's more intuitive, gtk, thank you!
g
you could also use native queries (JSON) which is what SQL plans into, if you end up needing to bypass the SQL parser and planner
g
I was thinking about sending it as json queries but I think I read somewhere that using SQL is the preferred way, as well some optimizations are only available via sql. Plus, the redundant parsing by druid didn’t seem to matter much, at least for small queries.
For some reason when I parse the query it’s a lot slower (40s) than when druid does it (<1s). My code
Copy code
SqlNode parseSql(final String query) throws SqlParseException {
        final SqlParser parser = SqlParser.create(query, SqlParser
        .configBuilder()
        .setCaseSensitive(true)
        .setUnquotedCasing(Casing.UNCHANGED)
        .setQuotedCasing(Casing.UNCHANGED)
        .setQuoting(Quoting.DOUBLE_QUOTE)
        .setConformance(DruidConformance.instance())
        .setParserFactory(new DruidSqlParserImplFactory()) // Custom sql parser factory
        .build(););
        return parser.parseStmt();
    }
seems identical to how druid does it in the CalcitePlanner https://github.com/apache/druid/blob/master/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java#L227
g
yeah, it's true in general SQL is the preferred way
hmm you're saying Druid parses it a lot faster than Calcite does when you embed it in your own app?
Seems odd… do you have the same version of Calcite?
Profiling might be useful to hint at what's going on (yourkit or sjk flame graph)
g
I was missing a RelOptPlanner to optimize queries before doing the parsing. Adding that solved that issue. Thanks!
g
ah ok! neat!