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]: Case Sensitive snowflake_procedure_sql variables #3298

Closed
1 task
jdoldis opened this issue Dec 16, 2024 · 4 comments
Closed
1 task

[Bug]: Case Sensitive snowflake_procedure_sql variables #3298

jdoldis opened this issue Dec 16, 2024 · 4 comments
Labels
docs Used to mark issues with documentation remark/questions resource:procedure_sql

Comments

@jdoldis
Copy link
Contributor

jdoldis commented Dec 16, 2024

Terraform CLI Version

1.9.8

Terraform Provider Version

0.100.0

Company Name

No response

Terraform Configuration

resource "snowflake_procedure_sql" "proc_create_stream_data_table" {
  name                = "TEST_PROCEDURE"
  database            = "<database>"
  schema              = "<schema>"
  comment             = "Test procedure"
  return_type         = "VARCHAR"
  execute_as          = "CALLER"
  null_input_behavior = "RETURNS NULL ON NULL INPUT"
  arguments {
    arg_name      = "schema_name"
    arg_data_type = "varchar"
  }
  arguments {
    arg_name      = "table_name"
    arg_data_type = "varchar"
  }
  procedure_definition = <<EOT
  DECLARE
    source_table STRING;
    target_table STRING;
  BEGIN
    source_table := 'database.' || schema_name || '.' || table_name;
    RETURN 'Success';
  END;
  EOT
}

Category

category:resource

Object type(s)

No response

Expected Behavior

CALL <database>.<schema>.TEST_PROCEDURE('test', 'test'); returns Success.

Actual Behavior

CALL <database>.<schema>.TEST_PROCEDURE('test', 'test'); gives error Error: invalid identifier 'SCHEMA_NAME' (line 13).

Steps to Reproduce

Create the resource with the above config, and run CALL <database>.<schema>.TEST_PROCEDURE('test', 'test');.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

It seems the arguments in the procedure signature are defined with double quotes. The create statement from the above configuration -

CREATE OR REPLACE PROCEDURE <database>.<schema>.TEST_PROCEDURE("schema_name" VARCHAR(16777216), "table_name" VARCHAR(16777216))
RETURNS VARCHAR(16777216)
LANGUAGE SQL
STRICT
COMMENT='Test procedure'
EXECUTE AS CALLER
AS '  DECLARE
    source_table STRING;
    target_table STRING;
  BEGIN
    source_table := ''database.'' || schema_name || ''.'' || table_name;
    RETURN ''Success'';
  END;
';

I verified on the console that removing the double quotes from the procedure signature and then calling returns Success as expected.

In addition, it seems quoting schema_name and table_name in the procedure definition of the resource fixes the issue -

resource "snowflake_procedure_sql" "proc_create_stream_data_table" {
  name                = "TEST_PROCEDURE"
  database            = "<database>"
  schema              = "<schema>"
  comment             = "Test procedure"
  return_type         = "VARCHAR"
  execute_as          = "CALLER"
  null_input_behavior = "RETURNS NULL ON NULL INPUT"
  arguments {
    arg_name      = "schema_name"
    arg_data_type = "varchar"
  }
  arguments {
    arg_name      = "table_name"
    arg_data_type = "varchar"
  }
  procedure_definition = <<EOT
  DECLARE
    source_table STRING;
    target_table STRING;
  BEGIN
    source_table := 'database.' || "schema_name" || '.' || "table_name";
    RETURN 'Success';
  END;
  EOT

I don't think this was necessary in previous versions of the provider, as calling the procedure worked previously.

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@jdoldis jdoldis added the bug Used to mark issues with provider's incorrect behavior label Dec 16, 2024
@jdoldis jdoldis changed the title [Bug]: snowflake_procedure_sql argument syntax error [Bug]: snowflake_procedure_sql argument casing Dec 16, 2024
@jdoldis jdoldis changed the title [Bug]: snowflake_procedure_sql argument casing [Bug]: Case sensitive snowflake_procedure_sql variables Dec 16, 2024
@jdoldis jdoldis changed the title [Bug]: Case sensitive snowflake_procedure_sql variables [Bug]: Case Sensitive snowflake_procedure_sql variables Dec 16, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @jdoldis 👋

You are right - this happens because arg_name is quoted (by the provider) and is actually lowercase in this example, but it is not quoted in the definition. The behavior is expected. Please either use uppercase arg_name or quote the arg name in procedure_definition.

I think this is related to all resources with fields like body, definition, etc. We will add a note to the documentation for the relevant resources.

@sfc-gh-jmichalak sfc-gh-jmichalak added docs Used to mark issues with documentation remark/questions and removed bug Used to mark issues with provider's incorrect behavior labels Dec 17, 2024
@jdoldis
Copy link
Contributor Author

jdoldis commented Dec 17, 2024

Perfect, thanks @sfc-gh-jmichalak !

sfc-gh-asawicki added a commit that referenced this issue Dec 20, 2024
- Update docs and migration guide
- Bump tracking version
- Fix method usage after merge (method has been removed)
- Fix whitespace
- Fix link
- Improve function and procedure examples (multiline)

References: #3303 #3302 #3298
sfc-gh-asawicki added a commit that referenced this issue Dec 20, 2024
- Update docs and migration guide
- Bump tracking version
- Fix method usage after merge (method has been removed)
- Fix whitespace
- Fix link
- Improve function and procedure examples (multiline)

References: #3303 #3302 #3298
@sfc-gh-asawicki
Copy link
Collaborator

Hey @jdoldis. We have released v1.0.1 on Friday. We added clarifications in the migration guide and the registry docs. Please check if the docs are clearer now.

@jdoldis
Copy link
Contributor Author

jdoldis commented Dec 27, 2024

Looks great @sfc-gh-asawicki , will close this issue thanks 🙂

@jdoldis jdoldis closed this as completed Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Used to mark issues with documentation remark/questions resource:procedure_sql
Projects
None yet
Development

No branches or pull requests

3 participants