-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Sql commands with same column name to dbt rpc produce weird results in table #3147
Comments
Thanks @nave91! I think this is a dupe of #2625, but you've provided much more detail here, the reproduction case is even weirder, and I'm better equipped to investigate this now than I was last summer. I don't actually think this is an RPC bug; I think it's a more foundational bug with And it's possible to reproduce this using {% if execute %}
{% set my_bad_query %}
select 1 as a, 2 as b, 3 as a, 4 as d
{% endset %}
{% set results = run_query(my_bad_query) %}
{{ results.column_names }}
{% for row in results %}
{{ row }}
{% endfor %}
{% endif %} And compiling it:
After a little more digging, it looks like the culprit here I popped > /Users/jerco/dev/product/dbt/core/dbt/adapters/sql/connections.py(105)process_results()
104
--> 105 return [dict(zip(column_names, row)) for row in rows]
106
ipdb> column_names
['a', 'b', 'a', 'd']
ipdb> rows
[(1, 2, 3, 4)]
ipdb> for row in rows:
dict(zip(column_names, row))
{'a': 3, 'b': 2, 'd': 4} It's not possible to have a dictionary with two keys both named The full array of ipdb> dbt.clients.agate_helper.table_from_data_flat(
data,
column_names
).print_table()
| a | b | a_2 | d |
| - | - | --- | - |
| 3 | 2 | 4 | | I think the |
Aah! My bad, I could've added details to that existing ticket. I'll keep in mind to look for existing tickets before creating a new one. Thank you for clarifying the details there @jtcohen6! |
@nave91 All good, thanks for writing up such a detailed issue! You really helped to clue me into what's going on here. And if, in your boundless free time, you ever want to contribute a few clever lines of python, now there's a clear place to do it ;) |
Signed-off-by: Tushar Mittal <[email protected]>
Feature to add _n alias to same column names #3147
Describe the bug
When we run sql like
select 1 as a, 2 as b, 3 as a, 4 as d
produces weird table results as shown in screenshot below.Steps To Reproduce
dbt rpc
.Result looks something like below and we are looking for
table
keyExpected behavior
Result should've been:
Screenshots and log output
Output of dbt rpc:
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
macOS Catalina 10.15.7
The output of
python --version
:Python 3.7.4
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: