-
Notifications
You must be signed in to change notification settings - Fork 669
fix: preserve SETTINGS clause in PrepareBatch after column list #1923
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
Open
polyglotAI-bot
wants to merge
2
commits into
main
Choose a base branch
from
polyglot/fix-preparebatch-settings-clause
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−1
Open
Changes from 1 commit
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package issues | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ClickHouse/clickhouse-go/v2" | ||
| clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" | ||
| ) | ||
|
|
||
| // Test1919 verifies that PrepareBatch preserves an inline SETTINGS clause placed after | ||
| // the column list instead of silently dropping it from the query sent to the server. | ||
| // See https://github.com/ClickHouse/clickhouse-go/issues/1919. | ||
| func Test1919(t *testing.T) { | ||
| testEnv, err := clickhouse_tests.GetTestEnvironment("issues") | ||
| require.NoError(t, err) | ||
|
|
||
| for _, protocol := range []clickhouse.Protocol{clickhouse.Native, clickhouse.HTTP} { | ||
| t.Run(fmt.Sprintf("%v", protocol), func(t *testing.T) { | ||
| conn, err := clickhouse_tests.GetConnection("issues", t, protocol, clickhouse_tests.TestClientDefaultSettings(testEnv), nil, nil) | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { conn.Close() }) | ||
|
|
||
| tableName := fmt.Sprintf("test_1919_%v", protocol) | ||
| require.NoError(t, conn.Exec(context.Background(), fmt.Sprintf(`CREATE TABLE %s | ||
| ( | ||
| col1 UInt64, | ||
| col2 String | ||
| ) | ||
| ENGINE = MergeTree | ||
| ORDER BY col1;`, tableName)), "Create table failed") | ||
| t.Cleanup(func() { | ||
| if err := conn.Exec(context.Background(), fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)); err != nil { | ||
| t.Logf("DROP TABLE %s failed: %v", tableName, err) | ||
| } | ||
| }) | ||
|
|
||
| // A valid SETTINGS clause after the column list must be accepted and the | ||
| // rows inserted. Before the fix the clause was dropped from the normalized | ||
| // query, so this only exercises the happy path staying intact. | ||
| batch, err := conn.PrepareBatch(context.Background(), fmt.Sprintf("INSERT INTO %s (col1, col2) SETTINGS async_insert=0", tableName)) | ||
| require.NoError(t, err, "PrepareBatch with SETTINGS after column list failed") | ||
| for i := range 10 { | ||
| require.NoError(t, batch.Append(uint64(i), "value")) | ||
| } | ||
| require.NoError(t, batch.Send()) | ||
|
|
||
| var count uint64 | ||
| require.NoError(t, conn.QueryRow(context.Background(), fmt.Sprintf("SELECT count() FROM %s", tableName)).Scan(&count)) | ||
| require.Equal(t, uint64(10), count) | ||
|
|
||
| // The SETTINGS clause must actually reach the server: an unknown setting has | ||
| // to surface as an error rather than being silently dropped. Before the fix | ||
| // the clause was stripped, so the insert succeeded and no error was raised. | ||
| send := func(query string) error { | ||
| b, err := conn.PrepareBatch(context.Background(), query) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err = b.Append(uint64(1), "value"); err != nil { | ||
| return err | ||
| } | ||
| return b.Send() | ||
| } | ||
| err = send(fmt.Sprintf("INSERT INTO %s (col1, col2) SETTINGS nonexistent_setting_for_test_1919=1", tableName)) | ||
| require.ErrorContains(t, err, "nonexistent_setting_for_test_1919") | ||
| }) | ||
| } | ||
| } |
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.