Skip to content

[Bug]: dbt --empty produces incorrect sql #309

Description

@jens-koster

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

using the --empty option seems to injects a table alias into the model code, this makes the sql broken if you already have a table alias for the ref() or source() statement.

Expected Behavior

dbt-dremio should compile correct sql (omitting the generated "alias"):

model stg_test2:
select * from {{ref('stg_test1')}} as boom

command:
dbt run -s stg_test2 --empty

compiled sql:
select * from (select * from "space"."trooper"."stg_test1" where false limit 0) as boom

Steps To Reproduce

model stg_test2:
select * from {{ref('stg_test1')}} as boom

command:
dbt run -s stg_test2 --empty

compiled sql:
select * from (select * from "space"."trooper"."stg_test1" where false limit 0) _dbt_limit_subq_stg_test1 as boom

dremio error: Encountered "as" at line 1, column 107.

the _dbt_limit_subq_stg_test1 alias should not be there.

Environment

os: macos sequoia 15.6.1
Core:
  - installed: 1.10.10
Plugins:
  - dremio: 1.9.0 - Up to date!

Relevant log output

11:53:04  Failure in model stg_test2 (models/staging/stg_test2.sql)
11:53:04    Runtime Error in model stg_test2 (models/staging/stg_test2.sql)
  ERROR: Encountered "as" at line 6, column 159.
  Was expecting one of:
      <EOF> 
      "," ...
      "ORDER" ...
      "LIMIT" ...
      "OFFSET" ...
      "FETCH" ...
      ";" ...
      "NATURAL" ...
      "JOIN" ...
      "INNER" ...
      "LEFT" ...
      "RIGHT" ...
      "FULL" ...
      "CROSS" ...
      "OUTER" ...
      "(" ...
      "TABLESAMPLE" ...
      "WHERE" ...
      "GROUP" ...
      "HAVING" ...
      "QUALIFY" ...
      "WINDOW" ...
      "UNION" ...
      "INTERSECT" ...
      "EXCEPT" ...
      "MINUS" ...
      
11:53:04  
11:53:04    compiled code at target/compiled/template/models/staging/stg_test2.sql
11:53:04  
11:53:04  Done. PASS=1 WARN=0 ERROR=1 SKIP=0 NO-OP=0 TOTAL=2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions