The HintStrategyTable can be defined in your adapter code for eg see
https://github.com/twilio/calcite-kudu/blob/84c13e80f7cff83f3acaf5be4fc312c977e18ee8/adapter/src/main/java/com/twilio/kudu/sql/KuduQuery.java#L88

-Thomas

On Fri, Oct 7, 2022 at 11:40 AM <[email protected]> wrote:

> Hello
>
> I'm developing an adapter for my custom data source. My adapter uses hints
> to tailor query calls to my underlying data source. Did I understand it
> correctly that hints have to be defined "outside" of an adapter, i.e., at
> the location where the connection is defined?
>
> I'm currently wrapping a JDBC connection with a hook for hint strategies.
> Is that the correct way to do that? It looks quite odd and wrong,
> especially since hooks should only be used for debugging and testing
> according to the documentation. I would rather expect hint strategies to be
> defined in my adapter directly (or the model.json or as a property along
> with the connection).
>
> Thanks for your help!
>
> try (Hook.Closeable closeable =
> Hook.SQL2REL_CONVERTER_CONFIG_BUILDER.addThread((Holder<SqlToRelConverter.Config>
> configHolder) -> {
>     HintStrategyTable strategies = HintStrategyTable.builder()
>             .hintStrategy("index", (hint, rel) -> true)
>             .build();
>     configHolder.accept(config ->
> config.withHintStrategyTable(strategies));
> })) {
>     String sql = """
>             SELECT *
>             FROM test /*+ index(A) */""";
>
>     final Properties info = new Properties();
>     info.put("model",
> requireNonNull(getClass().getResource("/model.json")).getPath());
>
>     final Connection connection =
> DriverManager.getConnection("jdbc:calcite:", info);
>
>     final Statement statement = connection.createStatement();
>     final ResultSet rs = statement.executeQuery(sql);
>
>     ...
> }
>
>

Reply via email to