-
Notifications
You must be signed in to change notification settings - Fork 121
Make Elementary work with ClickHouse cluster mode #878
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8db4bcf
Add cluster and exchange capabilities to temp relation creation
StevenReitsma 9519574
Use ClickHouse query settings in delete_and_insert
StevenReitsma f43acef
Use ClickHouse query settings in insert_rows
StevenReitsma 0abcdc4
Fix get_query_settings SQL macro syntax
StevenReitsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| {% macro get_query_settings() %} | ||
| {% do return(adapter.dispatch("get_query_settings", "elementary")()) %} | ||
| {% endmacro %} | ||
|
|
||
| {% macro default__get_query_settings() %} | ||
| {% do return("") %} | ||
| {% endmacro %} | ||
|
|
||
| {% macro clickhouse__get_query_settings() %} | ||
| {% do return(adapter.get_model_query_settings(model)) %} | ||
| {% endmacro %} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Two issues here:
Inconsistent pattern: This file directly calls
adapter.get_model_query_settings(model)whileinsert_rows.sqluses the dispatch macroelementary.get_query_settings(). Both target the same goal (injecting ClickHouse SETTINGS) but through different mechanisms. Standardize on one approach—the dispatch pattern is preferable for extensibility.SQL syntax concern (line 72): The insert query places the SETTINGS clause between
INSERT INTOandSELECT:ClickHouse typically expects
SETTINGSat the very end of the query. Verify this syntax is valid for ClickHouseINSERT...SELECT...SETTINGSstatements. If not, move the SETTINGS clause to the end of the query.Also applies to: 72-72
I'll verify the concerns in this review comment by examining the actual files and checking ClickHouse syntax.
🏁 Script executed:
Length of output: 414
🌐 Web query:
💡 Result:
Put the SETTINGS clause immediately after the table name and optional column list (i.e., before VALUES, FORMAT, or SELECT).
You can also set query-level options inside the SELECT itself using its own SETTINGS clause. [1][2]
Sources:
[1] ClickHouse INSERT INTO statement (syntax and note about SETTINGS placement).
[2] ClickHouse SELECT — SETTINGS in SELECT queries.
Let me correct the shell script and inspect both files:
🏁 Script executed:
Length of output: 11002
Let me examine the macro implementations to verify if the inconsistency claim is valid and check the dispatch patterns:
🏁 Script executed:
Length of output: 2290
Standardize on dispatch macro pattern for query settings.
This file directly calls
adapter.get_model_query_settings(model)(lines 65, 72) whileinsert_rows.sqluses the dispatch macroelementary.get_query_settings(). Both target the same goal for ClickHouse, but the dispatch pattern (used ininsert_rows.sql) is preferable—it provides adapter-agnostic abstraction and returns an empty string for non-ClickHouse adapters, while direct calls may fail on unsupported adapters.Replace
adapter.get_model_query_settings(model)withelementary.get_query_settings()to match the pattern used elsewhere in the codebase.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see this as an issue since this code is already in ClickHouse-adapter specific code. But can change if wanted from a human reviewer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StevenReitsma You're absolutely right! I apologize for the overly prescriptive suggestion.
The key distinction is that your code is in the
clickhouse__get_delete_and_insert_queriesmacro, which is already adapter-specific. In adapter-specific macros, directly calling adapter methods likeadapter.get_model_query_settings(model)is perfectly reasonable and arguably more direct.The dispatch pattern (
elementary.get_query_settings()) is most valuable in generic/cross-adapter code where you need a single implementation to work across multiple database types. Ininsert_rows.sql, the dispatch is used in the baseget_insert_rows_queriesmacro (not an adapter override), which is why the pattern makes sense there.Your current approach is clean and appropriate for adapter-specific code. No changes needed here! 👍