-
Notifications
You must be signed in to change notification settings - Fork 65
feat(kernel): send per-statement query tags on the kernel backend #470
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
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 167651ecc67143ef258ad70fd2682ced00beaa99 | ||
| 21504eae074c7f5b11888a4ebcc7468780b2f844 |
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,30 @@ | ||
| package kernel | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
| ) | ||
|
|
||
| // This file is intentionally NOT behind the `cgo && databricks_kernel` build tag: | ||
| // the interior-NUL guard on the serialized query-tags string is pure Go, so it is | ||
| // unit-tested under CGO_ENABLED=0 (see querytags_nul_test.go). The tagged execute | ||
| // path (operation.go) calls checkQueryTags before newCStr(serialized). | ||
|
|
||
| // errQueryTagsNUL rejects a serialized query-tags string containing an interior | ||
| // NUL. The kernel's set_query_tags C ABI takes it as a NUL-terminated C string | ||
| // with no length, so a NUL would silently truncate it — sending fewer/corrupted | ||
| // tags than intended — whereas the Thrift path puts the same tags in | ||
| // confOverlay["query_tags"] and transmits them whole. This is the query-tags | ||
| // counterpart to errQueryNUL (sqltext.go) and errParamNUL (bindparams.go), which | ||
| // guard SQL text and bound values for the identical reason. Fail loudly rather | ||
| // than diverge from Thrift. | ||
| var errQueryTagsNUL = errors.New("query tags contain a NUL byte, which the kernel set_query_tags ABI cannot carry") | ||
|
|
||
| // checkQueryTags validates the serialized query-tags string before the cgo layer | ||
| // C-string-marshals it. Returns errQueryTagsNUL when it contains an interior NUL. | ||
| func checkQueryTags(serialized string) error { | ||
| if strings.IndexByte(serialized, 0) >= 0 { | ||
| return errQueryTagsNUL | ||
| } | ||
| return nil | ||
| } |
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,27 @@ | ||
| package kernel | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
| ) | ||
|
|
||
| // checkQueryTags must reject a serialized query-tags string with an interior NUL | ||
| // (the kernel's set_query_tags ABI would truncate it, sending fewer tags than | ||
| // Thrift) but accept ordinary serialized tags and an empty string. Runs under | ||
| // CGO_ENABLED=0. | ||
| func TestCheckQueryTags(t *testing.T) { | ||
| if err := checkQueryTags("team:eng,job:etl,production"); err != nil { | ||
| t.Errorf("plain tags: got %v, want nil", err) | ||
| } | ||
| if err := checkQueryTags(""); err != nil { | ||
| t.Errorf("empty: got %v, want nil", err) | ||
| } | ||
| // NUL inside a value (querytags.Serialize escapes only \\, :, and , — never NUL). | ||
| if err := checkQueryTags("team:e\x00ng"); !errors.Is(err, errQueryTagsNUL) { | ||
| t.Errorf("NUL in value: got %v, want errQueryTagsNUL", err) | ||
| } | ||
| // NUL inside a key must be caught too. | ||
| if err := checkQueryTags("te\x00am:eng"); !errors.Is(err, errQueryTagsNUL) { | ||
| t.Errorf("NUL in key: got %v, want errQueryTagsNUL", err) | ||
| } | ||
| } |
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.