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

Parsing error of cluster_by value containing an expression #2110

Closed
buwi opened this issue Oct 10, 2023 · 5 comments
Closed

Parsing error of cluster_by value containing an expression #2110

buwi opened this issue Oct 10, 2023 · 5 comments
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:table Issue connected to the snowflake_table resource

Comments

@buwi
Copy link

buwi commented Oct 10, 2023

Provider Version

0.72.0

Terraform Version

v1.5.2

Describe the bug

I am using Terragrunt to manage state in AWS S3. It appears, the Snowflake provider is parsing the cluster_by value in the wrong place when it contains an expression.

For a table definition:

resource "snowflake_table" "sample-table" {
  database        = snowflake_schema.mydb-my_schema.database
  schema          = snowflake_schema.mydb-my_schema.name
  name              = local.sample-table_name
  cluster_by      = ["date_trunc('HOUR',TIMESTAMP_HR)","CLIENT_ID"]
  comment        = "..."
  change_tracking = false

  column {
    name     = "CLIENT_ID"
    type     = "VARCHAR(16777216)"
  }
  
  column {
    name     = "TIMESTAMP_HR"
    type     = "TIMESTAMP_TZ(9)"
  }
  
...

The initial run of terraform created the table successfully, with the correct cluster_by definition.

CLUSTERING_KEY: LINEAR(date_trunc('HOUR', TIMESTAMP_HR), CLIENT_ID)

But the state file contained the cluster_by as follows:

            "cluster_by": [
              "date_trunc('HOUR'",
              "TIMESTAMP_HR)",
              "CLIENT_ID"
            ],

On a subsequent run of Terraform, the cluster_by was identified as a change.

  
  Terraform will perform the following actions:

  # snowflake_table.sample-table will be updated in-place
  ~ resource "snowflake_table" "sample-table" {
      ~ cluster_by      = [
          - "date_trunc('HOUR'",
          - "TIMESTAMP_HR)",
          + "date_trunc('HOUR',TIMESTAMP_HR)",
            "CLIENT_ID",
        ]
        id              = "MYDB|MY_SCHEMA|MY_TABLE"
        name            = "MY_TABLE"
        # (6 unchanged attributes hidden)

        # (36 unchanged blocks hidden)
    }

Expected behavior

The state file should store the cluster_by definition as follows.

            "cluster_by": [
              "date_trunc('HOUR',TIMESTAMP_HR)",
              "CLIENT_ID"
            ],

Code samples and commands

Additional context

sample-table_name  ="MY_TABLE"
@buwi buwi added the bug Used to mark issues with provider's incorrect behavior label Oct 10, 2023
@meinczinger
Copy link

same issue here, it seems ClusterStatementToList just splits on ',' - with this issue the table object is not usable

@WojtekWaga
Copy link

Same here it misinterprets all values with a space inside:

 ~ cluster_by          = [
      - "left(data:session_id",
      - "4)",
      + "left(data:session_id, 4)",
    ]


  ~ cluster_by          = [
        "data:device_info:vehicle_id::varchar",
      - "date_trunc('month'",
      - "data:observed_at::timestamp_ltz(3))",
      + "date_trunc('month', data:observed_at::timestamp_ltz(3))",
    ]

@buwi
Copy link
Author

buwi commented Feb 21, 2024

Related issue : #2495

sfc-gh-asawicki added a commit that referenced this issue Feb 23, 2024
sfc-gh-asawicki added a commit that referenced this issue Feb 26, 2024
- Fixed clustering for table_resource (clustering with nested functions
are parsed correctly now)
- Adjusted view resource (`copy_grants` require `or_replace`) and
corrected the documentation

References: #2110 #2495 #2519
@sfc-gh-asawicki
Copy link
Collaborator

Hey @buwi @meinczinger @WojtekWaga. We have released the fix as part of v0.87.0 release. Please follow the migration guide during the update. Please confirm that the issue is resolved in the newest version. Thanks!

@sfc-gh-asawicki
Copy link
Collaborator

Closing as completed.

@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:table Issue connected to the snowflake_table resource labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:table Issue connected to the snowflake_table resource
Projects
None yet
Development

No branches or pull requests

5 participants