Skip to content

Commit

Permalink
Merge pull request #2 from firebolt-db/update_readme_cleanup_dropif
Browse files Browse the repository at this point in the history
Update readme cleanup dropif
  • Loading branch information
ima-hima authored Oct 28, 2021
2 parents 7b14189 + 6522db0 commit 69faaa4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 75 deletions.
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
1 change: 0 additions & 1 deletion dbt/include/firebolt/macros/dbt_external_tables/dropif.sql
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 %}

0 comments on commit 69faaa4

Please sign in to comment.