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

Bigquery sync table require filter #36677

Merged
merged 30 commits into from
Dec 20, 2023
Merged

Conversation

qnkhuat
Copy link
Contributor

@qnkhuat qnkhuat commented Dec 12, 2023

First milestone of #36668

Known limitation: this won't work for materialized views, see https://github.com/metabase/metabase/pull/36677/files#diff-370f1464c7c10bd0d0bd84544e6f80102152617fcd99fea6e9bd4dbaff4903caR131-R135 for why

To read more about partitioned tables, see https://cloud.google.com/bigquery/docs/partitioned-tables

@metabase-bot metabase-bot bot added the .Team/BackendComponents also known as BEC label Dec 12, 2023
@qnkhuat qnkhuat force-pushed the ngoc-bigquery-sync-filter-key branch from 869f11f to 7352041 Compare December 15, 2023 04:15
Copy link

cypress bot commented Dec 15, 2023

4 flaky tests on run #617 ↗︎

0 2179 159 0 Flakiness 4

Details:

Bigquery sync table require filter
Project: Metabase e2e Commit: 14bff219ec
Status: Passed Duration: 15:13 💡
Started: Dec 20, 2023 8:26 AM Ended: Dec 20, 2023 8:41 AM
Flakiness  sharing/subscriptions.cy.spec.js • 1 flaky test • sharing

View Output

Test Artifacts
scenarios > dashboard > subscriptions > EE email subscriptions > should only show users in same group in recipients dropdown if `user-visiblity` setting is `group` Test Replay Screenshots
Flakiness  sharing/downloads/reproductions/19889-native-query-export-column-order.cy.spec.js • 2 flaky tests • flaky

View Output

Test Artifacts
issue 19889 > should order columns correctly in saved native query exports Test Replay Screenshots
issue 19889 > should order columns correctly in saved native query exports when the query was modified but not re-run before save (#19889) Test Replay Screenshots
Flakiness  question/notebook.cy.spec.js • 1 flaky test • slow

View Output

Test Artifacts
scenarios > question > notebook > should process the updated expression when pressing Enter Test Replay Screenshots

Review all test suite changes for PR #36677 ↗︎

our-metadata (our-metadata database)
strip-desc (fn [metadata]
(set (map #(dissoc % :description) metadata)))
name+schema->db-table (m/index-by (juxt :name :schema) db-tables)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took a stab at refactoring this sync step a bit.
Details in the following comments

(when (seq changed-tables)
(sync-util/with-error-handling (format "Error updating table description for %s" (sync-util/name-for-logging database))
(update-table-description! database changed-tables)))
(sync-util/with-error-handling (format "Error updating table metadata for %s" (sync-util/name-for-logging database))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously, only table description could be updated during sync step, but I've changed it so that it could extend to other properties too.

table-metadata)
to-update-keys)
[_ changes _] (data/diff old-table new-table)
changes (cond-> changes
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 a specical case, check test metabase.sync.sync-metadata.comments-test/sync-existing-table-comment-test and metabase.sync.sync-metadata.comments-test/dont-overwrite-table-custom-description-test to know how it's expected to work.

@@ -114,7 +117,14 @@
(mt/dataset (basic-table "table_with_comment_after_sync" nil)
;; modify the source DB to add the comment and resync
(driver/notify-database-updated driver/*driver* (mt/db))
(tx/create-db! driver/*driver* (basic-table "table_with_comment_after_sync" "added comment"))
(tx/create-db! driver/*driver* (basic-table "table_with_comment_after_sync" nil))
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 test relied on the fact that descriptions are not included when inserting tables, the correct behavior is to start with a table without a description, then sync, then add a description, then sync. see https://github.com/metabase/metabase/pull/36677/files#r1427842665 for context.

@@ -185,8 +185,8 @@
(mt/with-test-user :rasta
(automagic-dashboards.test/with-dashboard-cleanup
(doseq [[table cardinality] (map vector
(t2/select Table :db_id (mt/id) {:order-by [[:id :asc]]})
[15 11 7 5])]
(t2/select Table :db_id (mt/id) {:order-by [[:name :asc]]})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 2 things happening here:

@qnkhuat qnkhuat requested a review from a team December 18, 2023 10:15
@@ -16,15 +16,15 @@ describe("scenarios > admin > datamodel > hidden tables (metabase#9759)", () =>

it("hidden table should not show up in various places in UI", () => {
// Visit the main page, we shouldn't be able to see the table
cy.visit(`/browse/${PRODUCTS_ID}`);
cy.visit(`/browse/${SAMPLE_DB_ID}`);
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 was a mistake and it accidentally works because producs_id and sample_db_id had the same id (=1)

Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

qnkhuat and others added 2 commits December 19, 2023 18:56
Copy link
Contributor

@calherries calherries left a comment

Choose a reason for hiding this comment

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

Solid work

Copy link
Contributor

@calherries calherries left a comment

Choose a reason for hiding this comment

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

Actually sorry, I think you're missing a test case for a table that is initially created without a required filter, then synced, then is modified to have a required filter, then synced again. Similar to sync-existing-table-comment-test

@qnkhuat
Copy link
Contributor Author

qnkhuat commented Dec 20, 2023

@calherries

I think you're missing a test case for a table that is initially created without a required filter, then synced, then is modified to have a required filter, then synced again. Similar to sync-existing-table-comment-test

This is not possible in bigquery because whether a table requires partition or not is a property it's created with. afaik You can't change it after.

I could add sth like sync-table-update-info-of-new-table-added-during-sync-test tho.

@calherries
Copy link
Contributor

Based on the docs (here and here), it looks like you can update the property after the table is created.

@calherries
Copy link
Contributor

Also using SQL (source):

ALTER TABLE IF EXISTS mydataset.newtable
SET OPTIONS(
    require_partition_filter = true
)

@qnkhuat
Copy link
Contributor Author

qnkhuat commented Dec 20, 2023

Good find! I was looking at the list of options for ALTER TABLE SET OPTIONS command(docs) and didn't find this option so I thought it's not possible.

anw I added the test here 8452b0b

Copy link
Contributor

@calherries calherries left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@qnkhuat qnkhuat added the no-backport Do not backport this PR to any branch label Dec 20, 2023
@qnkhuat qnkhuat merged commit ede142b into master Dec 20, 2023
107 of 108 checks passed
@qnkhuat qnkhuat deleted the ngoc-bigquery-sync-filter-key branch December 20, 2023 09:40
Copy link

@qnkhuat Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

@qnkhuat qnkhuat added this to the 0.49 milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/BackendComponents also known as BEC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants