Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of SETTINGS ClickHouse clause #803

Conversation

martijnthe
Copy link

@martijnthe martijnthe commented May 14, 2024

Summary

Clickhouse SQL has an optional SETTINGS clause with SELECTs which can be used to configure all kinds of options.

This PR adds a settings method to ClickHouseQueryBuilder to add these options to a SELECT query.

All current (Clickhouse 24.4) settings keys are snake-case. Therefore I opted to use the settings keys directly as kwargs to the settings method, allowing passing multiple settings pairs in one call in a Pythonic/ideomatic way.

Test Plan

Added a unit test to exercise the new function.

 ### Summary

Clickhouse SQL has an optional [`SETTINGS` clause](settings-clause) with
`SELECT`s which can be used to configure [all kinds of options](settings).

This PR adds a `settings` method to `ClickHouseQueryBuilder` to add these
options to a `SELECT` query.

All current (Clickhouse 24.4) settings keys are snake-case. Therefore I opted
to use the settings keys directly as kwargs to the `settings` method, allowing
passing multiple settings pairs in one call in a Pythonic/ideomatic way.

[settings-clause]: https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query
[settings]: https://clickhouse.com/docs/en/operations/settings/settings

 ### Test Plan

Added a unit test to exercise the new function.
@martijnthe martijnthe requested a review from a team as a code owner May 14, 2024 13:32
@martijnthe
Copy link
Author

cc @AzisK -- tagging you because you reviewed a very similar PR (#707). Thanks for looking!

@AzisK
Copy link

AzisK commented Jan 14, 2025

Hi @martijnthe. Did you close because you lost hope someone will review? I am sorry about it. I can find the time on the weekend to review

Copy link

@AzisK AzisK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me

@martijnthe
Copy link
Author

I also closed it because there's a problem with the implementation:

  • SETTINGS must come between LIMIT and UNION, not right after the FROM part of a SELECT.
  • Other statement kinds (i.e. INSERT) can also take SETTINGS, but it goes in a different place.

I didn't see a clean way to implement it w/o touching the base QueryBuilder class too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants