-
-
Notifications
You must be signed in to change notification settings - Fork 61
feat(eap): Add timestamp_ns column to eap_items_1 table #7671
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
base: master
Are you sure you want to change the base?
Conversation
Add a new UInt16 column `timestamp_ns` to the eap_items_1 table for storing sub-second timestamp precision. The column is added after the existing `timestamp` column and included in the sort key. Co-Authored-By: Claude <noreply@anthropic.com>
|
This PR has a migration; here is the generated SQL for -- start migrations
-- forward migration events_analytics_platform : 0052_add_timestamp_ns_column
Local op:
ALTER TABLE eap_items_1_local
ADD COLUMN IF NOT EXISTS timestamp_ns UInt16 AFTER timestamp,
MODIFY ORDER BY (organization_id, project_id, item_type, timestamp, timestamp_ns, trace_id, item_id)
Distributed op: ALTER TABLE eap_items_1_dist ON CLUSTER 'cluster_one_sh' ADD COLUMN IF NOT EXISTS timestamp_ns UInt16 AFTER timestamp;
-- end forward migration events_analytics_platform : 0052_add_timestamp_ns_column
-- backward migration events_analytics_platform : 0052_add_timestamp_ns_column
-- end backward migration events_analytics_platform : 0052_add_timestamp_ns_column |
snuba/snuba_migrations/events_analytics_platform/0052_add_timestamp_ns_column.py
Outdated
Show resolved
Hide resolved
| operations.DropColumn( | ||
| storage_set=self.storage_set_key, | ||
| table_name=self.dist_table_name, | ||
| column_name="timestamp_ns", | ||
| target=OperationTarget.DISTRIBUTED, | ||
| ), | ||
| operations.RunSql( | ||
| storage_set=self.storage_set_key, | ||
| statement=f""" | ||
| ALTER TABLE {self.local_table_name} | ||
| MODIFY ORDER BY (organization_id, project_id, item_type, timestamp, trace_id, item_id) | ||
| """, | ||
| target=OperationTarget.LOCAL, | ||
| ), |
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.
would this actually work? if you drop the column, the order by would break maybe?
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.
We can't modify the order by again since we'd modify it with columns that contain data and it might change the order of things on disk, the actual backwards operation here would be to stop inserting in timestamp_ns.
I removed the backwards operation.
5735acb to
51b6b0c
Compare
Replace RunSql with AddColumn operation for adding the timestamp_ns column to the distributed table. This uses the standard migration operation instead of raw SQL. Note: This migration is non-reversible due to ClickHouse limitations. ClickHouse does not allow removing a column from the middle of a sorting key via ALTER TABLE MODIFY ORDER BY. Co-Authored-By: Claude <noreply@anthropic.com>
51b6b0c to
e0ac45e
Compare
Add a new
timestamp_nscolumn of typeUInt16to theeap_items_1table for storing sub-second timestamp precision.The migration:
timestamp_nscolumn after the existingtimestampcolumntimestamp_nsaftertimestamp:(organization_id, project_id, item_type, timestamp, timestamp_ns, trace_id, item_id)