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

Fix/handle query array types #2376

Merged
merged 1 commit into from
May 2, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Fix "Object of type Decimal is not JSON serializable" error when BigQuery queries returned numeric types in nested data structures ([#2336](https:/fishtown-analytics/dbt/issues/2336), [#2348](https:/fishtown-analytics/dbt/pull/2348))
- No longer query the information_schema.schemata view on bigquery ([#2320](https:/fishtown-analytics/dbt/issues/2320), [#2382](https:/fishtown-analytics/dbt/pull/2382))
- Add support for `sql_header` config in incremental models ([#2136](https:/fishtown-analytics/dbt/issues/2136), [#2200](https:/fishtown-analytics/dbt/pull/2200))
- Postgres array types can now be returned via `run_query` macro calls ([#2337](https:/fishtown-analytics/dbt/issues/2337), [#2376](https:/fishtown-analytics/dbt/pull/2376))

### Under the hood
- Added more tests for source inheritance ([#2264](https:/fishtown-analytics/dbt/issues/2264), [#2291](https:/fishtown-analytics/dbt/pull/2291))
Expand Down
5 changes: 4 additions & 1 deletion core/dbt/adapters/sql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def get_result_from_cursor(cls, cursor: Any) -> agate.Table:
rows = cursor.fetchall()
data = cls.process_results(column_names, rows)

return dbt.clients.agate_helper.table_from_data(data, column_names)
return dbt.clients.agate_helper.table_from_data_flat(
data,
column_names
)

def execute(
self, sql: str, auto_begin: bool = False, fetch: bool = False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

{% macro test_array_results() %}

{% set sql %}
select ARRAY[1, 2, 3, 4] as mydata
{% endset %}

{% set result = run_query(sql) %}
{% set value = result.columns['mydata'][0] %}

{# This will be json-stringified #}
{% if value != "[1, 2, 3, 4]" %}
{% do exceptions.raise_compiler_error("Value was " ~ value) %}
{% endif %}

{% endmacro %}
25 changes: 25 additions & 0 deletions test/integration/060_run_query_tests/test_pg_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

from test.integration.base import DBTIntegrationTest, use_profile
import json

class TestPostgresTypes(DBTIntegrationTest):

@property
def schema(self):
return "pg_query_types_060"

@property
def models(self):
return "models"

@property
def project_config(self):
return {
'config-version': 2,
'macro-paths': ['macros'],
}

@use_profile('postgres')
def test__postgres_nested_types(self):
result = self.run_dbt(['run-operation', 'test_array_results'])
self.assertTrue(result.success)