forked from dbt-labs/dbt-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add apply_grants call to materialization macros (dbt-labs#381)
* Add apply_grants call to materialization macros * add standardize_grants_dict * Working grant macros * Initialize tests in CI * Refactor to account for core macro changes. Passing tests * Fix code checks * Try default__reset_csv_table * Code checks * Revert "Try default__reset_csv_table" This reverts commit 8bd4145. * Account for refactor in dbt-labs/dbt-core@c763601 * Account for test changes in dbt-labs/dbt-core@debc867 * add changelog * Empty-Commit * rerun ci * rerun ci * readd a persist_docs call to snapshot.sql * fix whitespace Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com> Co-authored-by: Matthew McKnight <matthew.mcknight@dbtlabs.com>
- Loading branch information
1 parent
af7fae3
commit f5db7e6
Showing
10 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{% macro spark__copy_grants() %} | ||
|
||
{% if config.materialized == 'view' %} | ||
{#-- Spark views don't copy grants when they're replaced --#} | ||
{{ return(False) }} | ||
|
||
{% else %} | ||
{#-- This depends on how we're replacing the table, which depends on its file format | ||
-- Just play it safe by assuming that grants have been copied over, and need to be checked / possibly revoked | ||
-- We can make this more efficient in the future | ||
#} | ||
{{ return(True) }} | ||
|
||
{% endif %} | ||
{% endmacro %} | ||
|
||
|
||
{%- macro spark__get_grant_sql(relation, privilege, grantees) -%} | ||
grant {{ privilege }} on {{ relation }} to {{ adapter.quote(grantees[0]) }} | ||
{%- endmacro %} | ||
|
||
|
||
{%- macro spark__get_revoke_sql(relation, privilege, grantees) -%} | ||
revoke {{ privilege }} on {{ relation }} from {{ adapter.quote(grantees[0]) }} | ||
{%- endmacro %} | ||
|
||
|
||
{%- macro spark__support_multiple_grantees_per_dcl_statement() -%} | ||
{{ return(False) }} | ||
{%- endmacro -%} | ||
|
||
|
||
{% macro spark__call_dcl_statements(dcl_statement_list) %} | ||
{% for dcl_statement in dcl_statement_list %} | ||
{% call statement('grant_or_revoke') %} | ||
{{ dcl_statement }} | ||
{% endcall %} | ||
{% endfor %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
from dbt.tests.adapter.grants.test_model_grants import BaseModelGrants | ||
from dbt.tests.adapter.grants.test_incremental_grants import BaseIncrementalGrants | ||
from dbt.tests.adapter.grants.test_invalid_grants import BaseInvalidGrants | ||
from dbt.tests.adapter.grants.test_seed_grants import BaseSeedGrants | ||
from dbt.tests.adapter.grants.test_snapshot_grants import BaseSnapshotGrants | ||
|
||
|
||
@pytest.mark.skip_profile("apache_spark", "spark_session") | ||
class TestModelGrantsSpark(BaseModelGrants): | ||
def privilege_grantee_name_overrides(self): | ||
# insert --> modify | ||
return { | ||
"select": "select", | ||
"insert": "modify", | ||
"fake_privilege": "fake_privilege", | ||
"invalid_user": "invalid_user", | ||
} | ||
|
||
|
||
@pytest.mark.skip_profile("apache_spark", "spark_session") | ||
class TestIncrementalGrantsSpark(BaseIncrementalGrants): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"+file_format": "delta", | ||
"+incremental_strategy": "merge", | ||
} | ||
} | ||
|
||
|
||
@pytest.mark.skip_profile("apache_spark", "spark_session") | ||
class TestSeedGrantsSpark(BaseSeedGrants): | ||
# seeds in dbt-spark are currently "full refreshed," in such a way that | ||
# the grants are not carried over | ||
# see https://github.com/dbt-labs/dbt-spark/issues/388 | ||
def seeds_support_partial_refresh(self): | ||
return False | ||
|
||
|
||
@pytest.mark.skip_profile("apache_spark", "spark_session") | ||
class TestSnapshotGrantsSpark(BaseSnapshotGrants): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"snapshots": { | ||
"+file_format": "delta", | ||
"+incremental_strategy": "merge", | ||
} | ||
} | ||
|
||
|
||
@pytest.mark.skip_profile("apache_spark", "spark_session") | ||
class TestInvalidGrantsSpark(BaseInvalidGrants): | ||
def grantee_does_not_exist_error(self): | ||
return "RESOURCE_DOES_NOT_EXIST" | ||
|
||
def privilege_does_not_exist_error(self): | ||
return "Action Unknown" |