Repository navigation
fix: Use zstd for bool and int attributes #8578
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
63 changes: 63 additions & 0 deletions
63
snuba/snuba_migrations/events_analytics_platform/0073_items_bool_int_codecs.py
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,63 @@ | ||
| """Add ZSTD(1) to the attributes_bool and attributes_int map columns. | ||
|
|
||
| These are the only two attribute map families without an explicit codec: 0024 | ||
| gave attributes_string_* and attributes_float_* ZSTD(1) (copied from | ||
| eap_spans), but bool and int were new column kinds with no precedent and fell | ||
| back to the LZ4 default. | ||
| """ | ||
|
|
||
| from snuba.clickhouse.columns import Bool, Column, Int, Map, String | ||
| from snuba.clusters.storage_sets import StorageSetKey | ||
| from snuba.migrations import migration, operations | ||
| from snuba.migrations.columns import MigrationModifiers as Modifiers | ||
| from snuba.migrations.operations import OperationTarget | ||
|
|
||
| storage_set = StorageSetKey.EVENTS_ANALYTICS_PLATFORM | ||
|
|
||
| local_tables = [ | ||
| "eap_items_1_local", | ||
| "eap_items_1_downsample_8_local", | ||
| "eap_items_1_downsample_64_local", | ||
| "eap_items_1_downsample_512_local", | ||
| "eap_items_2_local", | ||
| "eap_items_2_downsample_8_local", | ||
| "eap_items_2_downsample_64_local", | ||
| "eap_items_2_downsample_512_local", | ||
| ] | ||
|
|
||
|
|
||
| def _columns(codecs: list[str] | None) -> list[Column[Modifiers]]: | ||
| modifiers = Modifiers(codecs=codecs) if codecs else None | ||
| return [ | ||
| Column("attributes_bool", Map(String(), Bool(), modifiers=modifiers)), | ||
| Column("attributes_int", Map(String(), Int(64), modifiers=modifiers)), | ||
| ] | ||
|
|
||
|
|
||
| class Migration(migration.ClickhouseNodeMigration): | ||
| blocking = False | ||
|
|
||
| def forwards_ops(self) -> list[operations.SqlOperation]: | ||
| return [ | ||
| operations.ModifyColumn( | ||
| storage_set=storage_set, | ||
| table_name=table, | ||
| column=column, | ||
| target=OperationTarget.LOCAL, | ||
| ) | ||
| for table in local_tables | ||
| for column in _columns(["ZSTD(1)"]) | ||
| ] | ||
|
|
||
| def backwards_ops(self) -> list[operations.SqlOperation]: | ||
| return [ | ||
| operations.ModifyColumn( | ||
| storage_set=storage_set, | ||
| table_name=table, | ||
| column=column, | ||
| target=OperationTarget.LOCAL, | ||
| ) | ||
| for table in local_tables | ||
| # REMOVE CODEC not supported, so rollback declares LZ4 explicitly | ||
| for column in _columns(["LZ4"]) | ||
| ] | ||
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.