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: add event tables to sdk #2215

Merged
merged 8 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Client struct {
Databases Databases
DynamicTables DynamicTables
ExternalTables ExternalTables
EventTables EventTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Grants Grants
Expand Down Expand Up @@ -163,6 +164,7 @@ func (c *Client) initialize() {
c.Databases = &databases{client: c}
c.DynamicTables = &dynamicTables{client: c}
c.ExternalTables = &externalTables{client: c}
c.EventTables = &eventTables{client: c}
c.FailoverGroups = &failoverGroups{client: c}
c.FileFormats = &fileFormats{client: c}
c.Grants = &grants{client: c}
Expand Down
165 changes: 165 additions & 0 deletions pkg/sdk/event_tables_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package sdk

import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator"

sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
//go:generate go run ./poc/main.go

var eventTableSet = g.NewQueryStruct("EventTableSet").
OptionalNumberAssignment("DATA_RETENTION_TIME_IN_DAYS", g.ParameterOptions()).
OptionalNumberAssignment("MAX_DATA_EXTENSION_TIME_IN_DAYS", g.ParameterOptions()).
OptionalBooleanAssignment("CHANGE_TRACKING", g.ParameterOptions()).
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes())

var eventTableUnset = g.NewQueryStruct("EventTableUnset").
OptionalSQL("DATA_RETENTION_TIME_IN_DAYS").
OptionalSQL("MAX_DATA_EXTENSION_TIME_IN_DAYS").
OptionalSQL("CHANGE_TRACKING").
OptionalSQL("COMMENT")

var eventTableAddRowAccessPolicy = g.NewQueryStruct("EventTableAddRowAccessPolicy").
SQL("ADD").
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")

var eventTableDropRowAccessPolicy = g.NewQueryStruct("EventTableDropRowAccessPolicy").
SQL("DROP").
Identifier("RowAccessPolicy", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("ROW ACCESS POLICY").Required()).
WithValidation(g.ValidIdentifier, "RowAccessPolicy")

var eventTableDropAndAddRowAccessPolicy = g.NewQueryStruct("EventTableDropAndAddRowAccessPolicy").
QueryStructField("Drop", eventTableDropRowAccessPolicy, g.KeywordOptions().Required()).
QueryStructField("Add", eventTableAddRowAccessPolicy, g.KeywordOptions().Required())

var eventTableClusteringAction = g.NewQueryStruct("EventTableClusteringAction").
PredefinedQueryStructField("ClusterBy", "*[]string", g.KeywordOptions().Parentheses().SQL("CLUSTER BY")).
OptionalSQL("SUSPEND RECLUSTER").
OptionalSQL("RESUME RECLUSTER").
OptionalSQL("DROP CLUSTERING KEY")

var searchOptimization = g.NewQueryStruct("SearchOptimization").
SQL("SEARCH OPTIMIZATION").
PredefinedQueryStructField("On", "[]string", g.KeywordOptions().SQL("ON"))
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved

var eventTableSearchOptimizationAction = g.NewQueryStruct("EventTableSearchOptimizationAction").
OptionalQueryStructField(
"Add",
searchOptimization,
g.KeywordOptions().SQL("ADD"),
).
OptionalQueryStructField(
"Drop",
searchOptimization,
g.KeywordOptions().SQL("DROP"),
)

var EventTablesDef = g.NewInterface(
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
"EventTables",
"EventTable",
g.KindOfT[SchemaObjectIdentifier](),
).CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-event-table",
g.NewQueryStruct("CreateEventTable").
Create().
OrReplace().
SQL("EVENT TABLE").
IfNotExists().
Name().
NamedListWithParens("CLUSTER BY", g.KindOfT[string](), g.KeywordOptions()).
OptionalNumberAssignment("DATA_RETENTION_TIME_IN_DAYS", g.ParameterOptions()).
OptionalNumberAssignment("MAX_DATA_EXTENSION_TIME_IN_DAYS", g.ParameterOptions()).
OptionalBooleanAssignment("CHANGE_TRACKING", g.ParameterOptions()).
OptionalTextAssignment("DEFAULT_DDL_COLLATION", g.ParameterOptions().SingleQuotes()).
OptionalSQL("COPY GRANTS").
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
PredefinedQueryStructField("RowAccessPolicy", "*RowAccessPolicy", g.KeywordOptions()).
OptionalTags().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"),
).ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-event-tables",
g.DbStruct("eventTableRow").
Field("created_on", "time.Time").
Field("name", "string").
Field("database_name", "string").
Field("schema_name", "string").
Field("owner", "sql.NullString").
Field("comment", "sql.NullString").
Field("owner_role_type", "sql.NullString"),
g.PlainStruct("EventTable").
Field("CreatedOn", "time.Time").
Field("Name", "string").
Field("DatabaseName", "string").
Field("SchemaName", "string").
Field("Owner", "string").
Field("Comment", "string").
Field("OwnerRoleType", "string"),
g.NewQueryStruct("ShowEventTables").
Show().
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
SQL("EVENT TABLES").
OptionalLike().
OptionalIn().
OptionalStartsWith().
OptionalLimit(),
).ShowByIdOperation().DescribeOperation(
g.DescriptionMappingKindSingleValue,
"https://docs.snowflake.com/en/sql-reference/sql/desc-event-table",
g.DbStruct("eventTableDetailsRow").
Field("name", "string").
Field("kind", "string").
Field("comment", "string"),
g.PlainStruct("EventTableDetails").
Field("Name", "string").
Field("Kind", "string").
Field("Comment", "string"),
g.NewQueryStruct("DescribeEventTable").
Describe().
SQL("EVENT TABLE").
Name().
WithValidation(g.ValidIdentifier, "name"),
).DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-event-table",
Copy link
Collaborator

Choose a reason for hiding this comment

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

it should point to the drop table page (there's no such page as drop event table)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

g.NewQueryStruct("DropEventTable").
Drop().
SQL("TABLE").
IfExists().
Name().
OptionalSQL("RESTRICT"). // CASCADE or RESTRICT, and CASCADE for Default
WithValidation(g.ValidIdentifier, "name"),
).AlterOperation(
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
"https://docs.snowflake.com/en/sql-reference/sql/alter-event-table",
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
g.NewQueryStruct("AlterEventTable").
Alter().
SQL("TABLE").
IfNotExists().
Name().
OptionalQueryStructField(
"Set",
eventTableSet,
g.KeywordOptions().SQL("SET"),
).
OptionalQueryStructField(
"Unset",
eventTableUnset,
g.KeywordOptions().SQL("UNSET"),
).
OptionalQueryStructField("AddRowAccessPolicy", eventTableAddRowAccessPolicy, g.KeywordOptions()).
OptionalQueryStructField("DropRowAccessPolicy", eventTableDropRowAccessPolicy, g.KeywordOptions()).
OptionalQueryStructField("DropAndAddRowAccessPolicy", eventTableDropAndAddRowAccessPolicy, g.ListOptions().NoParentheses()).
OptionalSQL("DROP ALL ROW ACCESS POLICIES").
OptionalQueryStructField(
"ClusteringAction",
eventTableClusteringAction,
g.KeywordOptions(),
).
OptionalQueryStructField(
"SearchOptimizationAction",
eventTableSearchOptimizationAction,
g.KeywordOptions(),
).
OptionalSetTags().
OptionalUnsetTags().
Identifier("RenameTo", g.KindOfTPointer[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")).
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ExactlyOneValueSet, "RenameTo", "Set", "Unset", "SetTags", "UnsetTags", "AddRowAccessPolicy", "DropRowAccessPolicy", "DropAndAddRowAccessPolicy", "DropAllRowAccessPolicies", "ClusteringAction", "SearchOptimizationAction"),
)
Loading
Loading