diff --git a/docs/src/main/sphinx/connector/clickhouse.md b/docs/src/main/sphinx/connector/clickhouse.md index f531373da7d16f..e4a667de867c3e 100644 --- a/docs/src/main/sphinx/connector/clickhouse.md +++ b/docs/src/main/sphinx/connector/clickhouse.md @@ -332,6 +332,42 @@ statements, the connector supports the following features: ```{include} alter-schema-limitation.fragment ``` +## Table functions + +The connector provides specific {doc}`table functions ` to +access ClickHouse. + +(clickhouse-query-function)= +### `query(varchar) -> table` + +The `query` function allows you to query the underlying database directly. It +requires syntax native to ClickHouse, because the full query is pushed down and +processed in ClickHouse. This can be useful for accessing native features which +are not available in Trino or for improving query performance in situations +where running a query natively may be faster. + +```{include} query-passthrough-warning.fragment +``` + +As a simple example, query the `example` catalog and select an entire table: + +``` +SELECT + * +FROM + TABLE( + example.system.query( + query => 'SELECT + * + FROM + tpch.nation' + ) + ); +``` + +```{include} query-table-function-ordering.fragment +``` + ## Performance The connector includes a number of performance improvements, detailed in the diff --git a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClientModule.java b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClientModule.java index d6162c64ac0499..a5f8780349039e 100644 --- a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClientModule.java +++ b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClientModule.java @@ -29,10 +29,13 @@ import io.trino.plugin.jdbc.JdbcClient; import io.trino.plugin.jdbc.JdbcMetadataConfig; import io.trino.plugin.jdbc.credential.CredentialProvider; +import io.trino.plugin.jdbc.ptf.Query; +import io.trino.spi.function.table.ConnectorTableFunction; import java.util.Properties; import static com.clickhouse.client.config.ClickHouseClientOption.USE_BINARY_STRING; +import static com.google.inject.multibindings.Multibinder.newSetBinder; import static io.airlift.configuration.ConfigBinder.configBinder; import static io.trino.plugin.clickhouse.ClickHouseClient.DEFAULT_DOMAIN_COMPACTION_THRESHOLD; import static io.trino.plugin.jdbc.JdbcModule.bindSessionPropertiesProvider; @@ -50,6 +53,7 @@ public void configure(Binder binder) bindTablePropertiesProvider(binder, ClickHouseTableProperties.class); configBinder(binder).bindConfigDefaults(JdbcMetadataConfig.class, config -> config.setDomainCompactionThreshold(DEFAULT_DOMAIN_COMPACTION_THRESHOLD)); binder.install(new DecimalModule()); + newSetBinder(binder, ConnectorTableFunction.class).addBinding().toProvider(Query.class).in(Scopes.SINGLETON); } @Provides diff --git a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java index 63efb0a010baa7..0d5992ec755f49 100644 --- a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java +++ b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java @@ -77,7 +77,6 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) SUPPORTS_ARRAY, SUPPORTS_DELETE, SUPPORTS_DROP_NOT_NULL_CONSTRAINT, - SUPPORTS_NATIVE_QUERY, SUPPORTS_NEGATIVE_DATE, SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY, SUPPORTS_ROW_TYPE,