Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

DBT should have a Dry-Run mode #1059

Closed
mikekaminsky opened this issue Oct 13, 2018 · 17 comments
Closed

DBT should have a Dry-Run mode #1059

mikekaminsky opened this issue Oct 13, 2018 · 17 comments

Comments

@mikekaminsky
Copy link
Contributor

DBT should have a dry-run mode

Feature description

DBT should have a dry-run mode so that users can see all of the "commands" DBT will run for a given command without having DBT actually execute those commands against a database.

Who will this benefit?

This can be useful for both debugging as well as making sure that a given command is configured properly. This is especially useful when you're configuring a production setup and want to make sure you're not about to drop schemas or tables you didn't intend to.

It can also be useful for testing macros and other DBT configurations that are post-compilation but don't show up in the compiled SQL

@mikekaminsky
Copy link
Contributor Author

So, I took a look at dbt/adapters/default/impl.py to see how hard this might be and I don't think I have enough context on why some things are implemented the way they are to take a stab at this myself without some guidance.

I can see that the add_query method is where the statements get executed (cursor.execute(sql, bindings) but there's a bunch of other stuff happening in here I don't understand (I suspect a lot of it is related to handling multiple connections).

In case it's helpful to see where my head is going, the way I've implemented this in the past is to have two functions for executing SQL. One for commands (no results returned) and one for queries (returning data) -- this way your read and write operations are split.

Then, for the dry-run mode, you can put some logic in the command-handling function that just logs the command instead of passing it to cur.execute(). Something like:


def run_command(sql):
    print(sql)
    if not DRY_RUN:
        self.cur.execute(sql)

def get_data(sql):
    print(sql)
    self.cur.execute(sql)
    result = cur.fetchall()
    return result

@drewbanin drewbanin added this to the Wilt Chamberlain milestone Nov 28, 2018
@hui-zheng
Copy link

yes, I vote to have the dry-run feature, which will be super helpful for debug and performance tuning

@cmcarthur cmcarthur removed this from the Wilt Chamberlain milestone May 1, 2019
@thalesmello
Copy link

@cmcarthur What's the reasoning for this to be removed from the milestone?

@drewbanin
Copy link
Contributor

Hi @thalesmello - this is a pretty involved change to dbt! Connor and I tried to prioritize it for the Wilt Chamberlain release (0.14.0), but we ended up deciding to cull it in favor of Archive-related functionality. This feature is definitely going to be a big improvement to dbt - I'm looking forward to re-prioritizing it!

@thalesmello
Copy link

Thanks for the explanation @drewbanin 👍

@christopher-tin
Copy link

+1 as well to adding a dry run feature such as a dbt compile --all command

@darrenhaken
Copy link
Contributor

Any movement on this?

@giovanni-girelli-sdg
Copy link

Hello everyone!
Any progress on this? I think being able to see the actual sql that will be executed is quite the important feature.

@alepuccetti
Copy link
Contributor

@giovanni-girelli-sdg To see the actual SQL that dbt will execute you can use dbt compile https://docs.getdbt.com/reference/commands/compile/.

@giovanni-girelli-sdg
Copy link

giovanni-girelli-sdg commented Aug 11, 2020

Hi @alepuccetti! thanks for the reply, but there you can only see the SELECT statement. What I'd like to see is the actual SQL that will run, such as a MERGE, INSERT or CREATE statement.

Edit at least it's what I can find. Is there a way to see the full materialization code?

Edit2: I had not seen the target/run folder, that's enough for debugging in DEV. I still think it would be great to be able to have a dry run mode where no sql is actually executed, but I can see how that would be much harder to do. Thanks for the great work!

@bhtucker
Copy link

bhtucker commented Sep 1, 2020

@mikekaminsky you opened this on my birthday!

@davidsr2r
Copy link

+1 to this, especially if it allowed the calculation of the cost of the run, and allowed prevention of the run if the cost was too high unless a --force argument was used.

@y-tee
Copy link

y-tee commented Jan 14, 2021

+1

@the-davidsn
Copy link

+1

1 similar comment
@fclesio
Copy link

fclesio commented May 27, 2021

+1

@giovanni-girelli-sdg
Copy link

giovanni-girelli-sdg commented May 27, 2021 via email

@rabidaudio
Copy link

For some reason when searching for this I found #281 but not this issue.

I'm posting about it here with the link so that a reference will show up on the old PR, in case someone else finds the old PR.

@dbt-labs dbt-labs locked and limited conversation to collaborators Dec 8, 2021
@jtcohen6 jtcohen6 converted this issue into discussion #4456 Dec 8, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests