Skip to content

Commit

Permalink
First round of feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-codaio committed Jun 24, 2024
1 parent 8f8d243 commit b27b382
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/resources/cortex_search_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func UpdateCortexSearchService(d *schema.ResourceData, meta interface{}) error {
func DeleteCortexSearchService(d *schema.ResourceData, meta interface{}) error {
client := meta.(*provider.Context).Client
id := helpers.DecodeSnowflakeID(d.Id()).(sdk.SchemaObjectIdentifier)
request := sdk.NewDropCortexSearchServiceRequest(id)
request := sdk.NewDropCortexSearchServiceRequest(id).WithIfExists(true)

if err := client.CortexSearchServices.Drop(context.Background(), request); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/cortex_search_services_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var CortexSearchServiceDef = g.NewInterface(
PredefinedQueryStructField("QueryDefinition", "string", g.ParameterOptions().NoEquals().NoQuotes().Required().SQL("AS")).
// Validations
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidateValueSet, "On").
WithValidation(g.ValidateValueSet, "TargetLag").
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"),
Expand Down Expand Up @@ -102,7 +101,7 @@ var CortexSearchServiceDef = g.NewInterface(
Field("Attributes", "[]string").
Field("ServiceUrl", "string").
Field("NumRowsIndexed", "*int").
Field("Comment", "string"),
OptionalText("Comment"),
g.NewQueryStruct("DescribeCortexSearchService").
Describe().
SQL("CORTEX SEARCH SERVICE").
Expand All @@ -114,6 +113,7 @@ var CortexSearchServiceDef = g.NewInterface(
// Fields
Drop().
SQL("CORTEX SEARCH SERVICE").
IfExists().
Name().
WithValidation(g.ValidIdentifier, "name"),
)
5 changes: 5 additions & 0 deletions pkg/sdk/cortex_search_services_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sdk/cortex_search_services_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ type DescribeCortexSearchServiceRequest struct {
}

type DropCortexSearchServiceRequest struct {
name SchemaObjectIdentifier // required
IfExists *bool
name SchemaObjectIdentifier // required
}
9 changes: 2 additions & 7 deletions pkg/sdk/cortex_search_services_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type CreateCortexSearchServiceOptions struct {
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
QueryDefinition string `ddl:"parameter,no_quotes,no_equals" sql:"AS"`
}

type Attributes struct {
attributes bool `ddl:"static" sql:"ATTRIBUTES"`
Columns []string `ddl:"list,no_parentheses,no_equals"`
Expand All @@ -42,7 +41,6 @@ type AlterCortexSearchServiceOptions struct {
name SchemaObjectIdentifier `ddl:"identifier"`
Set *CortexSearchServiceSet `ddl:"keyword" sql:"SET"`
}

type CortexSearchServiceSet struct {
TargetLag *string `ddl:"parameter,single_quotes" sql:"TARGET_LAG"`
Warehouse *AccountObjectIdentifier `ddl:"identifier,equals" sql:"WAREHOUSE"`
Expand All @@ -58,15 +56,13 @@ type ShowCortexSearchServiceOptions struct {
StartsWith *string `ddl:"parameter,single_quotes,no_equals" sql:"STARTS WITH"`
Limit *LimitFrom `ddl:"keyword" sql:"LIMIT"`
}

type cortexSearchServiceRow struct {
CreatedOn time.Time `db:"created_on"`
Name string `db:"name"`
DatabaseName string `db:"database_name"`
SchemaName string `db:"schema_name"`
Comment string `db:"comment"`
}

type CortexSearchService struct {
CreatedOn time.Time
Name string
Expand All @@ -85,7 +81,6 @@ type DescribeCortexSearchServiceOptions struct {
cortexSearchService bool `ddl:"static" sql:"CORTEX SEARCH SERVICE"`
name SchemaObjectIdentifier `ddl:"identifier"`
}

type cortexSearchServiceDetailsRow struct {
Name string `db:"name"`
Schema string `db:"schema"`
Expand All @@ -98,7 +93,6 @@ type cortexSearchServiceDetailsRow struct {
NumRowsIndexed int `db:"num_rows_indexed"`
Comment string `db:"comment"`
}

type CortexSearchServiceDetails struct {
Name string
Schema string
Expand All @@ -109,12 +103,13 @@ type CortexSearchServiceDetails struct {
Attributes []string
ServiceUrl string
NumRowsIndexed *int
Comment string
Comment *string
}

// DropCortexSearchServiceOptions is based on https://docs.snowflake.com/LIMITEDACCESS/cortex-search/sql/drop-cortex-search.
type DropCortexSearchServiceOptions struct {
drop bool `ddl:"static" sql:"DROP"`
cortexSearchService bool `ddl:"static" sql:"CORTEX SEARCH SERVICE"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name SchemaObjectIdentifier `ddl:"identifier"`
}
7 changes: 6 additions & 1 deletion pkg/sdk/cortex_search_services_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ func (r *CreateCortexSearchServiceRequest) toOpts() *CreateCortexSearchServiceOp
Comment: r.Comment,
QueryDefinition: r.QueryDefinition,
}

if r.Attributes != nil {
opts.Attributes = &Attributes{
Columns: r.Attributes.Columns,
}
}

return opts
}

Expand All @@ -82,13 +84,15 @@ func (r *AlterCortexSearchServiceRequest) toOpts() *AlterCortexSearchServiceOpti
IfExists: r.IfExists,
name: r.name,
}

if r.Set != nil {
opts.Set = &CortexSearchServiceSet{
TargetLag: r.Set.TargetLag,
Warehouse: r.Set.Warehouse,
Comment: r.Set.Comment,
}
}

return opts
}

Expand Down Expand Up @@ -121,7 +125,8 @@ func (r cortexSearchServiceDetailsRow) convert() *CortexSearchServiceDetails {

func (r *DropCortexSearchServiceRequest) toOpts() *DropCortexSearchServiceOptions {
opts := &DropCortexSearchServiceOptions{
name: r.name,
IfExists: r.IfExists,
name: r.name,
}
return opts
}
3 changes: 0 additions & 3 deletions pkg/sdk/cortex_search_services_validations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ func (opts *CreateCortexSearchServiceOptions) validate() error {
if !ValidObjectIdentifier(opts.name) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if !ValidObjectIdentifier(opts.name) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if !valueSet(opts.On) {
errs = append(errs, errNotSet("CreateCortexSearchServiceOptions", "On"))
}
Expand Down

0 comments on commit b27b382

Please sign in to comment.