Skip to content

Commit

Permalink
Merge branch 'develop' into dup-macro-message
Browse files Browse the repository at this point in the history
  • Loading branch information
jtcohen6 authored Mar 17, 2021
2 parents f4c7496 + 9a6d30f commit 369b595
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
- Fix variable `_dbt_max_partition` declaration and initialization for BigQuery incremental models ([#2940](https://github.com/fishtown-analytics/dbt/issues/2940), [#2976](https://github.com/fishtown-analytics/dbt/pull/2976))
- Moving from 'master' to 'HEAD' default branch in git ([#3057](https://github.com/fishtown-analytics/dbt/issues/3057), [#3104](https://github.com/fishtown-analytics/dbt/issues/3104), [#3117](https://github.com/fishtown-analytics/dbt/issues/3117)))
- Requirement on `dataclasses` is relaxed to be between `>=0.6,<0.9` allowing dbt to cohabit with other libraries which required higher versions. ([#3150](https://github.com/fishtown-analytics/dbt/issues/3150), [#3151](https://github.com/fishtown-analytics/dbt/pull/3151))
- Raise a proper error message if dbt parses a macro twice due to macro duplication or misconfiguration. ([#2449](https://github.com/fishtown-analytics/dbt/issues/2449))
- Add feature to add `_n` alias to same column names in SQL query ([#3147](https://github.com/fishtown-analytics/dbt/issues/3147), [#3158](https://github.com/fishtown-analytics/dbt/pull/3158))
- Raise a proper error message if dbt parses a macro twice due to macro duplication or misconfiguration. ([#2449](https://github.com/fishtown-analytics/dbt/issues/2449), [#3165](https://github.com/fishtown-analytics/dbt/pull/3165))

### Features
- Add optional configs for `require_partition_filter` and `partition_expiration_days` in BigQuery ([#1843](https://github.com/fishtown-analytics/dbt/issues/1843), [#2928](https://github.com/fishtown-analytics/dbt/pull/2928))
Expand All @@ -26,6 +27,7 @@ Contributors:
- [@pcasteran](https://github.com/pcasteran) ([#2976](https://github.com/fishtown-analytics/dbt/pull/2976))
- [@VasiliiSurov](https://github.com/VasiliiSurov) ([#3104](https://github.com/fishtown-analytics/dbt/pull/3104))
- [@bastienboutonnet](https://github.com/bastienboutonnet) ([#3151](https://github.com/fishtown-analytics/dbt/pull/3151))
- [@techytushar](https://github.com/techytushar) ([#3158](https://github.com/fishtown-analytics/dbt/pull/3158))
- [@cgopalan](https://github.com/cgopalan) ([#3165](https://github.com/fishtown-analytics/dbt/pull/3165))

## dbt 0.19.1 (Release TBD)
Expand Down
9 changes: 8 additions & 1 deletion core/dbt/adapters/sql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ def process_results(
column_names: Iterable[str],
rows: Iterable[Any]
) -> List[Dict[str, Any]]:

unique_col_names = dict()
for idx in range(len(column_names)):
col_name = column_names[idx]
if col_name in unique_col_names:
unique_col_names[col_name] += 1
column_names[idx] = f'{col_name}_{unique_col_names[col_name]}'
else:
unique_col_names[column_names[idx]] = 1
return [dict(zip(column_names, row)) for row in rows]

@classmethod
Expand Down
18 changes: 18 additions & 0 deletions test/unit/test_sql_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
from dbt.adapters.sql.connections import SQLConnectionManager

class TestProcessSQLResult(unittest.TestCase):
def test_duplicated_columns(self):
cols_with_one_dupe = ['a', 'b', 'a', 'd']
rows = [(1, 2, 3, 4)]
self.assertEqual(
SQLConnectionManager.process_results(cols_with_one_dupe, rows),
[{"a": 1, "b": 2, "a_2": 3, "d": 4}]
)

cols_with_more_dupes = ['a', 'a', 'a', 'b']
rows = [(1, 2, 3, 4)]
self.assertEqual(
SQLConnectionManager.process_results(cols_with_more_dupes, rows),
[{"a": 1, "a_2": 2, "a_3": 3, "b": 4}]
)

0 comments on commit 369b595

Please sign in to comment.