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

Updating a DynamicTable defintion fails with SQL compilation error: unexpected <EOF> #2134

Closed
rmargarint-nydig opened this issue Oct 19, 2023 · 4 comments · Fixed by #2192
Closed
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@rmargarint-nydig
Copy link

rmargarint-nydig commented Oct 19, 2023

Attempting to create dynamic tables through TF, however running into a show stopper bug.

The very first apply of the dynamic table succeeds without any problems.
But:

  • Every subsquent apply that attempts to update the resource fails with
│ Error: 001003 (42000): SQL compilation error:
│ syntax error line 1 at position 71 unexpected '<EOF>'.
│ 
│   with snowflake_dynamic_table.my_dyn_table,
│   on my_dynamic_tables.tf line 59, in resource "snowflake_dynamic_table" "my_dyn_table":
│   59: resource "snowflake_dynamic_table" "my_dyn_table" {
  • Every tf apply thinks it detects changes for dynamic tables even if nothing changed. It seems to be because it thinks there were external changes to the query of the DT that added some spacing to the start of it, even if there were no changes at all (the exact same tf apply reran back to back)
Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply":

  # snowflake_dynamic_table.my_dyn_table has changed
  ~ resource "snowflake_dynamic_table" "my_dyn_table" {
        id                   = "MY_DB|PUBLIC|MY_DYN_TABLE"
        name                 = "my_dyn_table"
      ~ query                = <<-EOT
          -     ---
          + ---
                select * from (
@rmargarint-nydig rmargarint-nydig added the bug Used to mark issues with provider's incorrect behavior label Oct 19, 2023
@mgarrett2008
Copy link

mgarrett2008 commented Oct 26, 2023

hi @rmargarint-nydig , I experienced same error.

@mgarrett2008
Copy link

hello @rmargarint-nydig , did you find a work around for this? We are still experiencing the same issue.

@sonya
Copy link
Contributor

sonya commented Nov 6, 2023

It looks like the syntax error happens because the query that's executed is this:

ALTER DYNAMIC TABLE "<database>"."<schema>"."<table>" SET

(database, schema, and table are placeholders -- the important feature is that there is nothing after SET)

This appears to happen when Terraform detects that there are changes but there are actually no changes.

A workaround is to introduce an innocuous change that Terraform will actually apply. For example, if the table's target lag is an hour, Snowflake harmonizes this to 1 hour. If this is specified in Terraform as 60 minutes, the terraform provider detects this as a change, and the following statement will always be applied

ALTER DYNAMIC TABLE "<database>"."<schema>"."<table>" SET TARGET_LAG = '60 minutes'

Despite being an unnecessary alter statement, this works around the <EOF> error.

We actually discovered this because we tried to get rid of the spurious change and realized we were depending on a bug.

@sfc-gh-asawicki
Copy link
Collaborator

Hey @rmargarint-nydig. Thanks for creating the issue.

Yes, it looks like a bug in the dynamic table resource. It is relatively easy to fix. I will work on it next week so that it will hopefully be ready for next Wednesday's release.

sfc-gh-asawicki added a commit that referenced this issue Nov 14, 2023
sfc-gh-asawicki added a commit that referenced this issue Nov 14, 2023
* Fix file format csv parameters config

Fixes #2176

* Fix show by id for dynamic table

Fixes #2173

* Add helper method

* Refactor test

* Fix 2134

Fixes #2134

* Fix 1947

Fixes #1947

* Fix fmt

* Fix after review
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

Successfully merging a pull request may close this issue.

4 participants