-
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.
- 新增克隆表功能,支持在 MaxCompute 中创建表的副本 - 优化表创建逻辑,移除不必要的 if not exists 判断 - 添加更新表注释和列注释的功能 - 新增测试用例以验证克隆表和注释功能
- Loading branch information
1 parent
186525a
commit e085e98
Showing
27 changed files
with
1,186 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.8.0-alpha.9" | ||
version = "1.8.0-dev" |
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,16 @@ | ||
{% macro maxcompute__alter_column_comment(relation, column_dict) %} | ||
{% set existing_columns = adapter.get_columns_in_relation(relation) | map(attribute="name") | list %} | ||
{% for column_name in column_dict if (column_name in existing_columns) %} | ||
{% set comment = column_dict[column_name]['description'] %} | ||
{% set escaped_comment = quote_and_escape(comment) %} | ||
alter table {{ relation.render() }} change column {{ column_name }} comment {{ escaped_comment }}; | ||
{% endfor %} | ||
{% endmacro %} | ||
|
||
{% macro maxcompute__alter_relation_comment(relation, relation_comment) -%} | ||
{% if relation.is_table -%} | ||
alter table {{relation.render()}} set comment {{quote_and_escape(relation_comment)}}; | ||
{% else -%} | ||
{{ exceptions.raise_compiler_error("MaxCompute not support set comment to view") }} | ||
{% endif -%} | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% macro maxcompute__can_clone_table() %} | ||
{{ return(True) }} | ||
{% endmacro %} | ||
|
||
|
||
{% macro maxcompute__create_or_replace_clone(this_relation, defer_relation) %} | ||
clone table {{ this_relation.render() }} to {{ defer_relation.render() }} if exists overwrite; | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% macro run_hooks(hooks, inside_transaction=True) %} | ||
{% for hook in hooks | selectattr('transaction', 'equalto', inside_transaction) %} | ||
{% set rendered = render(hook.get('sql')) | trim %} | ||
{% if (rendered | length) > 0 %} | ||
{% call statement(auto_begin=inside_transaction) %} | ||
{{ rendered }} | ||
{% endcall %} | ||
{% endif %} | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
drop table if exists {schema}.on_model_hook; | ||
|
||
create table {schema}.on_model_hook ( | ||
test_state string, -- start|end | ||
target_dbname string, | ||
target_host string, | ||
target_name string, | ||
target_schema string, | ||
target_type string, | ||
target_user string, | ||
target_pass string, | ||
target_threads int, | ||
run_started_at string, | ||
invocation_id string, | ||
thread_id string | ||
); |
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,16 @@ | ||
drop table if exists {schema}.on_run_hook; | ||
|
||
create table {schema}.on_run_hook ( | ||
test_state string, -- start|end | ||
target_dbname string, | ||
target_host string, | ||
target_name string, | ||
target_schema string, | ||
target_type string, | ||
target_user string, | ||
target_pass string, | ||
target_threads int, | ||
run_started_at string, | ||
invocation_id string, | ||
thread_id string | ||
); |
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,25 @@ | ||
import pytest | ||
from dbt.artifacts.schemas.catalog import CatalogArtifact | ||
from dbt.tests.adapter.catalog.relation_types import CatalogRelationTypes | ||
|
||
|
||
class TestCatalogAdapter(CatalogRelationTypes): | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def models(self): | ||
from dbt.tests.adapter.catalog import files | ||
|
||
yield {"my_table.sql": files.MY_TABLE, "my_view.sql": files.MY_VIEW} | ||
|
||
@pytest.mark.parametrize( | ||
"node_name,relation_type", | ||
[ | ||
("seed.test.my_seed", "TABLE"), | ||
("model.test.my_table", "TABLE"), | ||
("model.test.my_view", "VIEW"), | ||
], | ||
) | ||
def test_relation_types_populate_correctly( | ||
self, docs: CatalogArtifact, node_name: str, relation_type: str | ||
): | ||
super().test_relation_types_populate_correctly(docs, node_name, relation_type) |
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,27 @@ | ||
import pytest | ||
from dbt.tests.adapter.dbt_clone.test_dbt_clone import ( | ||
BaseClonePossible, | ||
BaseCloneSameTargetAndState, | ||
) | ||
|
||
|
||
class TestMaxComputeClonePossible(BaseClonePossible): | ||
@pytest.fixture(autouse=True) | ||
def clean_up(self, project): | ||
yield | ||
with project.adapter.connection_named("__test"): | ||
relation = project.adapter.Relation.create( | ||
database=project.database, schema=f"{project.test_schema}_seeds" | ||
) | ||
project.adapter.drop_schema(relation) | ||
|
||
relation = project.adapter.Relation.create( | ||
database=project.database, schema=project.test_schema | ||
) | ||
project.adapter.drop_schema(relation) | ||
|
||
pass | ||
|
||
|
||
class TestCloneSameTargetAndState(BaseCloneSameTargetAndState): | ||
pass |
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,17 @@ | ||
from dbt.tests.adapter.dbt_show.test_dbt_show import ( | ||
BaseShowSqlHeader, | ||
BaseShowLimit, | ||
BaseShowDoesNotHandleDoubleLimit, | ||
) | ||
|
||
|
||
class TestPostgresShowSqlHeader(BaseShowSqlHeader): | ||
pass | ||
|
||
|
||
class TestPostgresShowLimit(BaseShowLimit): | ||
pass | ||
|
||
|
||
class TestShowDoesNotHandleDoubleLimit(BaseShowDoesNotHandleDoubleLimit): | ||
pass |
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,9 @@ | ||
from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, BaseTestEmptyInlineSourceRef | ||
|
||
|
||
class TestEmpty(BaseTestEmpty): | ||
pass | ||
|
||
|
||
class TestEmptyInlineSourceRef(BaseTestEmptyInlineSourceRef): | ||
pass |
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,74 @@ | ||
from dbt.tests.adapter.ephemeral.test_ephemeral import ( | ||
BaseEphemeral, | ||
BaseEphemeralMulti, | ||
BaseEphemeralNested, | ||
BaseEphemeralErrorHandling, | ||
) | ||
import os | ||
import re | ||
from dbt.tests.util import check_relations_equal, run_dbt | ||
|
||
|
||
# change test project to actually project, here is 'dingxin' | ||
class TestEphemeralMulti(BaseEphemeralMulti): | ||
def test_ephemeral_multi(self, project): | ||
run_dbt(["seed"]) | ||
results = run_dbt(["run"]) | ||
assert len(results) == 3 | ||
|
||
check_relations_equal(project.adapter, ["seed", "dependent"]) | ||
check_relations_equal(project.adapter, ["seed", "double_dependent"]) | ||
check_relations_equal(project.adapter, ["seed", "super_dependent"]) | ||
assert os.path.exists("./target/run/test/models/double_dependent.sql") | ||
with open("./target/run/test/models/double_dependent.sql", "r") as fp: | ||
sql_file = fp.read() | ||
|
||
sql_file = re.sub(r"\d+", "", sql_file) | ||
expected_sql = ( | ||
"create view `dingxin`.`test_test_ephemeral`.`double_dependent__dbt_tmp` as (" | ||
"with __dbt__cte__base as (" | ||
"select * from test_test_ephemeral.seed" | ||
"), __dbt__cte__base_copy as (" | ||
"select * from __dbt__cte__base" | ||
")-- base_copy just pulls from base. Make sure the listed" | ||
"-- graph of CTEs all share the same dbt_cte__base cte" | ||
"select * from __dbt__cte__base where gender = 'Male'" | ||
"union all" | ||
"select * from __dbt__cte__base_copy where gender = 'Female'" | ||
");" | ||
) | ||
sql_file = "".join(sql_file.split()) | ||
expected_sql = "".join(expected_sql.split()) | ||
assert sql_file == expected_sql | ||
|
||
pass | ||
|
||
|
||
class TestEphemeralNested(BaseEphemeralNested): | ||
def test_ephemeral_nested(self, project): | ||
results = run_dbt(["run"]) | ||
assert len(results) == 2 | ||
assert os.path.exists("./target/run/test/models/root_view.sql") | ||
with open("./target/run/test/models/root_view.sql", "r") as fp: | ||
sql_file = fp.read() | ||
|
||
sql_file = re.sub(r"\d+", "", sql_file) | ||
expected_sql = ( | ||
"create view `dingxin`.`test_test_ephemeral`.`root_view__dbt_tmp` as (" | ||
"with __dbt__cte__ephemeral_level_two as (" | ||
"select * from `dingxin`.`test_test_ephemeral`.`source_table`" | ||
"), __dbt__cte__ephemeral as (" | ||
"select * from __dbt__cte__ephemeral_level_two" | ||
")select * from __dbt__cte__ephemeral" | ||
");" | ||
) | ||
|
||
sql_file = "".join(sql_file.split()) | ||
expected_sql = "".join(expected_sql.split()) | ||
assert sql_file == expected_sql | ||
|
||
pass | ||
|
||
|
||
class TestEphemeralErrorHandling(BaseEphemeralErrorHandling): | ||
pass |
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,9 @@ | ||
import pytest | ||
from dbt.tests.adapter.grants.test_seed_grants import BaseSeedGrants | ||
|
||
|
||
@pytest.mark.skip( | ||
reason="Please use webconsole/pyodps for permission operations. Dbt will not perform any modification operations." | ||
) | ||
class TestSeedGrants(BaseSeedGrants): | ||
pass |
Oops, something went wrong.