clickhouse-connect icon indicating copy to clipboard operation
clickhouse-connect copied to clipboard

FINAL modifier

Open jmerchantmetrics opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. When using replacingMergeTree and some other tables in clickhouse, you need to use the FINAL modifier to dedupe the results that hasn't been garbage collected yet. (ex. SELECT * FROM tbl FINAL WHERE id = 1) is there any way to do this without creating a custom dataset or view?

jmerchantmetrics avatar Aug 10 '24 13:08 jmerchantmetrics

I assume you're talking about within Superset? The main client query methods in clickhouse-connect accept whatever SQL query (including a FINAL modifier) you specify. Note that we don't recommend using the minimal clickhouse-connect SQLAlchemy dialect outside of Superset.

Within Superset I could see setting a flag somehow to always specify a FINAL modifier for ReplacingMergeTree queries. We'll look into that as time and resources permit. And of course, community contributions to either the SQLAlchemy dialect in clickhouse-connect or the Superset ClickHouse Engine Spec are more than welcome.

genzgd avatar Aug 10 '24 22:08 genzgd

I assume you're talking about within Superset? The main client query methods in clickhouse-connect accept whatever SQL query (including a FINAL modifier) you specify. Note that we don't recommend using the minimal clickhouse-connect SQLAlchemy dialect outside of Superset.

Within Superset I could see setting a flag somehow to always specify a FINAL modifier for ReplacingMergeTree queries. We'll look into that as time and resources permit. And of course, community contributions to either the SQLAlchemy dialect in clickhouse-connect or the Superset ClickHouse Engine Spec are more than welcome.

Do you know how i could manually code in the FINAL modifier in to superset, i am using clickhouse-connect in superset and cant seem to figure out how to do it.

jmerchantmetrics avatar Aug 10 '24 22:08 jmerchantmetrics

Unfortunately I'm not aware of any way to pass such a modifier with the current versions of Superset and clickhouse-connect (or with clickhouse-driver and clickhouse-sqlalchemy, for that matter). Others more familiar with Superset might have an idea.

As I mentioned above, we'll look into the necessary code changes to support this in the future, although I can't give any time estimate.

genzgd avatar Aug 11 '24 23:08 genzgd

Is your feature request related to a problem? Please describe. When using replacingMergeTree and some other tables in clickhouse, you need to use the FINAL modifier to dedupe the results that hasn't been garbage collected yet. (ex. SELECT * FROM tbl FINAL WHERE id = 1) is there any way to do this without creating a custom dataset or view?

SETTINGS final=1 for sqlalchemy or execution_options(settings=dict(final=1))

franz101 avatar Aug 12 '24 16:08 franz101

I know this is old but I was able to use the Select.with_hint() method to accomplish this. It has been merged, but not yet released.

Closed by https://github.com/ClickHouse/clickhouse-connect/pull/584

joe-clickhouse avatar Nov 13 '25 22:11 joe-clickhouse