Skip to content

Commit

Permalink
[Feature][dbt] add partition_type support (apache#9389)
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice authored May 6, 2022
1 parent 86b7717 commit 7af79e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 7 additions & 1 deletion extension/dbt-doris/dbt/adapters/doris/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ class Engine(str, Enum):
iceberg = "iceberg"


class PartitionType(str, Enum):
list = "LIST"
range = "RANGE"


class DorisConfig(AdapterConfig):
engine: Engine = Engine.olap
engine: Engine
duplicate_key: Tuple[str]
partition_by: Tuple[str]
partition_type: PartitionType
partition_by_init: List[str]
distributed_by: Tuple[str]
buckets: int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@

{% macro doris__engine() -%}
{% set label = 'ENGINE' %}
{% set engine = config.get('engine', validator=validation.any[basestring]) %}
{% if engine is not none %}
{% set engine = config.get('engine', 'OLAP', validator=validation.any[basestring]) %}
{{ label }} = {{ engine }}
{% else %}
{{ label }} = OLAP
{% endif %}
{%- endmacro %}

{% macro doris__partition_by() -%}
{% set cols = config.get('partition_by') %}
{% set partition_type = config.get('partition_type', 'RANGE') %}
{% if cols is not none %}
PARTITION BY RANGE (
PARTITION BY {{ partition_type }} (
{% for col in cols %}
{{ col }}{% if not loop.last %},{% endif %}
{% endfor %}
)(
{% set init = config.get('partition_by_init',validator=validation.any[list]) %}
{% set init = config.get('partition_by_init', validator=validation.any[list]) %}
{% if init is not none %}
{% for row in init %}
{{ row }}{% if not loop.last %},{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
-- under the License.

{% macro doris__create_table_as(temporary, relation, sql) -%}
{% set sql_header = config.get('sql_header', none) %}

{{ sql_header if sql_header is not none }}
create table {{ relation.include(database=False) }}
{% set sql_header = config.get('sql_header', none) %}
{% set table = relation.include(database=False) %}
{{ sql_header if sql_header is not none }}
create table {{ table }}
{{ doris__partition_by() }}
{{ doris__distributed_by() }}
{{ doris__properties() }} as {{ sql }}
{{ doris__properties() }} as {{ sql }};
insert into {{ table }} {{ sql }};
{%- endmacro %}

0 comments on commit 7af79e1

Please sign in to comment.