-
Notifications
You must be signed in to change notification settings - Fork 427
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: Add materialized view to the SDK #2403
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d42b7e6
Start materialized view definition
sfc-gh-asawicki 95c6088
Add materialized view alter definition
sfc-gh-asawicki fb7a89d
Add materialized view drop definition
sfc-gh-asawicki 51c93af
Add materialized view show definition
sfc-gh-asawicki 9936289
Add materialized view describe definition
sfc-gh-asawicki 49a3e95
Fix def
sfc-gh-asawicki e0eb4d8
Generate files for materialized views
sfc-gh-asawicki 590419c
Fix name for describe
sfc-gh-asawicki 8f27a12
Adjust show by id
sfc-gh-asawicki c22c0a3
Pass unit tests for create materialized view (WIP)
sfc-gh-asawicki b81acbc
Pass unit tests for create materialized view (with regenerate)
sfc-gh-asawicki b7d6cd0
Pass unit tests for alter materialized view (WIP)
sfc-gh-asawicki 07bf913
Pass unit tests for alter materialized view (WIP - after regeneration)
sfc-gh-asawicki 2a03b53
Pass unit tests for alter materialized view
sfc-gh-asawicki e035c2e
Pass unit tests for drop materialized view
sfc-gh-asawicki 970947d
Pass unit tests for show materialized views
sfc-gh-asawicki bbf72c7
Pass unit tests for desc materialized view
sfc-gh-asawicki 78c0c3b
Prepare integration test list
sfc-gh-asawicki 5c5dbb6
Implement show integration tests
sfc-gh-asawicki 2feda2c
Implement describe integration tests
sfc-gh-asawicki 3fa0657
Implement drop integration tests
sfc-gh-asawicki 4fe6daf
Implement create integration tests
sfc-gh-asawicki f9849cb
Implement half of alter integration tests
sfc-gh-asawicki 0437301
Implement alter integration tests
sfc-gh-asawicki a1e3fba
Fix linter complaints
sfc-gh-asawicki c552d5f
Merge branch 'main' into add-materialized-view-to-the-sdk
sfc-gh-asawicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package sdk | ||
|
||
import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" | ||
|
||
//go:generate go run ./poc/main.go | ||
|
||
var materializedViewColumn = g.NewQueryStruct("MaterializedViewColumn"). | ||
Text("Name", g.KeywordOptions().DoubleQuotes().Required()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes().NoEquals()) | ||
|
||
var materializedViewColumnMaskingPolicy = g.NewQueryStruct("MaterializedViewColumnMaskingPolicy"). | ||
Text("Name", g.KeywordOptions().Required()). | ||
Identifier("MaskingPolicy", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("MASKING POLICY").Required()). | ||
NamedListWithParens("USING", g.KindOfT[string](), nil). // TODO: double quotes here? | ||
OptionalTags() | ||
|
||
var materializedViewRowAccessPolicy = g.NewQueryStruct("MaterializedViewRowAccessPolicy"). | ||
Identifier("RowAccessPolicy", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("ROW ACCESS POLICY").Required()). | ||
NamedListWithParens("ON", g.KindOfT[string](), g.KeywordOptions().Required()). // TODO: double quotes here? | ||
WithValidation(g.ValidIdentifier, "RowAccessPolicy"). | ||
WithValidation(g.ValidateValueSet, "On") | ||
|
||
var materializedViewClusterByExpression = g.NewQueryStruct("MaterializedViewClusterByExpression"). | ||
Text("Name", g.KeywordOptions().DoubleQuotes().Required()) | ||
|
||
var materializedViewClusterBy = g.NewQueryStruct("MaterializedViewClusterBy"). | ||
SQL("CLUSTER BY"). | ||
ListQueryStructField("Expressions", materializedViewClusterByExpression, g.ListOptions().Parentheses()). | ||
WithValidation(g.ValidateValueSet, "Expressions") | ||
|
||
var materializedViewSet = g.NewQueryStruct("MaterializedViewSet"). | ||
OptionalSQL("SECURE"). | ||
OptionalComment(). | ||
WithValidation(g.ExactlyOneValueSet, "Secure", "Comment") | ||
|
||
var materializedViewUnset = g.NewQueryStruct("MaterializedViewUnset"). | ||
OptionalSQL("SECURE"). | ||
OptionalSQL("COMMENT"). | ||
WithValidation(g.ExactlyOneValueSet, "Secure", "Comment") | ||
|
||
var materializedViewDbRow = g.DbStruct("materializedViewDBRow"). | ||
Text("created_on"). | ||
Text("name"). | ||
OptionalText("reserved"). | ||
Text("database_name"). | ||
Text("schema_name"). | ||
OptionalText("cluster_by"). | ||
Number("rows"). | ||
Number("bytes"). | ||
Text("source_database_name"). | ||
Text("source_schema_name"). | ||
Text("source_table_name"). | ||
Time("refreshed_on"). | ||
Time("compacted_on"). | ||
Text("owner"). | ||
Bool("invalid"). | ||
OptionalText("invalid_reason"). | ||
Text("behind_by"). | ||
OptionalText("comment"). | ||
Text("text"). | ||
Bool("is_secure"). | ||
Text("automatic_clustering"). | ||
OptionalText("owner_role_type"). | ||
OptionalText("budget") | ||
|
||
var materializedView = g.PlainStruct("MaterializedView"). | ||
Text("CreatedOn"). | ||
Text("Name"). | ||
OptionalText("Reserved"). | ||
Text("DatabaseName"). | ||
Text("SchemaName"). | ||
Text("ClusterBy"). | ||
Number("Rows"). | ||
Number("Bytes"). | ||
Text("SourceDatabaseName"). | ||
Text("SourceSchemaName"). | ||
Text("SourceTableName"). | ||
Time("RefreshedOn"). | ||
Time("CompactedOn"). | ||
Text("Owner"). | ||
Bool("Invalid"). | ||
Text("InvalidReason"). | ||
Text("BehindBy"). | ||
Text("Comment"). | ||
Text("Text"). | ||
Bool("IsSecure"). | ||
Bool("AutomaticClustering"). | ||
Text("OwnerRoleType"). | ||
Text("Budget") | ||
|
||
var materializedViewDetailsDbRow = g.DbStruct("materializedViewDetailsRow"). | ||
Text("name"). | ||
Field("type", "DataType"). | ||
Text("kind"). | ||
Text("null"). | ||
OptionalText("default"). | ||
Text("primary key"). | ||
Text("unique key"). | ||
OptionalText("check"). | ||
OptionalText("expression"). | ||
OptionalText("comment") | ||
|
||
var materializedViewDetails = g.PlainStruct("MaterializedViewDetails"). | ||
Text("Name"). | ||
Field("Type", "DataType"). | ||
Text("Kind"). | ||
Bool("IsNullable"). | ||
OptionalText("Default"). | ||
Bool("IsPrimary"). | ||
Bool("IsUnique"). | ||
OptionalBool("Check"). | ||
OptionalText("Expression"). | ||
OptionalText("Comment") | ||
|
||
var MaterializedViewsDef = g.NewInterface( | ||
"MaterializedViews", | ||
"MaterializedView", | ||
g.KindOfT[SchemaObjectIdentifier](), | ||
). | ||
CreateOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/create-materialized-view", | ||
g.NewQueryStruct("CreateMaterializedView"). | ||
Create(). | ||
OrReplace(). | ||
OptionalSQL("SECURE"). | ||
SQL("MATERIALIZED VIEW"). | ||
IfNotExists(). | ||
Name(). | ||
OptionalCopyGrants(). | ||
ListQueryStructField("Columns", materializedViewColumn, g.ListOptions().Parentheses()). | ||
ListQueryStructField("ColumnsMaskingPolicies", materializedViewColumnMaskingPolicy, g.ListOptions().NoParentheses().NoEquals()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). | ||
OptionalQueryStructField("RowAccessPolicy", materializedViewRowAccessPolicy, g.KeywordOptions()). | ||
OptionalTags(). | ||
OptionalQueryStructField("ClusterBy", materializedViewClusterBy, g.KeywordOptions()). | ||
SQL("AS"). | ||
Text("sql", g.KeywordOptions().NoQuotes().Required()). | ||
WithValidation(g.ValidIdentifier, "name"). | ||
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"), | ||
). | ||
AlterOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/alter-materialized-view", | ||
g.NewQueryStruct("AlterMaterializedView"). | ||
Alter(). | ||
SQL("MATERIALIZED VIEW"). | ||
Name(). | ||
OptionalIdentifier("RenameTo", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). | ||
OptionalQueryStructField("ClusterBy", materializedViewClusterBy, g.KeywordOptions()). | ||
OptionalSQL("DROP CLUSTERING KEY"). | ||
OptionalSQL("SUSPEND RECLUSTER"). | ||
OptionalSQL("RESUME RECLUSTER"). | ||
OptionalSQL("SUSPEND"). | ||
OptionalSQL("RESUME"). | ||
OptionalQueryStructField("Set", materializedViewSet, g.KeywordOptions().SQL("SET")). | ||
OptionalQueryStructField("Unset", materializedViewUnset, g.KeywordOptions().SQL("UNSET")). | ||
WithValidation(g.ValidIdentifier, "name"). | ||
WithValidation(g.ExactlyOneValueSet, "RenameTo", "ClusterBy", "DropClusteringKey", "SuspendRecluster", "ResumeRecluster", "Suspend", "Resume", "Set", "Unset"), | ||
). | ||
DropOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/drop-materialized-view", | ||
g.NewQueryStruct("DropMaterializedView"). | ||
Drop(). | ||
SQL("MATERIALIZED VIEW"). | ||
IfExists(). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
ShowOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/show-materialized-views", | ||
materializedViewDbRow, | ||
materializedView, | ||
g.NewQueryStruct("ShowMaterializedViews"). | ||
Show(). | ||
SQL("MATERIALIZED VIEWS"). | ||
OptionalLike(). | ||
OptionalIn(), | ||
). | ||
ShowByIdOperation(). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSlice, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-materialized-view", | ||
materializedViewDetailsDbRow, | ||
materializedViewDetails, | ||
g.NewQueryStruct("DescribeMaterializedView"). | ||
Describe(). | ||
SQL("MATERIALIZED VIEW"). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does column actually allow comment? im having trouble finding it in the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this to the questions about the docs I post on doc-discuss.
You are right. It's not written in materialized view docs but in regular view ones. Also, there is a test proving that it can be done: https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/2403/files#diff-7a8a3cc00d490b622d152a5bdf42e0915fff497c2eb4554f491dfaaaa3d51025R124.