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

Provider tries to set column collation when changing numeric types. #2588

Open
MattMcFahn opened this issue Mar 5, 2024 · 4 comments
Open
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:table Issue connected to the snowflake_table resource

Comments

@MattMcFahn
Copy link

MattMcFahn commented Mar 5, 2024

Terraform CLI and Provider Versions

Terraform v1.5.7
on darwin_arm64

Provider version: 0.87.0

Terraform Configuration

# variables.tf
variable "snowflake_account_id" {
  type = string
}
variable "snowflake_role" {
  type = string
}
variable "snowflake_user" {
  type = string
}
variable "password" {
  type = string
}

# terraform.tf
terraform {
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "0.87.0"
    }
  }
}

provider "snowflake" {
  account       = var.snowflake_account_id
  role          = var.snowflake_role
  user          = var.snowflake_user
  password      = var.password
}

# database.tf
resource "snowflake_database" "db" {
  name = "SOME_DB"
}

resource "snowflake_schema" "schema" {
  name = "SOME_SCHEMA"
  database = snowflake_database.db.name
}

resource "snowflake_table" "table" {
  name = "SOME_TABLE"
  schema = snowflake_schema.schema.name
  database = snowflake_database.db.name

  column {
    name    = "SOME_COLUMN"
    type    = "NUMBER(38,0)"
  }
}

Expected Behavior

Apply the configuration as-is to create a new database, schema and table are created in the relevant snowflake account.

The table has one column, SOME_COLUMN, which has type NUMBER(38,0).

Then change the column type to e.g. NUMBER(36,0), and re-apply.

Expectation:

  • The column's data type is modified appropriately.

Actual Behavior

The column fails to modify with the following message:

image

Steps to Reproduce

  1. terraform apply
  2. Change NUMBER(38,0) to NUMBER(36,0)
  3. Re run terraform apply

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

Introduced in the upgrade from 0.86.0 to 0.87.0, by #2496. We also can't use 0.86.0 due to this issue: #2535

@MattMcFahn MattMcFahn added the bug Used to mark issues with provider's incorrect behavior label Mar 5, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

Hey, @MattMcFahn 👋 Thanks for reporting the issue.
I'll take a look at it this week.

@MattMcFahn
Copy link
Author

Thanks @sfc-gh-jcieslak ! I'll try and find some time to look myself also.

I think it might also be related to where analogous types have been converted internally. E.g. when we're specifying type as NUMBER, for example, this gets converted to NUMBER(38,0), and we then get the collation issue.

We've been able to work around this by identifying what the conversion will be and specifying that in the first instance - e.g. using NUMBER(38,0) rather than NUMBER, FLOAT rather than REAL. Given we've got the workaround I've moved the impact down.

@sfc-gh-jcieslak
Copy link
Collaborator

sfc-gh-jcieslak commented Mar 6, 2024

Number != Number(38,0) issue comes from the fact that Snowflake doesn't return the same value we're specifying. E.g. when you create a column with the type TEXT Snowflake in the SHOW command will return some kind of VARCHAR(...) (same for Number turning into Number(38,0)). Collation issue may come from this pr (#2496) where we added collation, specifically, you can look into the UpdateTable function which handles state Updates (e.g. NUMBER(38,0) to NUMBER(36,0) type change).

sfc-gh-jcieslak added a commit that referenced this issue Mar 11, 2024
Fix for #2588
In the alter column call collate was always added which caused the error
non-text (and probably text too) data types

## Test Plan
<!-- detail ways in which this PR has been tested or needs to be tested
-->
* [x] test case for data type alter

## References
* [ALTER
TABLE](https://docs.snowflake.com/en/sql-reference/sql/alter-table)
@sfc-gh-jcieslak sfc-gh-jcieslak self-assigned this Mar 11, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

Hey, the fix was recently released. Please see if the issue has been resolved in the latest version of the provider. Thanks :)

@sfc-gh-jcieslak sfc-gh-jcieslak added resource:table Issue connected to the snowflake_table resource category: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

2 participants