You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sqlserver__get_columns_in_query was added by @qed- in #56 as basically a near copy of the base adapter version get_columns_in_query I'm working on it for the workaround suggested by the venerable @jtcohen6 in microsoft/dbt-synapse#40.
TL;DR
The return statement below isn't working because:
accessing the .columns attr of load_result().table throws and error, and
when I can get an Agate table I can't access the column column and make it into a list
Running with dbt=0.19.0-rc2
Encountered an error:
Compilation Error in model anders (models/marts/core/anders.sql)
'None' has no attribute 'table'
> in macro sqlserver__get_columns_in_query (macros/adapters.sql)
> called by model anders (models/marts/core/anders.sql)
attempts to fix
1) adding log information
I commented out the replaced the return statement with these logs. below is the result
table:
| column | data_type |
| ---------- | --------- |
| id | Number |
| user_id | Number |
| order_date | Number |
| status | Number |
coverted_columns:
[]
output:
[]
17:49:06 | Done.
3) access first column of Agate table
I thought I could copy this pattern form the Agate docs to get the column column table.columns[0] or table.columns['column']. Fail again with the same original error:
'None' has no attribute 'table'
Which peeves me to no end bc you can see that result.table is an agate.table.Table object!
4) debug in an ipython term to figure out how to properly query Agate table...
I tried to use {{ debug() }} but got an error that debug is undefined.
I saw the note in the docs about setting DBT_MACRO_DEBUGGING
I ran export DBT_MACRO_DEBUGGING=1
I call dbt compile and get No module named ipdb`
pip install ipdb
No module named ipdb`
open this GitHub issue.
The text was updated successfully, but these errors were encountered:
dataders
changed the title
sqlserver__get_columns_in_query not working in at least azuresql
sqlserver__get_columns_in_query not working
Jan 23, 2021
@swanderz This is one of the most confusing things in dbt-Jinja, and it has to do with execute (docs). Basically, during dbt's first step-through of your project—when it's just trying to capture ref, source, and config to build the DAG and determine run order—it does not run any SQL, so any Jinja objects that are defined via call blocks are simply set to None. You can tell dbt to ignore these objects during the first step-through with execute.
This could be addressed in your reproduction case, anders.sql:
{% set select_sql ='select * from ' ~ ref('raw_orders') %}
{% if execute %}
{% set output = sqlserver__get_columns_in_query(select_sql) %}
{{ log('output:\n' ~ output, info=True) }}
{% endif %}
I suppose you could add an if execute filter directly within sqlserver__get_columns_in_query, too, though it doesn't look like the default implementation does that today either.
background
sqlserver__get_columns_in_query
was added by @qed- in #56 as basically a near copy of the base adapter versionget_columns_in_query
I'm working on it for the workaround suggested by the venerable @jtcohen6 in microsoft/dbt-synapse#40.TL;DR
The return statement below isn't working because:
.columns
attr ofload_result().table
throws and error, andcolumn
column and make it into a listdbt-sqlserver/dbt/include/sqlserver/macros/adapters.sql
Lines 6 to 15 in 4b3f7bc
reproduction
in the https://github.com/dbt-msft/jaffle_shop_mssql/, I make a dummy model for testing that looks like this (after running
dbt seed
)environment
installed
dbt-sqlserver
in develop mode (pip install -e .
) from lastest commit of master branch (full list of packages installed)anders.sql
error
full stacktrace
attempts to fix
1) adding log information
I commented out the replaced the return statement with these logs. below is the result
full log
2) using
sqlserver__get_columns_from_relation()
's return syntaxsqlserver__get_columns_from_relation()
's return syntax works fine withSo I tried that, but
sql_convert_columns_in_relation()
expects each column to be a row, soconverted_columns
is an empty list.3) access first column of Agate table
I thought I could copy this pattern form the Agate docs to get the
column
columntable.columns[0]
ortable.columns['column']
. Fail again with the same original error:Which peeves me to no end bc you can see that
result.table
is anagate.table.Table
object!4) debug in an ipython term to figure out how to properly query Agate table...
{{ debug() }}
but got an error thatdebug
is undefined.DBT_MACRO_DEBUGGING
export DBT_MACRO_DEBUGGING=1
dbt compile
and getNo module named
ipdb`pip install ipdb
No module named
ipdb`The text was updated successfully, but these errors were encountered: