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

Support profiles that are simply 'type: duckdb' by correctly configuring the in-memory db setup #159

Merged
merged 4 commits into from
May 2, 2023
Merged
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
33 changes: 18 additions & 15 deletions dbt/adapters/duckdb/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,25 @@ class DuckDBCredentials(Credentials):

@classmethod
def __pre_deserialize__(cls, data: Dict[Any, Any]) -> Dict[Any, Any]:
data = super().__pre_deserialize__(data)
path = data.get("path")
if path and "database" not in data and duckdb.__version__ >= "0.7.0":
if path == ":memory:":
data["database"] = "memory"
else:
parsed = urlparse(path)
base_file = os.path.basename(parsed.path)
db = os.path.splitext(base_file)[0]
if db:
data["database"] = db
if duckdb.__version__ >= "0.7.0":
data = super().__pre_deserialize__(data)
if "database" not in data:
# if no database is specified in the profile, figure out
# the database value to use from the path argument
path = data.get("path")
if path is None or path == ":memory:":
data["database"] = "memory"
else:
raise dbt.exceptions.DbtRuntimeError(
"Unable to determine database name from path"
" and no database was specified in profile"
)
parsed = urlparse(path)
base_file = os.path.basename(parsed.path)
db = os.path.splitext(base_file)[0]
if db:
data["database"] = db
else:
raise dbt.exceptions.DbtRuntimeError(
"Unable to determine database name from path"
" and no database was specified in profile"
)
return data

@property
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def dbt_profile_target(profile_type, bv_server_process, tmp_path_factory):
"port": 5433,
"user": "test",
}
elif profile_type == "memory":
profile["path"] = ":memory:"
elif profile_type == "file":
profile["path"] = str(tmp_path_factory.getbasetemp() / "tmp.db")
elif profile_type == "memory":
pass # use the default path-less profile
else:
raise ValueError(f"Invalid profile type '{profile_type}'")

Expand All @@ -71,4 +71,4 @@ def skip_by_profile_type(profile_type, request):
@pytest.fixture(scope="session")
def test_data_path():
test_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(test_dir, "data")
return os.path.join(test_dir, "data")
5 changes: 2 additions & 3 deletions tests/functional/adapter/test_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
SELECT * FROM {{ ref('source_model') }}
"""


@pytest.mark.skip_profile("buenavista")
class TestAttachedDatabase:
@pytest.fixture(scope="class")
Expand All @@ -45,14 +46,12 @@ def attach_test_db(self):

@pytest.fixture(scope="class")
def profiles_config_update(self, dbt_profile_target, attach_test_db):
if "path" not in dbt_profile_target:
return {}
return {
"test": {
"outputs": {
"dev": {
"type": "duckdb",
"path": dbt_profile_target["path"],
"path": dbt_profile_target.get("path", ":memory:"),
"attach": [{"path": attach_test_db}],
}
},
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/fsspec/test_filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
WHERE conf = 'West'
"""


@pytest.mark.skip_profile("buenavista")
class TestFilesystems:
@pytest.fixture(scope="class")
def dbt_profile_target(self, dbt_profile_target):
if "path" not in dbt_profile_target:
return dbt_profile_target
return {
"type": "duckdb",
"path": dbt_profile_target["path"],
"filesystems": [{"fs": "github", "org": "jwills", "repo": "nba_monte_carlo"}],
"path": dbt_profile_target.get("path", ":memory:"),
"filesystems": [
{"fs": "github", "org": "jwills", "repo": "nba_monte_carlo"}
],
}

@pytest.fixture(scope="class")
Expand Down
5 changes: 1 addition & 4 deletions tests/functional/plugins/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def sqlite_test_db(self):

@pytest.fixture(scope="class")
def profiles_config_update(self, dbt_profile_target, sqlite_test_db):
if "path" not in dbt_profile_target:
return {}

config = {"connection_url": f"sqlite:///{sqlite_test_db}"}
plugins = [
{"name": "excel", "impl": "excel"},
Expand All @@ -87,7 +84,7 @@ def profiles_config_update(self, dbt_profile_target, sqlite_test_db):
"outputs": {
"dev": {
"type": "duckdb",
"path": dbt_profile_target["path"],
"path": dbt_profile_target.get("path", ":memory:"),
"plugins": plugins,
}
},
Expand Down