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

[Bug]: Function with multiline statement adds \n and fails #3089

Closed
1 task
epmenard-ia opened this issue Sep 18, 2024 · 2 comments
Closed
1 task

[Bug]: Function with multiline statement adds \n and fails #3089

epmenard-ia opened this issue Sep 18, 2024 · 2 comments
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@epmenard-ia
Copy link

epmenard-ia commented Sep 18, 2024

Terraform CLI Version

1.9.4

Terraform Provider Version

0.95.0

Terraform Configuration

resource "snowflake_function" "TEST_PARSER_VOLATILE_FUNC" {
  database = local.databases[var.DATABASE]
  schema = snowflake_schema.TEST_PARSER.name
  name = "VOLATILE_FUNC"

  arguments {
    name = "D"
    type = "DATE"
  }

  return_type = "TABLE (\"EVENT_DATE\" DATE, \"CITY\" VARCHAR(16777216), \"TEMPERATURE\" NUMBER(38,0))"
  language = "sql"
  
  statement = <<-EOT
AS '
SELECT d, ''New York'', 65.0
UNION ALL
SELECT d, ''Los Angeles'', 69.0
';
EOT
}

Category

category:resource

Object type(s)

resource:function

Expected Behavior

  # snowflake_function.TEST_PARSER_VOLATILE_FUNC will be created
  + resource "snowflake_function" "TEST_PARSER_VOLATILE_FUNC" {
      + comment              = "user-defined function"
      + database             = "DB_DPT_DEV_STG"
      + fully_qualified_name = (known after apply)
      + id                   = (known after apply)
      + is_secure            = false
      + language             = "sql"
      + name                 = "VOLATILE_FUNC"
      + null_input_behavior  = "CALLED ON NULL INPUT"

      + return_type          = "TABLE (\"EVENT_DATE\" DATE, \"CITY\" VARCHAR(16777216), \"TEMPERATURE\" NUMBER(38,0))"
      + schema               = "TEST_PARSER"
      + statement            = <<-EOT
            AS '
            SELECT d, ''New York'', 65.0
            UNION ALL
            SELECT d, ''Los Angeles'', 69.0
            ';
        EOT

      + arguments {
          + name = "D"
          + type = "DATE"
        }
    }

Actual Behavior

provider adds a return_behavior defaulted to VOLATILE.

  # snowflake_function.TEST_PARSER_VOLATILE_FUNC will be created
  + resource "snowflake_function" "TEST_PARSER_VOLATILE_FUNC" {
      + comment              = "user-defined function"
      + database             = "DB_DPT_DEV_STG"
      + fully_qualified_name = (known after apply)
      + id                   = (known after apply)
      + is_secure            = false
      + language             = "sql"
      + name                 = "VOLATILE_FUNC"
      + null_input_behavior  = "CALLED ON NULL INPUT"
      + return_behavior      = "VOLATILE"
      + return_type          = "TABLE (\"EVENT_DATE\" DATE, \"CITY\" VARCHAR(16777216), \"TEMPERATURE\" NUMBER(38,0))"
      + schema               = "TEST_PARSER"
      + statement            = <<-EOT
            AS '
            SELECT d, ''New York'', 65.0
            UNION ALL
            SELECT d, ''Los Angeles'', 69.0
            ';
        EOT

      + arguments {
          + name = "D"
          + type = "DATE"
        }
    }

Apply fails

│ Error: 001003 (42000): SQL compilation error:
│ syntax error line 1 at position 86 unexpected 'VOLATILE'.
│ 
│   with snowflake_function.TEST_PARSER_VOLATILE_FUNC,
│   on test_parser.functions.volatile_func.tf line 1, in resource "snowflake_function" "TEST_PARSER_VOLATILE_FUNC":
│    1: resource "snowflake_function" "TEST_PARSER_VOLATILE_FUNC" {
│ 
╵

Steps to Reproduce

  1. Copy Configuration
  2. update database and schema params
  3. run apply

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@epmenard-ia epmenard-ia added the bug Used to mark issues with provider's incorrect behavior label Sep 18, 2024
@epmenard-ia epmenard-ia changed the title [Bug]: Function with no return_behaviour defaults to volatile and fails [Bug]: Function with multiline statement adds \n and fails Sep 18, 2024
@epmenard-ia epmenard-ia closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

sfc-gh-jmichalak commented Sep 19, 2024

Hi @epmenard-ia 👋

You closed this issue. Is it still relevant? Functions are currently being reworked, so we'll take a look at this issue then.

Also, as @sfc-gh-jcieslak noticed, your configuration has null_input_behavior, which is not supported for SQL functions (docs).

cc @sfc-gh-asawicki

@epmenard-ia
Copy link
Author

epmenard-ia commented Sep 19, 2024 via email

@sfc-gh-jmichalak sfc-gh-jmichalak self-assigned this Oct 23, 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
Projects
None yet
Development

No branches or pull requests

2 participants