Skip to content

Add macro to support introspection on semantic view - #13

Draft
sfc-gh-yutliu wants to merge 2 commits into
mainfrom
yutliu-fix-issue-5
Draft

Add macro to support introspection on semantic view#13
sfc-gh-yutliu wants to merge 2 commits into
mainfrom
yutliu-fix-issue-5

Conversation

@sfc-gh-yutliu

@sfc-gh-yutliu sfc-gh-yutliu commented Nov 5, 2025

Copy link
Copy Markdown
Collaborator

Root cause:
DBT adapter does not support semantic view, so snowflake__get_columns_in_relation will fail if taking a semantic view as argument.

Solution:
Add customization macro of snowflake__get_columns_in_relation in dbt_semantic_view package to return empty column list instead of go to default describe table <semantic_view> to avoid Invalid object type: 'TABLE' issue.

Caveat:
customers need to add search_order: [dbt_semantic_view, dbt] (see dbt_project.yml change in this pr) to make the package override take precedent of dbt's implementation.

Tests:

  • Without customized macro and overriding the search_order: [dbt_semantic_view, dbt], running macro debug_call_get_columns will fail.
(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) ✗ dbt run-operation debug_call_get_columns --args '{"model_name": "semantic_view_basic"}'
23:38:27  Running with dbt=1.9.4
23:38:28  Registered adapter: snowflake=1.9.2
23:38:28  Unable to do partial parsing because saved manifest not found. Starting full parse.
23:38:29  Found 10 models, 10 data tests, 1 seed, 2 operations, 2 sources, 601 macros
23:38:30  Encountered an error while running operation: Database Error
  002030 (42601): SQL compilation error:
  Invalid object type: 'TABLE'
(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) ✗ 

Running model dbt run --models union_table_refer_to_semantic_views will fail.

(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) ✗ dbt run --models union_table_refer_to_semantic_views 
00:14:04  Running with dbt=1.9.4
00:14:05  Registered adapter: snowflake=1.9.2
00:14:05  Unable to do partial parsing because saved manifest not found. Starting full parse.
00:14:06  Found 11 models, 10 data tests, 1 seed, 2 operations, 2 sources, 601 macros
00:14:06  
00:14:06  Concurrency: 4 threads (target='snowflake')
00:14:06  
00:14:20  1 of 2 START hook: dbt_semantic_view_integration_tests.on-run-start.0 .......... [RUN]
00:14:20  1 of 2 OK hook: dbt_semantic_view_integration_tests.on-run-start.0 ............. [OK in 1.74s]
00:14:20  2 of 2 START hook: dbt_semantic_view_integration_tests.on-run-start.1 .......... [RUN]
00:14:20  2 of 2 OK hook: dbt_semantic_view_integration_tests.on-run-start.1 ............. [OK in 0.43s]
00:14:20  
00:14:20  1 of 1 START sql table model yutliu.union_table_refer_to_semantic_views ........ [RUN]
00:14:20  1 of 1 ERROR creating sql table model yutliu.union_table_refer_to_semantic_views  [ERROR in 0.16s]
00:14:21  
00:14:21  Finished running 2 project hooks, 1 table model in 0 hours 0 minutes and 14.97 seconds (14.97s).
00:14:21  
00:14:21  Completed with 1 error, 0 partial successes, and 0 warnings:
00:14:21  
00:14:21    Database Error in model union_table_refer_to_semantic_views (models/union_table_refer_to_semantic_views.sql)
  002030 (42601): SQL compilation error:
  Invalid object type: 'TABLE'
00:14:21  
00:14:21  Done. PASS=2 WARN=0 ERROR=1 SKIP=0 TOTAL=3
(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) ✗ 
  • With customized macro and overriding the search_order: [dbt_semantic_view, dbt], running macro debug_call_get_columns will succeed.
(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) dbt run-operation debug_call_get_columns --args '{"model_name": "semantic_view_basic"}'
00:09:27  Running with dbt=1.9.4
00:09:27  Registered adapter: snowflake=1.9.2
00:09:28  Found 11 models, 10 data tests, 1 seed, 2 operations, 2 sources, 601 macros
00:09:29  override test -> temp.yutliu.semantic_view_basic columns=0
(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) 

Running model dbt run --models union_table_refer_to_semantic_views will fail, but not the error Invalid object type: 'TABLE'.

(custom_vemv) ➜  integration_tests git:(yutliu-fix-issue-5) dbt run --models union_table_refer_to_semantic_views                                   
00:11:45  Running with dbt=1.9.4
00:11:46  Registered adapter: snowflake=1.9.2
00:11:46  Found 11 models, 10 data tests, 1 seed, 2 operations, 2 sources, 601 macros
00:11:46  
00:11:46  Concurrency: 4 threads (target='snowflake')
00:11:46  
00:11:59  1 of 2 START hook: dbt_semantic_view_integration_tests.on-run-start.0 .......... [RUN]
00:11:59  1 of 2 OK hook: dbt_semantic_view_integration_tests.on-run-start.0 ............. [OK in 1.87s]
00:11:59  2 of 2 START hook: dbt_semantic_view_integration_tests.on-run-start.1 .......... [RUN]
00:11:59  2 of 2 OK hook: dbt_semantic_view_integration_tests.on-run-start.1 ............. [OK in 0.26s]
00:11:59  
00:11:59  1 of 1 START sql table model yutliu.union_table_refer_to_semantic_views ........ [RUN]
00:12:00  1 of 1 ERROR creating sql table model yutliu.union_table_refer_to_semantic_views  [ERROR in 1.06s]
00:12:01  
00:12:01  Finished running 2 project hooks, 1 table model in 0 hours 0 minutes and 15.11 seconds (15.11s).
00:12:01  
00:12:01  Completed with 1 error, 0 partial successes, and 0 warnings:
00:12:01  
00:12:01    Database Error in model union_table_refer_to_semantic_views (models/union_table_refer_to_semantic_views.sql)
  000002 (0A000): Unsupported feature 'SELECT FROM SEMANTIC VIEW'.
  compiled code at target/run/dbt_semantic_view_integration_tests/models/union_table_refer_to_semantic_views.sql
00:12:01  
00:12:01  Done. PASS=2 WARN=0 ERROR=1 SKIP=0 TOTAL=3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant