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

Unexpected formatting of array literals (BigQuery) #235

Closed
nfcampos opened this issue Aug 5, 2022 · 1 comment · Fixed by #238
Closed

Unexpected formatting of array literals (BigQuery) #235

nfcampos opened this issue Aug 5, 2022 · 1 comment · Fixed by #238
Labels
bug Something isn't working
Milestone

Comments

@nfcampos
Copy link

nfcampos commented Aug 5, 2022

Describe the bug
I'm not too particular about exactly how you format it, just definitely would prefer it doesn't start in the same line as the previous field, which to me look quite confusing

To Reproduce

select
    'xero' as billing_platform,
    [ invoice_id, invoice.invoice_number ] as billing_platform_references,
from hello

Expected behavior

select
    'xero' as billing_platform,
    [ invoice_id, invoice.invoice_number ] as billing_platform_references,
from hello

or

select
    'xero' as billing_platform,
    [
        invoice_id, invoice.invoice_number
    ] as billing_platform_references,
from hello

Actual behavior

select
    'xero' as billing_platform, [
        invoice_id, invoice.invoice_number
    ] as billing_platform_references,
from hello

Additional context
What is the output of sqlfmt --version?
Whatever is live on http://sqlfmt.com

@tconbeer
Copy link
Owner

tconbeer commented Aug 5, 2022

v0.10.0

Interesting, thanks for the report! I'm surprised this happens, since we get it right with parentheses:

-- formatted
select
    'xero' as billing_platform,
    (invoice_id, invoice.invoice_number) as billing_platform_references,
from hello

We also get it wrong when there is an operator (not a comma) in the brackets:

-- expected
select
    'xero' as billing_platform,
    [invoice_id + invoice.invoice_number] as billing_platform_references,
from hello

-- actual
select
    'xero' as billing_platform, [
        invoice_id + invoice.invoice_number
    ] as billing_platform_references,
from hello

I need to check (probably in merger.py::_maybe_stubbornly_merge), but it's possible we assume square brackets will follow a name (as the index operation), when clearly that isn't true.

@tconbeer tconbeer added the bug Something isn't working label Aug 5, 2022
@tconbeer tconbeer added this to the v0.11.0 milestone Aug 5, 2022
tconbeer added a commit that referenced this issue Aug 9, 2022
* fix #235: not all square brackets are array index operators

* chore: bump primer ref; add uncommitted test file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants