Skip to content

Commit

Permalink
stryle: checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxin-tech committed Dec 25, 2024
1 parent 4060cc1 commit 3ff913c
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/maxcompute/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.0-alpha.13"
version = "1.8.0-alpha.13"
5 changes: 3 additions & 2 deletions dbt/adapters/maxcompute/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ def parse_partition_by(self, raw_partition_by: Any) -> Optional[PartitionConfig]

@available
@classmethod
def mc_render_raw_columns_constraints(cls, raw_columns: Dict[str, Dict[str, Any]],
partition_config: Optional[PartitionConfig]) -> List:
def mc_render_raw_columns_constraints(
cls, raw_columns: Dict[str, Dict[str, Any]], partition_config: Optional[PartitionConfig]
) -> List:
rendered_column_constraints = []
partition_column = []
if partition_config and not partition_config.auto_partition():
Expand Down
6 changes: 4 additions & 2 deletions dbt/adapters/maxcompute/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from dbt.adapters.contracts.relation import RelationType, Path, Policy, RelationConfig
from odps.models import Table

from dbt.adapters.maxcompute.relation_configs._materialized_view import MaxComputeMaterializedViewConfig
from dbt.adapters.maxcompute.relation_configs._materialized_view import (
MaxComputeMaterializedViewConfig,
)

Self = TypeVar("Self", bound="MaxComputeRelation")

Expand Down Expand Up @@ -80,7 +82,7 @@ def from_odps_table(cls, table: Table):

@classmethod
def materialized_view_from_relation_config(
cls, relation_config: RelationConfig
cls, relation_config: RelationConfig
) -> MaxComputeMaterializedViewConfig:
return MaxComputeMaterializedViewConfig.from_relation_config(relation_config)

Expand Down
18 changes: 14 additions & 4 deletions dbt/adapters/maxcompute/relation_configs/_materialized_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ def parse_relation_config(cls, relation_config: RelationConfig) -> Dict[str, Any
"schema": relation_config.schema,
"project": relation_config.database,
}
items = ["lifecycle", "build_deferred", "columns", "column_comment", "disable_rewrite", "table_comment",
"partition_by", "tblProperties"]
items = [
"lifecycle",
"build_deferred",
"columns",
"column_comment",
"disable_rewrite",
"table_comment",
"partition_by",
"tblProperties",
]

if relation_config:
for item in items:
Expand All @@ -78,7 +86,9 @@ def create_table_sql(self) -> str:
sql += "("
for column in self.columns:
if self.column_comment and column in self.column_comment:
sql += f"{quote_ref(column)} COMMENT {quote_string(self.column_comment[column])}"
sql += (
f"{quote_ref(column)} COMMENT {quote_string(self.column_comment[column])}"
)
else:
sql += f"{quote_ref(column)}"
sql += ", "
Expand All @@ -93,7 +103,7 @@ def create_table_sql(self) -> str:
if self.tblProperties and len(self.tblProperties) > 0:
sql += "TBLPROPERTIES( "
for k, v in self.tblProperties.items():
sql += f"\"{k}\"=\"{v}\", "
sql += f'"{k}"="{v}", '
sql = sql[:-2]
sql += ")\n"
return sql
12 changes: 6 additions & 6 deletions dbt/adapters/maxcompute/relation_configs/_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def auto_partition(self) -> bool:
def render(self, with_type: bool = True) -> str:
default_value = len(self.data_types) == 0
res = ""
for i, field in enumerate(self.fields):
for i, field_name in enumerate(self.fields):
if with_type:
if default_value:
column = f"{field} string"
column = f"{field_name} string"
else:
column = f"{field} {self.data_types[i]}"
column = f"{field_name} {self.data_types[i]}"
else:
column = field
column = field_name
res += f"{column}, "
res = res[:-2] # 去掉最后的逗号和空格
return res
Expand All @@ -42,8 +42,8 @@ def parse(cls, raw_partition_by) -> Optional["PartitionConfig"]:
try:
new_dict = {}
for key, value in raw_partition_by.items():
if key in ['fields', 'data_types']:
new_dict[key] = [item.strip() for item in value.split(',')]
if key in ["fields", "data_types"]:
new_dict[key] = [item.strip() for item in value.split(",")]
else:
new_dict[key] = value
res = cls.from_dict(new_dict)
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/maxcompute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@


def quote_string(value: str) -> str:
value.replace('\'', "\\'")
value.replace("'", "\\'")
return f"'{value}'"


def quote_ref(value: str) -> str:
value.replace('`', "``")
value.replace("`", "``")
return f"`{value}`"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{%- set materialized_view = adapter.Relation.materialized_view_from_relation_config(config.model) -%}
{{ materialized_view.create_table_sql() }}
as ({{ sql }});
{% endmacro %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{{ exceptions.raise_compiler_error(
"maxcompute materialized view not support rename operation."
) }}
{% endmacro %}
{% endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/maxcompute/macros/relations/partition.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
{%- else -%}
partitioned by ({{ partition_config.render() }})
{%- endif -%}
{%- endmacro -%}
{%- endmacro -%}
2 changes: 1 addition & 1 deletion dbt/include/maxcompute/macros/utils/date_spine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@

select * from filtered

{% endmacro %}
{% endmacro %}
2 changes: 1 addition & 1 deletion tests/functional/adapter/test_materialized_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_view_replaces_materialized_view(self, project, my_materialized_view):
pass

def test_materialized_view_only_updates_after_refresh(
self, project, my_materialized_view, my_seed
self, project, my_materialized_view, my_seed
):
# poll database
table_start = self.query_row_count(project, my_seed)
Expand Down

0 comments on commit 3ff913c

Please sign in to comment.