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

Alt approach for grant location #218

Merged

Conversation

jtcohen6
Copy link
Contributor

@jtcohen6 jtcohen6 commented Jul 11, 2022

builds off #212

Alternative approach, with two main components:

  1. Use an adapter (Python) method to get the location from the client's dataset reference, rather than requiring it in the user's profiles.yml. This value should always be available. It does require an API/client call, so we could look into either (a) caching it, or (b) taking the user-supplied credentials.location if available—but the call is super quick one, and I'd vote better safe than sorry.
  2. Add location as an attribute of BigQueryRelation + BigQueryInformationSchema. Add it into the rendered form of {{ relation.information_schema() }} in a pretty hacky way. A better approach would require us to update lots of underlying class methods, to register Region as a real ComponentName. This feels like a reasonable compromise for now, which still lets us benefit from the relation.information_schema() abstraction within dbt (Add Grants to BigQuery Materializations #212 (comment)).

These approaches could be separated out, if (e.g.) we wanted to use 1 but not 2. I wasn't super neat about it in my commits, but it's not a lot of code.

Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

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

This feels like a great balance between implementing our generalized patterns while making the minimal amount of code changes.

👍 I feel good about adopting both components/approaches (1 and 2).

It seems like the only thing to determine is whether to raise an exception or leave as-is (without raising the exception).


select privilege_type, grantee
from `{{ relation.project }}`.`region-{{ target.location }}`.INFORMATION_SCHEMA.OBJECT_PRIVILEGES
from {{ relation.information_schema("OBJECT_PRIVILEGES") }}
Copy link
Contributor

Choose a reason for hiding this comment

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

🤩

Comment on lines +82 to +84
def get_region_identifier(self) -> str:
region_id = f"region-{self.location}"
return self.quoted(region_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

🎯

Comment on lines 86 to 90
@classmethod
def from_relation(cls, relation, information_schema_view):
info_schema = super().from_relation(relation, information_schema_view)
if information_schema_view == "OBJECT_PRIVILEGES" and relation.location:
# TODO: raise an exception if relation.location is missing?
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any concerns about raising an exception?

It seems like either we raise the exception (hopefully with a useful message) or BigQuery will raise it during execution.

dbt/adapters/bigquery/relation.py Show resolved Hide resolved
dbt/adapters/bigquery/relation.py Show resolved Hide resolved
@emmyoop emmyoop merged commit 27c41ed into er/ct-717-grant-materialization Jul 11, 2022
@emmyoop emmyoop deleted the jerco/bq-grants-alt-location-approach branch July 11, 2022 16:46
emmyoop added a commit that referenced this pull request Jul 11, 2022
* Add get_show_grant_sql

* first pass at granting with sql

* more macro overrides

* update macros, temp update to dev-req for CI

* tweak to sql and added some TODOs

* move things around

* exclude session_user

* fix mypy error, fix exclude to be more than users

* simplify revoke logic

* small cleanup, point to ct-660 branch

* grant entire list in one statement

* wip

* wip, broken tests

* Update dbt/include/bigquery/macros/materializations/incremental.sql

Co-authored-by: Anders <anders.swanson@dbtlabs.com>

* working on getting tests working, very WIP

* All tests passing locally

* Updated user / group names

* Ongoing test cleanup

* Account for refactor in dbt-labs/dbt-core@c763601

* Updated third value

* Alt approach for grant location (#218)

* Alt approach to grabbing + factoring info_schema region

* add exception for blank location

* Update dbt/adapters/bigquery/relation.py

Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>

* point to existing branch

* fix pre commit errors

Co-authored-by: Emily Rockman <emily.rockman@dbtlabs.com>
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>

* reset to point dbt-core to main instead of branch

* fix examples in test.env.example

* add changelog

Co-authored-by: Anders <anders.swanson@dbtlabs.com>
Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Co-authored-by: Doug Beatty <doug.beatty@dbtlabs.com>
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants