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(data-warehouse): Add created_at to BigQuery persons batch export #26486

Merged
merged 6 commits into from
Nov 29, 2024

Conversation

rossgray
Copy link
Contributor

@rossgray rossgray commented Nov 27, 2024

Problem

We don't currently send the created_at field in the persons batch export. Here we add it for the BigQuery destination (others to follow).

Changes

  • Updated the persons batch export view query (requires a ClickHouse migration)
  • Updated the query used by BigQuery persons batch export to include the created_at column
  • The created_at column will only be used when creating new tables, if the export uses a merge then it will be ignored in order to preserve the current table schema. If the user adds the column to their BigQuery table manually, the data will be included in subsequent batch exports.

Questions

  • Should I add the migration in a separate PR? I'm not sure if we could run into a case where the migration hasn't been applied but exports are running and failing due to the created_at column not existing yet?
  • I wasn't able to test the frontend changes because I think persons batch export is behind a feature flag and not sure how to set that up locally. It's a fairly simple change though so I presume it should be ok?

Post-deployment

  • Need to update the batch export docs to mention the addition of this new field and also to describe how to pull in this field for existing batch exports

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

Should do

How did you test this code?

Added unit test to cover both newly created tables and existing ones.

@rossgray rossgray changed the title Add created_at to persons batch export Add created_at to persons batch export Nov 27, 2024
@rossgray rossgray changed the title Add created_at to persons batch export feat(data-warehouse): Add created_at to persons batch export Nov 27, 2024
@rossgray rossgray force-pushed the ross/add-created-at-to-persons-batch-export branch from ac356bf to c9da9c8 Compare November 27, 2024 20:42
Copy link
Contributor

github-actions bot commented Nov 27, 2024

Size Change: 0 B

Total Size: 1.16 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.16 MB

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@rossgray rossgray changed the title feat(data-warehouse): Add created_at to persons batch export feat(data-warehouse): Add created_at to BigQuery persons batch export Nov 28, 2024
@rossgray rossgray marked this pull request as ready for review November 28, 2024 09:13
@rossgray rossgray requested a review from a team as a code owner November 28, 2024 09:13
@rossgray rossgray requested a review from tomasfarias November 28, 2024 09:13
@rossgray rossgray force-pushed the ross/add-created-at-to-persons-batch-export branch from e9dcdf3 to 2ed487a Compare November 28, 2024 11:27
exists_ok: bool = True,
not_found_ok: bool = True,
delete: bool = True,
create: bool = True,
) -> collections.abc.AsyncGenerator[bigquery.Table, None]:
"""Manage a table in BigQuery by ensure it exists while in context."""
if create is True:
assert table_schema is not None, "Table schema is required when creating a table"
Copy link
Contributor

Choose a reason for hiding this comment

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

Assertions are removed by optimized Python, I'm wondering if we would prefer to still keep the check by instead raising a ValueError("Table schema is required when creating a table") or other non-retryable error here.

Do we ever expect schema to be None?

Copy link
Contributor Author

@rossgray rossgray Nov 28, 2024

Choose a reason for hiding this comment

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

Assertions are removed by optimized Python

ah right, I wasn't aware of this, thanks!

Do we ever expect schema to be None?

To be honest, we're always called managed_table with a schema so we can probably remove this check

@@ -450,6 +472,109 @@ async def test_insert_into_bigquery_activity_merges_data_in_follow_up_runs(
)


async def test_insert_into_bigquery_activity_handles_person_schema_changes(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test!

Copy link
Contributor

@tomasfarias tomasfarias left a comment

Choose a reason for hiding this comment

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

The migration will need to be bumped to 0093 (or later) as we'll merge my #26477 first. But otherwise PR looks good!

@rossgray rossgray force-pushed the ross/add-created-at-to-persons-batch-export branch from c6703a3 to e43bfa5 Compare November 28, 2024 14:53
Copy link
Contributor

@Daesgar Daesgar left a comment

Choose a reason for hiding this comment

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

lgtm!

@rossgray rossgray merged commit ce66669 into master Nov 29, 2024
96 checks passed
@rossgray rossgray deleted the ross/add-created-at-to-persons-batch-export branch November 29, 2024 10:54
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.

4 participants