tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
399 stars 16 forks source link

sqlfmt incorrect reformatted JSON access path, breaking all accesses. #568

Closed jlucas91 closed 6 months ago

jlucas91 commented 6 months ago

Describe the bug We store json blobs within columns throughout our data pipeline. We'll then parse the JSON blob's field/values into their own columns in later stages. sqlfmt incorrectly lowercased the access path when retrieving data from the JSON blob. This lead to all accesses silently failing.

To Reproduce Given the original snippet:

with test as (
    select
        cast(json:source_payload:orderId as varchar) as order_id,
    from source
)
select *
from test

sqlfmt formats to:

with
    test as (
        select cast(json:source_payload:orderid as varchar) as order_id, from source
    )
select *
from test

Note that orderId has become orderid. This is not a safe fix.

Expected behavior Only safe formatting fixes should be performed.

Actual behavior The json access path is broken.

Additional context sqlfmt, version 0.21.2

tconbeer commented 6 months ago

This duplicates https://github.com/tconbeer/sqlfmt/issues/269

Please see that issue and the related note about the "help wanted" tag