Skip to content

Bug: Select of functions get reordered, breaking comments and whole query #917

Open
@quassy

Description

@quassy

What Happened

playground

SELECT
    name AS name1,
    name2,  -- my fav function
    FAVORITE('%y%m%j', exit_date) AS quite_long_column_name,
    -- my newest function    NEWEST('%y%m%j', exit_date)
        AS quite_long_column_name,
    PARSE_DATE('%y%m%j', exit_date) AS quite_long_column_name
FROM users

locally with v0.19.0

SELECT
    name AS name1,
    name2,  -- my fav function
    FAVORITE('%y%m%j', exit_date) AS quite_long_column_name,
    -- my newest function
    NEWEST('%y%m%j', exit_date) AS quite_long_column_name,
    PARSE_DATE('%y%m%j', exit_date) AS quite_long_column_name,
FROM USERS

Expected Behaviour

  1. Column order should not be changed (just because some columns use a function).
  2. Inline comments should keep their context.
  3. Long lines with a comment should not break the resulting SQL (only reproducible in playground).

How to reproduce

SELECT 
    name AS name1,
    FAVORITE('%y%m%j', exit_date) AS quite_long_column_name,  -- my fav function
    NEWEST('%y%m%j', exit_date) AS quite_long_column_name,  -- my newest function
    PARSE_DATE('%y%m%j', exit_date) AS quite_long_column_name,
    name2
from USERS

Configuration

[sqruff]
dialect = bigquery
rules = all

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions