Hey Calcites,
I'm working on embedding Calcite into Druid (http://druid.io/,
https://github.com/druid-io/druid/pull/3682) and am running into a problem
that is making me wonder if the approach I'm using makes sense.
Consider the expression EXTRACT(YEAR FROM __time). Calcite has a standard
convertlet rule "convertExtract" that changes this into some arithmetic on
__time casted to an int type. But Druid has some builtin functions to do
this, and I'd rather use those than arithmetic (for a bunch of reasons).
Ideally, in my RelOptRules that convert Calcite rels to Druid queries, I'd
see the EXTRACT as a normal RexCall with the time flag and an expression to
apply it to. That's a lot easier to translate than the arithmetic stuff,
which I'd have to pattern match and undo first before translating.
So the problem I have is that I want to disable convertExtract, but I don't
see a way to do that or to swap out the convertlet table.
The code I'm using to set up a connection is:
public CalciteConnection createCalciteConnection(
final DruidSchema druidSchema
) throws SQLException
{
final Properties props = new Properties();
props.setProperty("caseSensitive", "true");
props.setProperty("unquotedCasing", "UNCHANGED");
final Connection connection =
DriverManager.getConnection("jdbc:calcite:", props);
final CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
calciteConnection.getRootSchema().setCacheEnabled(false);
calciteConnection.getRootSchema().add(DRUID_SCHEMA_NAME, druidSchema);
return calciteConnection;
}
This CalciteConnection is then used by the Druid HTTP server to offer a SQL
API.
Is there some way to swap out the convertlet table that I'm missing?
Also, just in general, am I going about this the right way? Is using the
JDBC driver the right way to embed Calcite? Or should I be calling into it
at some lower level?
Thanks!
Gian