-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 add database schema and datalake options to profile creation (#60)
### Add new Profile Options Add profile options that reflect Dremio concepts. ### Description Existing profile options reflected dbt concepts that did map intuitively to Dremio concepts, such as `database`, `schema`, etc. Hence, added profile options that reflect Dremio concepts, and mapped these to the dbt equivalents. Added: - object_storage_source --> datalake - object_storage_path --> root_folder - dremio_space --> database - dremio_space_folder --> schema ### Related Issue #53 ### Additional Reviewers @ArgusLi @ravjotbrar ### Testing - /tests/component/test_profile_template.py [new] - /.github/scripts/smoke_test.sh (all tests) Co-authored-by: ArgusLi <[email protected]>
- Loading branch information
Showing
5 changed files
with
198 additions
and
37 deletions.
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
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,139 @@ | ||
# Copyright (C) 2022 Dremio Corporation | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import pytest | ||
from typing import Dict | ||
import os | ||
|
||
from dbt.config.profile import read_profile | ||
from dbt.adapters.dremio.credentials import DremioCredentials | ||
|
||
# Tests require manual setup before executing. | ||
# | ||
# Prior to running these tests, create three dbt projects: | ||
# | ||
# 1. `dbt init test_cloud_options` | ||
# - accept all default options | ||
# - provide any value for mandatory options | ||
# | ||
# 2. `dbt init test_sw_up_options` | ||
# - accept all default options | ||
# - provide any value for mandatory options | ||
# | ||
# 3. `dbt init test_sw_pat_options` | ||
# - accept all default options | ||
# - provide any value for mandatory options | ||
# | ||
# These tests assumes there exists a $HOME/.dbt/profiles.yml | ||
# file containing these three dbt projects. | ||
class TestProfileTemplate: | ||
# non-OS specific | ||
PROFILE_DIRECTORY = os.path.expanduser("~") + "/.dbt/" | ||
|
||
# These projects must exist in the profile.yml file. All defaults must be selected. | ||
_TEST_CLOUD_PROFILE_PROJECT = "test_cloud_options" | ||
_TEST_SOFTWARE_USER_PASSWORD_PROFILE_PROJECT = "test_sw_up_options" | ||
_TEST_SOFTWARE_PAT_PROFILE_PROJECT = "test_sw_pat_options" | ||
|
||
_PASSWORD_AUTH_PROFILE_OPTIONS_WITH_DEFAULTS = {"password": None} | ||
_PAT_AUTH_PROFILE_OPTIONS_WITH_DEFAULTS = {"pat": None} | ||
_COMMON_PROFILE_OPTIONS_WITH_DEFAULTS = { | ||
"user": None, | ||
"object_storage_source": "$scratch", | ||
"object_storage_path": "no_schema", | ||
"dremio_space": "@user", | ||
"dremio_space_folder": "no_schema", | ||
"threads": 1, | ||
} | ||
_DREMIO_CLOUD_PROFILE_SPECIFIC_OPTIONS_WITH_DEFAULTS = { | ||
"cloud_host": "api.dremio.cloud", | ||
"cloud_project_id": None, | ||
"use_ssl": True, | ||
} | ||
_DREMIO_SW_PROFILE_SPECIFIC_OPTIONS_WITH_DEFAULTS = { | ||
"software_host": None, | ||
"port": 9047, | ||
"use_ssl": False, | ||
} | ||
|
||
_DREMIO_CLOUD_PROFILE_OPTIONS_WITH_DEFAULTS = ( | ||
_COMMON_PROFILE_OPTIONS_WITH_DEFAULTS | ||
| _DREMIO_CLOUD_PROFILE_SPECIFIC_OPTIONS_WITH_DEFAULTS | ||
| _PAT_AUTH_PROFILE_OPTIONS_WITH_DEFAULTS | ||
) | ||
_DREMIO_SOFTWARE_USERNAME_PASSWORD_PROFILE_OPTIONS = ( | ||
_COMMON_PROFILE_OPTIONS_WITH_DEFAULTS | ||
| _DREMIO_SW_PROFILE_SPECIFIC_OPTIONS_WITH_DEFAULTS | ||
| _PASSWORD_AUTH_PROFILE_OPTIONS_WITH_DEFAULTS | ||
) | ||
_DREMIO_SOFTWARE_PAT_PROFILE_OPTIONS = ( | ||
_COMMON_PROFILE_OPTIONS_WITH_DEFAULTS | ||
| _DREMIO_SW_PROFILE_SPECIFIC_OPTIONS_WITH_DEFAULTS | ||
| _PAT_AUTH_PROFILE_OPTIONS_WITH_DEFAULTS | ||
) | ||
|
||
_PROFILE_OPTIONS_ALIASES = { | ||
"username": "UID", | ||
"user": "UID", | ||
"password": "PWD", | ||
"object_storage_source": "datalake", | ||
"object_storage_path": "root_path", | ||
"dremio_space": "database", | ||
"dremio_space_folder": "schema", | ||
} | ||
|
||
def test_cloud_options(self) -> None: | ||
self._test_project_profile_options( | ||
self._get_dbt_test_project_dict(self._TEST_CLOUD_PROFILE_PROJECT), | ||
self._DREMIO_CLOUD_PROFILE_OPTIONS_WITH_DEFAULTS, | ||
) | ||
|
||
def test_software_username_password_options(self) -> None: | ||
self._test_project_profile_options( | ||
self._get_dbt_test_project_dict( | ||
self._TEST_SOFTWARE_USER_PASSWORD_PROFILE_PROJECT | ||
), | ||
self._DREMIO_SOFTWARE_USERNAME_PASSWORD_PROFILE_OPTIONS, | ||
) | ||
|
||
def test_software_pat_options(self) -> None: | ||
self._test_project_profile_options( | ||
self._get_dbt_test_project_dict(self._TEST_SOFTWARE_PAT_PROFILE_PROJECT), | ||
self._DREMIO_SOFTWARE_PAT_PROFILE_OPTIONS, | ||
) | ||
|
||
def test_aliases(self) -> None: | ||
credentials = DremioCredentials() | ||
credential_option_aliases = credentials.aliases | ||
for option, alias in self._PROFILE_OPTIONS_ALIASES.items(): | ||
assert credential_option_aliases[option] is not None | ||
assert alias == credential_option_aliases[option] | ||
|
||
@pytest.mark.skip | ||
def _get_dbt_test_project_dict(self, dbt_test_project_name: str) -> Dict[str, any]: | ||
# read_profile returns dictionary with the following layout: | ||
# { <project name>: { 'outputs': { 'dev' } : { <all the profile options and values that we want to test> ] } } | ||
profile_dictionary = read_profile(TestProfileTemplate.PROFILE_DIRECTORY) | ||
return profile_dictionary.get(dbt_test_project_name).get("outputs").get("dev") | ||
|
||
@pytest.mark.skip | ||
def _test_project_profile_options( | ||
self, test_project: Dict[str, any], test_options: Dict[str, any] | ||
) -> None: | ||
|
||
assert test_project is not None | ||
|
||
for option in test_options: | ||
assert test_project[option] is not None | ||
if test_options[option] is not None: | ||
assert test_project[option] == test_options[option] |