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

Update readme cleanup dropif #2

Merged
merged 4 commits into from
Oct 28, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v.0.21.1

### Fixes

- removed log statements and an extra `firebolt__get_create_index_sql` macro error via [#2](https://github.com/firebolt-db/dbt-firebolt/pull/2)

## v.0.21.0

### Features
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ These fields are optional:

Note that, although the value of `type` is always `firebolt`, it must be included either in `profiles.yml` or in the dbt_project.yml file for your application.

Finally, multi-threading is not currently supported, so threads must be set to 1.

#### Example file:
```
my_project:
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/firebolt/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.21.0"
version = "0.21.1"
18 changes: 8 additions & 10 deletions dbt/adapters/firebolt/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,17 @@ def form_sing_val_col(string_val) -> agate.Formula:
@available.parse_none
def make_field_partition_pairs(self, columns, partitions) -> List[str]:
"""
Return a list of strings of form "column column_type PARTITION(regex)"
or "column column_type" if not partition exists for that column.
Columns with a partition must come at end of list.
Return a list of strings of form "column column_type" or
"column column_type PARTITION(regex)" where the partitions
fall at the end of the list.
"""
unpartitioned_columns = []
partitioned_columns = []
print('\n** make_field_partition_pairs')
print('partitions: ', partitions)
for column in columns:
unpartitioned_columns.append(self.quote(column['name'])
+ ' '
+ column['data_type']
)
if partitions: # partitions may be empty.
for partition in partitions:
partitioned_columns.append(self.quote(partition['name'])
Expand All @@ -181,11 +184,6 @@ def make_field_partition_pairs(self, columns, partitions) -> List[str]:
+ partition['regex']
+ "')"
)
for column in columns:
unpartitioned_columns.append(self.quote(column['name'])
+ ' '
+ column['data_type']
)
return unpartitioned_columns + partitioned_columns

@available.parse_none
Expand Down
91 changes: 28 additions & 63 deletions dbt/include/firebolt/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% do drop_relations_loop(tbls) %}
{% endmacro %}


{% macro drop_relations_loop(relations) %}
{% for row in relations %}
{%- set relation = api.Relation.create(database=target.database,
Expand Down Expand Up @@ -64,23 +65,6 @@
{% endmacro %}


{% macro firebolt__get_create_index_sql(relation, index_dict) -%}
{%- set index_config = adapter.parse_index(index_dict) -%}
{%- set index_name = index_config.render(relation) -%}
{%- set index_type = index_config.type | upper -%}

{%- if index_type == "JOIN" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE JOIN INDEX",
index_config.join_column, index_config.dimension_column) }}
{%- elif index_type == "AGGREGATING" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE AND GENERATE AGGREGATING INDEX",
index_config.key_column, index_config.aggregation) }}
{%- endif -%}
{%- endmacro %}


{% macro make_create_index_sql(relation,
index_name,
create_statement,
Expand All @@ -96,65 +80,46 @@
);
{%- endmacro %}


{% macro drop_index(index_name, index_type) -%}
{% call statement('drop_relation', auto_begin=False) -%}
DROP {{ index_type | upper }} INDEX "{{ index_name }}"
{%- endcall %}
{% endmacro %}

{% macro firebolt__get_create_index_sql(relation, index_dict) -%}
{%- set index_config = adapter.parse_index(index_dict) -%}
{%- set index_name = index_config.render(relation) -%}
{%- set index_type = index_config.type | upper -%}

{%- if index_type == "JOIN" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE JOIN INDEX",
index_config.join_column, index_config.dimension_column) }}
{%- elif index_type == "AGGREGATING" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE AND GENERATE AGGREGATING INDEX",
index_config.key_column, index_config.aggregation) }}
{%- endif -%}

{%- endmacro %}

{% macro make_create_index_sql(
relation, index_name, create_statement, spine_col, other_col) -%}
{% macro firebolt__get_create_index_sql(relation, index_dict) -%}
{%- set index_config = adapter.parse_index(index_dict) -%}
{%- set index_name = index_config.render(relation) -%}
{%- set index_type = index_config.type | upper -%}

{{ create_statement }} "{{ index_name }}" ON {{ relation }} (
{{ spine_col }},
{% if other_col is iterable and other_col is not string -%}
{{ other_col | join(', ') }}
{%- else -%}
{{ other_col }}
{%- if index_type == "JOIN" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE JOIN INDEX",
index_config.join_column, index_config.dimension_column) }}
{%- elif index_type == "AGGREGATING" -%}
{{ make_create_index_sql(
relation, index_name, "CREATE AND GENERATE AGGREGATING INDEX",
index_config.key_column, index_config.aggregation) }}
{%- endif -%}
);
{%- endmacro %}

{% macro drop_index(index_name, index_type) -%}

{% call statement('drop_relation', auto_begin=False) -%}
DROP {{ index_type | upper }} INDEX "{{ index_name }}"
{%- endcall %}
{% endmacro %}


{% macro firebolt__drop_relation(relation) -%}
{# drop non-primary indexes #}
{% if relation.type == 'table' %}
{% set idx_info_table = run_query('SHOW INDEXES;') %}
{% set idxs_tbl = adapter.filter_table(idx_info_table, 'table_name', relation.identifier) %}
{% set idxs_to_drop = adapter.filter_table(idxs_tbl, 'type', '^((?!primary).)*$') %}

{% for row in idxs_to_drop %}
{% do drop_index(row[0], row[2]) %}
{% endfor %}
{% endif %}

{% call statement('drop_relation', auto_begin=False) -%}
DROP {{ relation.type }} IF EXISTS {{ relation.identifier }}
{%- endcall %}
{# drop non-primary indexes #}
{% if relation.type == 'table' %}
{% set idx_info_table = run_query('SHOW INDEXES;') %}
{% set idxs_tbl = adapter.filter_table(idx_info_table, 'table_name', relation.identifier) %}
{% set idxs_to_drop = adapter.filter_table(idxs_tbl, 'type', '^((?!primary).)*$') %}

{% for row in idxs_to_drop %}
{% do drop_index(row[0], row[2]) %}
{% endfor %}
{% endif %}

{% call statement('drop_relation', auto_begin=False) -%}
DROP {{ relation.type }} IF EXISTS {{ relation.identifier }}
{%- endcall %}
{% endmacro %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
DROP TABLE IF EXISTS {{ source_node['name'] }}
{% endset %}
{{return(ddl)}}
{{ log(source_node ~ ' dropped.\n', True) }}
{% endmacro %}