-
Notifications
You must be signed in to change notification settings - Fork 166
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
Alt approach for grant location #218
Conversation
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.
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") }} |
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.
🤩
def get_region_identifier(self) -> str: | ||
region_id = f"region-{self.location}" | ||
return self.quoted(region_id) |
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.
🎯
dbt/adapters/bigquery/relation.py
Outdated
@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? |
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.
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.
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…b.com/dbt-labs/dbt-bigquery into jerco/bq-grants-alt-location-approach
…dbt-labs/dbt-bigquery into jerco/bq-grants-alt-location-approach
* 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>
builds off #212
Alternative approach, with two main components:
location
from the client's dataset reference, rather than requiring it in the user'sprofiles.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-suppliedcredentials.location
if available—but the call is super quick one, and I'd vote better safe than sorry.location
as an attribute ofBigQueryRelation
+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 registerRegion
as a realComponentName
. This feels like a reasonable compromise for now, which still lets us benefit from therelation.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.