Skip to content
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

Feat: Add plan option to show rendered model diff #3691

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

VaggelisD
Copy link
Contributor

Fixes #1254

The default behavior of plan diff is to compare raw models i.e the original queries & statements:

Differences from the `dev` environment:

Models:
└── Directly Modified:
    └── default__dev.test

--- 

+++ 

@@ -4,13 +4,13 @@

 CREATE TABLE IF NOT EXISTS foo AS
 (
   SELECT
-    @OR(FALSE, TRUE)
+    @AND(TRUE, NULL)
 )
 SELECT
-  4 + 2
+  5 + 2
 CREATE TABLE IF NOT EXISTS foo2 AS
 (
   SELECT
-    @AND(TRUE, FALSE)
+    @OR(TRUE, NULL)
 )
-DROP VIEW @this_model
+DROP VIEW IF EXISTS @this_model

This PR introduces the sqlmesh plan --rendered-model-diff which instead compares rendered queries/statements:

@@ -4,13 +4,13 @@

 CREATE TABLE IF NOT EXISTS "foo" AS
 (
   SELECT
-    FALSE OR TRUE
+    TRUE
 )
 SELECT
-  6 AS "_col_0"
+  7 AS "_col_0"
 CREATE TABLE IF NOT EXISTS "foo2" AS
 (
   SELECT
-    TRUE AND FALSE
+    TRUE
 )
-DROP VIEW "test"
+DROP VIEW IF EXISTS "test"

sqlmesh/core/context.py Outdated Show resolved Hide resolved
self,
include_python: bool = True,
include_defaults: bool = False,
render_model: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render_query

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and everywhere

Copy link
Contributor Author

@VaggelisD VaggelisD Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought render_model was more fitting because we'll also render it's statements along with the query, but don't have strong feelings about it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ makes sense to me.

Copy link
Contributor Author

@VaggelisD VaggelisD Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinging @izeigerman because this was resolved before, any final preference between the two?

@VaggelisD VaggelisD requested a review from a team January 23, 2025 17:55
@@ -335,6 +335,7 @@ Options:
application (prod environment only).
--enable-preview Enable preview for forward-only models when
targeting a development environment.
--rendered-model-diff Output text differences for the rendered versions of models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these docs are outdated? Isn't the option diff-rendered after the recent renaming? Standalone audits can be diffed as well.

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.

Add an option to sqlmesh plan to use rendered model queries for diffing
3 participants