Skip to content

Fix: Don't rewrite_casts for for subclasses like JSONCast#5805

Open
cory2067 wants to merge 1 commit into
SQLMesh:mainfrom
cory2067:fix-json-cast
Open

Fix: Don't rewrite_casts for for subclasses like JSONCast#5805
cory2067 wants to merge 1 commit into
SQLMesh:mainfrom
cory2067:fix-json-cast

Conversation

@cory2067
Copy link
Copy Markdown

Description

I noticed a bug in sqlmesh format when working with the ClickHouse dialect. The rewrite_casts option will rewrite exp.JSONCast (the .: operator) to ::, which changes the semantics of the query.

For example,

-- input query
SELECT foo.:String, CAST(bar AS String)

-- expected result
SELECT foo.:String, bar::String

-- observed result
SELECT foo::String, bar::String

This adds a one-line fix by only rewriting exp.Cast itself and not subclasses like exp.JSONCast.

Test Plan

Add unit test for the formatter that makes sure exp.JSONCast is not rewritten, but exp.Cast is still rewritten

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: Cory Lynch <cjl2625@gmail.com>
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