Skip to content
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

feat: Support property group migrations on distributed and sharded tables #24274

Merged
merged 3 commits into from
Aug 12, 2024

Conversation

tkaemming
Copy link
Contributor

Problem

#24152 added the property group columns to the sharded tables, but not the distributed tables.

Changes

This extracts the migration related parts from #24171:

  • Refactors PropertyGroupManager to more cleanly support managing multiple tables
  • Adds (non-materialized) property group columns to the sharded_events table in migration
  • Adds property group columns to SQL statements in posthog/models/event/sql.py so that they are created in test environment which does not apply migrations, and updates migrations to use IF NOT EXISTS to avoid conflicts

Does this work well for both Cloud and self-hosted?

Yes.

How did you test this code?

Run migrations and see updated snapshot.

@tkaemming tkaemming changed the title ref: Support property group migrations on distributed and sharded tables feat: Support property group migrations on distributed and sharded tables Aug 8, 2024
@tkaemming tkaemming marked this pull request as ready for review August 8, 2024 22:31
@tkaemming tkaemming requested a review from a team as a code owner August 8, 2024 22:31

def get_create_table_pieces(self, table: TableName) -> Iterable[str]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the correct terminology is here. They're not expressions, but also not whole statements, so just went with something generic.

Comment on lines +16 to +18
TableName = str
ColumnName = str
PropertyGroupName = str
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(These aliases are just for documentation purposes.)

"sharded_events": event_property_group_definitions,
"events": {
column_name: {
group_name: dataclasses.replace(group_definition, is_materialized=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of clunky — maybe in retrospect it would have been better to have this as some sort of flag up at the table level rather than each individual property group definition…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's definitely not easy reading

Comment on lines +62 to +65
for group_name in groups:
yield self.__get_column_definition(table, column, group_name)
for index_definition in self.__get_index_definitions(table, column, group_name):
yield f"INDEX {index_definition}"
Copy link
Member

@fuziontech fuziontech Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig this. Really nice use of python iterator building up table bits

Copy link
Member

@fuziontech fuziontech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@tkaemming tkaemming merged commit 716ff6f into master Aug 12, 2024
86 checks passed
@tkaemming tkaemming deleted the property-groups-migrations branch August 12, 2024 18:26
tkaemming added a commit that referenced this pull request Aug 13, 2024
We'll try this again later
fuziontech added a commit that referenced this pull request Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants