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

Make grant configs a no-op for DuckDB #459

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dbt/adapters/duckdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager
from multiprocessing.context import SpawnContext
from typing import Optional
from typing import Set
from typing import Tuple
from typing import TYPE_CHECKING

Expand All @@ -25,6 +26,7 @@ class DuckDBConnectionManager(SQLConnectionManager):
TYPE = "duckdb"
_LOCK = threading.RLock()
_ENV = None
_LOGGED_MESSAGES: Set[str] = set()

def __init__(self, config: AdapterRequiredConfig, mp_context: SpawnContext) -> None:
super().__init__(config, mp_context)
Expand Down Expand Up @@ -68,6 +70,15 @@ def close(cls, connection: Connection) -> Connection:
connection = super(SQLConnectionManager, cls).close(connection)
return connection

@classmethod
def warn_once(cls, msg: str):
"""Post a warning message once per dbt execution."""
with cls._LOCK:
if msg in cls._LOGGED_MESSAGES:
return
cls._LOGGED_MESSAGES.add(msg)
logger.warning(msg)

def cancel(self, connection: Connection):
if self._ENV is not None:
logger.debug(
Expand Down
15 changes: 13 additions & 2 deletions dbt/adapters/duckdb/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from dbt.adapters.duckdb.relation import DuckDBRelation
from dbt.adapters.duckdb.utils import TargetConfig
from dbt.adapters.duckdb.utils import TargetLocation
from dbt.adapters.events.logging import AdapterLogger
from dbt.adapters.sql import SQLAdapter


Expand All @@ -31,6 +32,8 @@
if TYPE_CHECKING:
import agate

logger = AdapterLogger("DuckDB")


class DuckDBAdapter(SQLAdapter):
ConnectionManager = DuckDBConnectionManager
Expand Down Expand Up @@ -171,6 +174,11 @@ def external_read_location(self, write_location: str, rendered_options: dict) ->
return ".".join(["/".join(globs), str(rendered_options.get("format", "parquet"))])
return write_location

@available
def warn_once(self, msg: str):
"""Post a warning message once per dbt execution."""
DuckDBConnectionManager.warn_once(msg)

def valid_incremental_strategies(self) -> Sequence[str]:
"""DuckDB does not currently support MERGE statement."""
return ["append", "delete+insert"]
Expand Down Expand Up @@ -255,7 +263,8 @@ def _clean_up_temp_relation_for_incremental(self, config):
if self.is_motherduck() and hasattr(config, "model"):
if "incremental" == config.model.get_materialization():
temp_relation = self.Relation(
path=self.get_temp_relation_path(config.model), type=RelationType.Table
path=self.get_temp_relation_path(config.model),
type=RelationType.Table,
)
self.drop_relation(temp_relation)

Expand All @@ -278,7 +287,9 @@ def get_temp_relation_path(self, model: Any):
table that is dropped at the end of the incremental macro or post-model hook.
"""
return Path(
schema=self._temp_schema_name, database=model.database, identifier=model.identifier
schema=self._temp_schema_name,
database=model.database,
identifier=model.identifier,
)

def post_model_hook(self, config: Any, context: Any) -> None:
Expand Down
7 changes: 7 additions & 0 deletions dbt/include/duckdb/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,10 @@ def materialize(df, con):

{% do return(options) %}
{%- endmacro %}

{% macro duckdb__apply_grants(relation, grant_config, should_revoke=True) %}
{#-- If grant_config is {} or None, this is a no-op --#}
{% if grant_config %}
{{ adapter.warn_once('Grants for relations are not supported by DuckDB') }}
{% endif %}
{% endmacro %}
Loading