Skip to content

CLI flag --output-to-lower on Snowflake database does not respect alphabetical sort order on adding new columns #309

@FrankTub

Description

@FrankTub

We use dbt-osmosis versus a Snowflake database. The columns and tables are all in upper case and since we started our project with lower case, we prefer to keep it that way.

The exact command we use is (where --output-to-lower is relevant to this issue):

dbt-osmosis yaml document --skip-add-source-columns --output-to-lower --skip-merge-meta

We also prefer to keep the schema files alphabetical ordered so it is less often reordered due to how SQL is written. To do so I have added for example this in my dbt_project.yml

models:
...
  +dbt-osmosis-sort-by: "alphabetical"

That all works as expected, but not in one case. This issue can be reproduced with the following steps:

  • Make sure an existing model is alphabetically ordered in your schema file.
  • Modify your dbt_project.yml like above
  • Add a new column that is not expected to be the top column in your schema file to the model and create it in your target by running dbt.
  • Run the dbt osmosis command like mentioned before and observe that the column is added at the top, this is not correct
  • Run the dbt osmosis command again and observe that this time the column is placed in the correct location, this is as it should be.

Example

Starting schema.yml:

version: 2
models:
  - name: my_model
    description: Some description
    columns:
      - name: already_available_column
        description: Blabla
        data_type: varchar

Now add a column like test and create it in the database and run dbt-osmosis yaml document --skip-add-source-columns --output-to-lower --skip-merge-meta. The output will be:

version: 2
models:
  - name: my_model
    description: Some description
    columns:
      - name: test
        description: Some more bla
      - name: already_available_column
        description: Blabla
        data_type: varchar

Run command dbt-osmosis yaml document --skip-add-source-columns --output-to-lower --skip-merge-meta again and now the output is as it should be:

version: 2
models:
  - name: my_model
    description: Some description
    columns:
      - name: already_available_column
        description: Blabla
        data_type: varchar
      - name: test
        description: Some more bla

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions