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

feat: Stream on table resource #3109

Merged
merged 12 commits into from
Oct 9, 2024
Merged

feat: Stream on table resource #3109

merged 12 commits into from
Oct 9, 2024

Conversation

sfc-gh-jmichalak
Copy link
Collaborator

@sfc-gh-jmichalak sfc-gh-jmichalak commented Oct 1, 2024

  • add snowflake_stream_on_table resource
  • add LastQueryId to the context client
  • add a helper to insert data in a table - this is needed to track data in streams
  • extract common code to be reused in other stream resources
  • add a new function to parse a list of schema-level object identifiers
  • use enums in streams sdk
  • add a note to CHANGES_BEFORE_V1 explaining support of COPY GRANTS
  • minor docs fixes

Test Plan

  • acceptance tests

References

https://docs.snowflake.com/en/sql-reference/sql/create-stream

TODO

Add remaining resources (external table, stage, view). Rework data source.

Copy link

github-actions bot commented Oct 1, 2024

Integration tests failure for 66bd22b103e4ff516a40f9da7ce174abf8a78629

@sfc-gh-jmichalak sfc-gh-jmichalak marked this pull request as ready for review October 1, 2024 12:44
Copy link

github-actions bot commented Oct 1, 2024

Integration tests failure for c67968c20a4f56b0c6e02df2909021f83c8e5041

pkg/resources/stream_on_table.go Outdated Show resolved Hide resolved
}

if v := d.Get("copy_grants"); v.(bool) {
req.WithCopyGrants(true).WithOrReplace(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is OrReplace needed here? It allows for possible overriding of already existing stream, without it the task will use OrReplace only when modified attribute cannot be altered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed because otherwise when you have COPY GRANTS without OR REPLACE, Snowflake fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about the need for orReplace needed with copy grants but I am with @sfc-gh-jcieslak here: we should steer the copy grants logic, and use it only when we need to replace the stream and not by default in create

Copy link
Collaborator Author

@sfc-gh-jmichalak sfc-gh-jmichalak Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use OR REPLACE by default. It's used when the stream is already in the state, and detect changes on fields that can't be updated, because ForceNew drops the grants. In the second case, when it's not in the state, and the user wants COPY GRANTS to preserve old grants. In other cases, we don't use OR REPLACE.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with the second case. IMO a new create should be done without copy grants and without or replace. Thge assumption should be, that if we are creating a new object, the copy grants do not matter. Copy grants should be used only in the first scenario you mentioned (so the object is already managed and we discover changes).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed again.

pkg/schemas/stream.go Outdated Show resolved Hide resolved
pkg/schemas/stream_gen.go Outdated Show resolved Hide resolved
pkg/sdk/parsers.go Show resolved Hide resolved
pkg/sdk/parsers_test.go Show resolved Hide resolved
pkg/sdk/streams_def.go Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Oct 2, 2024

Integration tests cancelled for d61356336d2253d924befc0e47db4006421c81b4

Copy link

github-actions bot commented Oct 2, 2024

Integration tests failure for c1f7c234fcd8962531b2672c8f10191f471b0ae3

MIGRATION_GUIDE.md Show resolved Hide resolved
}

if v := d.Get("copy_grants"); v.(bool) {
req.WithCopyGrants(true).WithOrReplace(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about the need for orReplace needed with copy grants but I am with @sfc-gh-jcieslak here: we should steer the copy grants logic, and use it only when we need to replace the stream and not by default in create

pkg/resources/stream_on_table.go Outdated Show resolved Hide resolved
pkg/schemas/stream_gen.go Show resolved Hide resolved
pkg/sdk/streams_def.go Show resolved Hide resolved
table, cleanupTable := acc.TestClient().Table.CreateWithChangeTracking(t)
t.Cleanup(cleanupTable)

baseModel := func() *model.StreamOnTableModel {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could be added as Base(id, table_id) func in _ext.go file for model

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I'll leave this for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? For consistency we should have a way of defining a default/common base for model.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll do this in the next pr.

Copy link

github-actions bot commented Oct 3, 2024

Integration tests failure for bb56ac99ba21c82519f5a5a17a498893f2acc4cf

Copy link

github-actions bot commented Oct 3, 2024

Integration tests failure for 5ba98dd58fa3be86e55c8e4bfcb4061d2eaded4a

pkg/resources/stream_common.go Show resolved Hide resolved
pkg/resources/stream_on_table.go Outdated Show resolved Hide resolved
pkg/schemas/stream.go Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 72e29d3f49ebc019e54bac1384b9e203210b15d9

Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 7cb18a96e580feb3bd49e1734ade447c8f735ae3

Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 08c9c852fe81b9a76f4d76583ed4ea66cf195f10

Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 81dec99a87740624ce17a68afb3914dc5f43a9a3

Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 5a16dd94cdd87b082fcb66aede700b9bed79e0da

@@ -63,7 +63,7 @@ resource "snowflake_stream_on_table" "stream" {
- `at` (Block List, Max: 1) This field specifies that the request is inclusive of any changes made by a statement or transaction with a timestamp equal to the specified parameter. Due to Snowflake limitations, the provider does not detect external changes on this field. External changes for this field won't be detected. In case you want to apply external changes, you can re-create the resource manually using "terraform taint". (see [below for nested schema](#nestedblock--at))
- `before` (Block List, Max: 1) This field specifies that the request refers to a point immediately preceding the specified parameter. This point in time is just before the statement, identified by its query ID, is completed. Due to Snowflake limitations, the provider does not detect external changes on this field. External changes for this field won't be detected. In case you want to apply external changes, you can re-create the resource manually using "terraform taint". (see [below for nested schema](#nestedblock--before))
- `comment` (String) Specifies a comment for the stream.
- `copy_grants` (Boolean) Retains the access permissions from the original stream when a new stream is created using the OR REPLACE clause. Use only if the resource is already managed by Terraform.
- `copy_grants` (Boolean) Retains the access permissions from the original stream when a new stream is created using the OR REPLACE clause. Use only if the resource is already managed by Terraform. Otherwise, this field is skipped.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the description of this field to something similar to:
Retains the access permissions from the original stream when a new stream is created using the OR REPLACE clause that is sometimes used when updating the stream. The value won't have any effect when creating a new stream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll rephrase this in the next pr.

@sfc-gh-jmichalak sfc-gh-jmichalak merged commit 97fa9b4 into main Oct 9, 2024
8 of 9 checks passed
@sfc-gh-jmichalak sfc-gh-jmichalak deleted the stream-v1 branch October 9, 2024 10:52
sfc-gh-jcieslak pushed a commit that referenced this pull request Oct 11, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.97.0](v0.96.0...v0.97.0)
(2024-10-10)


### 🎉 **What's new:**

* Add secret to sdk
([#3091](#3091))
([7430aee](7430aee))
* Add service user and legacy service user resources
([#3119](#3119))
([0e88e08](0e88e08))
* Handle all Task parameters in SDK
([#3103](#3103))
([08ae072](08ae072))
* Stream on external table resource
([#3122](#3122))
([d837341](d837341))
* Stream on table resource
([#3109](#3109))
([97fa9b4](97fa9b4))
* Tasks v1 readiness - SDK part
([#3086](#3086))
([0a77383](0a77383))
* Upgrade stream sdk
([#3105](#3105))
([ad5fa11](ad5fa11))


### 🔧 **Misc**

* Add pre check to each datasource
([#3065](#3065))
([560ab6b](560ab6b))
* Bump golang-ci lint to 1.61
([#3112](#3112))
([f23e085](f23e085))
* Secret Validation change
([#3111](#3111))
([666630e](666630e))


### 🐛 **Bug fixes:**

* Fix parsing text in view, check parenthesis in
ParseSchemaObjectIdentifierWithArguments
([#3102](#3102))
([b0a67e6](b0a67e6))
* Try to reproduce 2679 and 3117
([#3124](#3124))
([ccdbc30](ccdbc30))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: snowflake_stream show_initial_rows = true is reset at every apply
3 participants