-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat(eap-items): drop attributes_array JSON column from distributed tables #8236
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
onewland
wants to merge
2
commits into
master
Choose a base branch
from
oliver/drop-attributes-array-json-dist-only
base: master
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.
+69
−0
Open
Changes from all commits
Commits
Show all changes
2 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
69 changes: 69 additions & 0 deletions
69
...a/snuba_migrations/events_analytics_platform/0062_drop_attributes_array_json_from_dist.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,69 @@ | ||
| from snuba.clickhouse.columns import JSON, Column | ||
| 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, SqlOperation | ||
| from snuba.snuba_migrations.events_analytics_platform.templates import SAMPLING_WEIGHTS | ||
|
|
||
| storage_set = StorageSetKey.EVENTS_ANALYTICS_PLATFORM | ||
| ro_storage_set = StorageSetKey.EVENTS_ANALYTICS_PLATFORM_RO | ||
|
|
||
| column_name = "attributes_array" | ||
| after = "attributes_float_39" | ||
|
|
||
| # Column definition as added by migration 0050, needed to re-add the column | ||
| # on rollback. | ||
| attributes_array_column = Column( | ||
| column_name, | ||
| JSON( | ||
| max_dynamic_paths=128, | ||
| modifiers=Modifiers(codecs=["ZSTD(1)"]), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def _tables() -> list[tuple[StorageSetKey, str]]: | ||
| tables: list[tuple[StorageSetKey, str]] = [(storage_set, "eap_items_1_dist")] | ||
| for w in SAMPLING_WEIGHTS: | ||
| tables.append((storage_set, f"eap_items_1_downsample_{w}_dist")) | ||
| tables.append((ro_storage_set, "eap_items_1_dist_ro")) | ||
| for w in SAMPLING_WEIGHTS: | ||
| tables.append((ro_storage_set, f"eap_items_1_downsample_{w}_dist_ro")) | ||
| return tables | ||
|
|
||
|
|
||
| class Migration(migration.ClickhouseNodeMigration): | ||
| """Drop the `attributes_array` JSON column (added by migration 0050) from | ||
| the distributed eap_items tables. | ||
|
|
||
| The column was replaced by the typed attributes_array_{string,int,float,bool} | ||
| map columns from migration 0059 and is no longer read. Local tables keep the | ||
| column: dropping it from MergeTree tables would trigger a full part rewrite | ||
| even though the column holds only default values. No materialized view | ||
| projects this column, so no view regeneration is needed. | ||
| """ | ||
|
|
||
| blocking = False | ||
|
|
||
| def forwards_ops(self) -> list[SqlOperation]: | ||
| return [ | ||
| operations.DropColumn( | ||
| storage_set=ss, | ||
| table_name=table, | ||
| column_name=column_name, | ||
| target=OperationTarget.DISTRIBUTED, | ||
| ) | ||
| for (ss, table) in _tables() | ||
| ] | ||
|
|
||
| def backwards_ops(self) -> list[SqlOperation]: | ||
| return [ | ||
| operations.AddColumn( | ||
| storage_set=ss, | ||
| table_name=table, | ||
| column=attributes_array_column, | ||
| after=after, | ||
| target=OperationTarget.DISTRIBUTED, | ||
| ) | ||
| for (ss, table) in reversed(_tables()) | ||
| ] | ||
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.
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.
Let's not add the column back in case we need to go backwards.