From a0f9ccdf90b127d39958f4e8d7e47c67ece91bea Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Sun, 3 Dec 2023 23:42:37 -0800 Subject: [PATCH] update procedures --- pkg/sdk/common_types.go | 28 + pkg/sdk/poc/generator/keyword_builders.go | 4 +- pkg/sdk/procedures_def.go | 270 ++++------ pkg/sdk/procedures_dto_builders_gen.go | 437 ++++++---------- pkg/sdk/procedures_dto_gen.go | 156 +++--- pkg/sdk/procedures_gen.go | 356 ++++++------- pkg/sdk/procedures_gen_test.go | 214 ++++---- pkg/sdk/procedures_impl_gen.go | 369 ++++++------- pkg/sdk/procedures_validations_gen.go | 67 ++- .../testint/procedures_integration_test.go | 494 +++++++++--------- 10 files changed, 1059 insertions(+), 1336 deletions(-) diff --git a/pkg/sdk/common_types.go b/pkg/sdk/common_types.go index 57a4f862e0..70980a48b5 100644 --- a/pkg/sdk/common_types.go +++ b/pkg/sdk/common_types.go @@ -207,3 +207,31 @@ func (row *propertyRow) toBoolProperty() *BoolProperty { Description: row.Description, } } + +type ExecuteAs string + +func ExecuteAsPointer(v ExecuteAs) *ExecuteAs { + return &v +} + +const ( + ExecuteAsCaller ExecuteAs = "EXECUTE AS CALLER" + ExecuteAsOwner ExecuteAs = "EXECUTE AS OWNER" +) + +type NullInputBehavior string + +func NullInputBehaviorPointer(v NullInputBehavior) *NullInputBehavior { + return &v +} + +const ( + NullInputBehaviorCalledOnNullInput NullInputBehavior = "CALLED ON NULL INPUT" + NullInputBehaviorReturnNullInput NullInputBehavior = "RETURN NULL ON NULL INPUT" + NullInputBehaviorStrict NullInputBehavior = "STRICT" +) + +type Secret struct { + VariableName string `ddl:"keyword,single_quotes"` + Name string `ddl:"parameter,no_quotes"` +} diff --git a/pkg/sdk/poc/generator/keyword_builders.go b/pkg/sdk/poc/generator/keyword_builders.go index db58de2f25..dadb98d34f 100644 --- a/pkg/sdk/poc/generator/keyword_builders.go +++ b/pkg/sdk/poc/generator/keyword_builders.go @@ -79,7 +79,7 @@ func (v *QueryStruct) SetTags() *QueryStruct { } func (v *QueryStruct) OptionalSetTags() *QueryStruct { - return v.setTags(nil) + return v.setTags(KeywordOptions().SQL("SET TAG")) } func (v *QueryStruct) setTags(transformer *KeywordTransformer) *QueryStruct { @@ -91,7 +91,7 @@ func (v *QueryStruct) UnsetTags() *QueryStruct { } func (v *QueryStruct) OptionalUnsetTags() *QueryStruct { - return v.unsetTags(nil) + return v.unsetTags(KeywordOptions().SQL("UNSET TAG")) } func (v *QueryStruct) unsetTags(transformer *KeywordTransformer) *QueryStruct { diff --git a/pkg/sdk/procedures_def.go b/pkg/sdk/procedures_def.go index f22731da11..32089d8024 100644 --- a/pkg/sdk/procedures_def.go +++ b/pkg/sdk/procedures_def.go @@ -5,25 +5,19 @@ import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/gen //go:generate go run ./poc/main.go var procedureArgument = g.NewQueryStruct("ProcedureArgument"). - Text("ArgName", g.KeywordOptions().NoQuotes()). - Text("ArgDataType", g.KeywordOptions().NoQuotes()) - -var procedureArgumentType = g.NewQueryStruct("ProcedureArgumentType"). - Text("ArgDataType", g.KeywordOptions().NoQuotes()) + Text("ArgName", g.KeywordOptions().NoQuotes().Required()). + PredefinedQueryStructField("ArgDataType", "DataType", g.KeywordOptions().NoQuotes().Required()). + PredefinedQueryStructField("DefaultValue", "*string", g.ParameterOptions().NoEquals().SQL("DEFAULT")) var procedureColumn = g.NewQueryStruct("ProcedureColumn"). - Text("ColumnName", g.KeywordOptions().NoQuotes()). - Text("ColumnDataType", g.KeywordOptions().NoQuotes()) - -var procedureSecret = g.NewQueryStruct("ProcedureSecret"). - Text("SecretVariableName", g.KeywordOptions().SingleQuotes()). - Text("SecretName", g.KeywordOptions().NoQuotes()) + Text("ColumnName", g.KeywordOptions().NoQuotes().Required()). + PredefinedQueryStructField("ColumnDataType", "DataType", g.KeywordOptions().NoQuotes().Required()) var procedureReturns = g.NewQueryStruct("ProcedureReturns"). OptionalQueryStructField( "ResultDataType", g.NewQueryStruct("ProcedureReturnsResultDataType"). - Text("ResultDataType", g.KeywordOptions()). + PredefinedQueryStructField("ResultDataType", "DataType", g.KeywordOptions().NoQuotes().Required()). OptionalSQL("NULL").OptionalSQL("NOT NULL"), g.KeywordOptions(), ). @@ -38,14 +32,11 @@ var procedureReturns = g.NewQueryStruct("ProcedureReturns"). g.KeywordOptions().SQL("TABLE"), ) -var procedureReturns2 = g.NewQueryStruct("ProcedureReturns2"). - Text("ResultDataType", g.KeywordOptions()).OptionalSQL("NOT NULL") - -var procedureReturns3 = g.NewQueryStruct("ProcedureReturns3"). +var procedureSQLReturns = g.NewQueryStruct("ProcedureSQLReturns"). OptionalQueryStructField( "ResultDataType", g.NewQueryStruct("ProcedureReturnsResultDataType"). - Text("ResultDataType", g.KeywordOptions()), + PredefinedQueryStructField("ResultDataType", "DataType", g.KeywordOptions().NoQuotes().Required()), g.KeywordOptions(), ). OptionalQueryStructField( @@ -60,18 +51,9 @@ var procedureReturns3 = g.NewQueryStruct("ProcedureReturns3"). ). OptionalSQL("NOT NULL") -var procedureSet = g.NewQueryStruct("ProcedureSet"). - OptionalTextAssignment("LOG_LEVEL", g.ParameterOptions().SingleQuotes()). - OptionalTextAssignment("TRACE_LEVEL", g.ParameterOptions().SingleQuotes()). - OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()) - -var procedureUnset = g.NewQueryStruct("ProcedureUnset").OptionalSQL("COMMENT") - var ( - procedureStrictOrNot = g.NewQueryStruct("ProcedureStrictOrNot").OptionalSQL("STRICT").OptionalSQL("CALLED ON NULL INPUT") - procedureExecuteAs = g.NewQueryStruct("ProcedureExecuteAs").OptionalSQL("CALLER").OptionalSQL("OWNER") - procedureImport = g.NewQueryStruct("ProcedureImport").Text("Import", g.KeywordOptions().SingleQuotes()) - procedurePackage = g.NewQueryStruct("ProcedurePackage").Text("Package", g.KeywordOptions().SingleQuotes()) + procedureImport = g.NewQueryStruct("ProcedureImport").Text("Import", g.KeywordOptions().SingleQuotes().Required()) + procedurePackage = g.NewQueryStruct("ProcedurePackage").Text("Package", g.KeywordOptions().SingleQuotes().Required()) ) var ProceduresDef = g.NewInterface( @@ -79,9 +61,9 @@ var ProceduresDef = g.NewInterface( "Procedure", g.KindOfT[SchemaObjectIdentifier](), ).CustomOperation( - "CreateProcedureForJava", - "https://docs.snowflake.com/en/sql-reference/sql/create-procedure", - g.NewQueryStruct("CreateProcedureForJava"). + "CreateForJava", + "https://docs.snowflake.com/en/sql-reference/sql/create-procedure#java-handler", + g.NewQueryStruct("CreateForJava"). Create(). OrReplace(). OptionalSQL("SECURE"). @@ -93,47 +75,36 @@ var ProceduresDef = g.NewInterface( g.ParameterOptions().Parentheses().NoEquals(), ). OptionalSQL("COPY GRANTS"). - OptionalQueryStructField( + QueryStructField( "Returns", procedureReturns, - g.KeywordOptions().SQL("RETURNS"), + g.KeywordOptions().SQL("RETURNS").Required(), ). SQL("LANGUAGE JAVA"). - OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). + TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()). ListQueryStructField( "Packages", procedurePackage, - g.ParameterOptions().Parentheses().SQL("PACKAGES"), + g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(), ). ListQueryStructField( "Imports", procedureImport, g.ParameterOptions().Parentheses().SQL("IMPORTS"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()). - ListQueryStructField( - "Secrets", - procedureSecret, - g.ParameterOptions().Parentheses().SQL("SECRETS"), - ). + ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()). OptionalTextAssignment("TARGET_PATH", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "StrictOrNot", - procedureStrictOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - OptionalTextAssignment("AS", g.ParameterOptions().NoEquals().SingleQuotes()), + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"), ).CustomOperation( - "CreateProcedureForJavaScript", - "https://docs.snowflake.com/en/sql-reference/sql/create-procedure", - g.NewQueryStruct("CreateProcedureForJavaScript"). + "CreateForJavaScript", + "https://docs.snowflake.com/en/sql-reference/sql/create-procedure#javascript-handler", + g.NewQueryStruct("CreateForJavaScript"). Create(). OrReplace(). OptionalSQL("SECURE"). @@ -145,28 +116,18 @@ var ProceduresDef = g.NewInterface( g.ParameterOptions().Parentheses().NoEquals(), ). OptionalSQL("COPY GRANTS"). - OptionalQueryStructField( - "Returns", - procedureReturns2, - g.KeywordOptions().SQL("RETURNS"), - ). + PredefinedQueryStructField("ResultDataType", "DataType", g.ParameterOptions().NoEquals().SQL("RETURNS").Required()). + OptionalSQL("NOT NULL"). SQL("LANGUAGE JAVASCRIPT"). - OptionalQueryStructField( - "StrictOrNot", - procedureStrictOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - OptionalTextAssignment("AS", g.ParameterOptions().NoEquals().SingleQuotes()), + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + PredefinedQueryStructField("ProcedureDefinition", "string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()). + WithValidation(g.ValidIdentifier, "name"), ).CustomOperation( - "CreateProcedureForPython", - "https://docs.snowflake.com/en/sql-reference/sql/create-procedure", - g.NewQueryStruct("CreateProcedureForPython"). + "CreateForPython", + "https://docs.snowflake.com/en/sql-reference/sql/create-procedure#python-handler", + g.NewQueryStruct("CreateForPython"). Create(). OrReplace(). OptionalSQL("SECURE"). @@ -178,46 +139,35 @@ var ProceduresDef = g.NewInterface( g.ParameterOptions().Parentheses().NoEquals(), ). OptionalSQL("COPY GRANTS"). - OptionalQueryStructField( + QueryStructField( "Returns", procedureReturns, - g.KeywordOptions().SQL("RETURNS"), + g.KeywordOptions().SQL("RETURNS").Required(), ). SQL("LANGUAGE PYTHON"). - OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). + TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()). ListQueryStructField( "Packages", procedurePackage, - g.ParameterOptions().Parentheses().SQL("PACKAGES"), + g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(), ). ListQueryStructField( "Imports", procedureImport, g.ParameterOptions().Parentheses().SQL("IMPORTS"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()). - ListQueryStructField( - "Secrets", - procedureSecret, - g.ParameterOptions().Parentheses().SQL("SECRETS"), - ). - OptionalQueryStructField( - "StrictOrNot", - procedureStrictOrNot, - g.KeywordOptions(), - ). + ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - OptionalTextAssignment("AS", g.ParameterOptions().NoEquals().SingleQuotes()), + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"), ).CustomOperation( - "CreateProcedureForScala", - "https://docs.snowflake.com/en/sql-reference/sql/create-procedure", - g.NewQueryStruct("CreateProcedureForScala"). + "CreateForScala", + "https://docs.snowflake.com/en/sql-reference/sql/create-procedure#scala-handler", + g.NewQueryStruct("CreateForScala"). Create(). OrReplace(). OptionalSQL("SECURE"). @@ -229,41 +179,34 @@ var ProceduresDef = g.NewInterface( g.ParameterOptions().Parentheses().NoEquals(), ). OptionalSQL("COPY GRANTS"). - OptionalQueryStructField( + QueryStructField( "Returns", procedureReturns, - g.KeywordOptions().SQL("RETURNS"), + g.KeywordOptions().SQL("RETURNS").Required(), ). SQL("LANGUAGE SCALA"). - OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). + TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()). ListQueryStructField( "Packages", procedurePackage, - g.ParameterOptions().Parentheses().SQL("PACKAGES"), + g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(), ). ListQueryStructField( "Imports", procedureImport, g.ParameterOptions().Parentheses().SQL("IMPORTS"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). OptionalTextAssignment("TARGET_PATH", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "StrictOrNot", - procedureStrictOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - OptionalTextAssignment("AS", g.ParameterOptions().NoEquals().SingleQuotes()), + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"), ).CustomOperation( - "CreateProcedureForSQL", - "https://docs.snowflake.com/en/sql-reference/sql/create-procedure", - g.NewQueryStruct("CreateProcedureForSQL"). + "CreateForSQL", + "https://docs.snowflake.com/en/sql-reference/sql/create-procedure#snowflake-scripting-handler", + g.NewQueryStruct("CreateForSQL"). Create(). OrReplace(). OptionalSQL("SECURE"). @@ -275,24 +218,17 @@ var ProceduresDef = g.NewInterface( g.ParameterOptions().Parentheses().NoEquals(), ). OptionalSQL("COPY GRANTS"). - OptionalQueryStructField( + QueryStructField( "Returns", - procedureReturns3, - g.KeywordOptions().SQL("RETURNS"), + procedureSQLReturns, + g.KeywordOptions().SQL("RETURNS").Required(), ). SQL("LANGUAGE SQL"). - OptionalQueryStructField( - "StrictOrNot", - procedureStrictOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - TextAssignment("AS", g.ParameterOptions().NoEquals().SingleQuotes()), + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + PredefinedQueryStructField("ProcedureDefinition", "string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()). + WithValidation(g.ValidIdentifier, "name"), ).AlterOperation( "https://docs.snowflake.com/en/sql-reference/sql/alter-procedure", g.NewQueryStruct("AlterProcedure"). @@ -300,27 +236,18 @@ var ProceduresDef = g.NewInterface( SQL("PROCEDURE"). IfExists(). Name(). - ListQueryStructField( - "ArgumentTypes", - procedureArgumentType, - g.ParameterOptions().Parentheses().NoEquals()). - OptionalQueryStructField( - "Set", - procedureSet, - g.KeywordOptions().SQL("SET"), - ). - OptionalQueryStructField( - "Unset", - procedureUnset, - g.KeywordOptions().SQL("UNSET"), - ). - OptionalQueryStructField( - "ExecuteAs", - procedureExecuteAs, - g.KeywordOptions().SQL("EXECUTE AS"), - ). - Identifier("RenameTo", g.KindOfTPointer[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). - SetTags().UnsetTags(), + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). + OptionalIdentifier("RenameTo", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). + OptionalTextAssignment("SET COMMENT", g.ParameterOptions().SingleQuotes()). + OptionalTextAssignment("SET LOG_LEVEL", g.ParameterOptions().SingleQuotes()). + OptionalTextAssignment("SET TRACE_LEVEL", g.ParameterOptions().SingleQuotes()). + OptionalSQL("UNSET COMMENT"). + OptionalSetTags(). + OptionalUnsetTags(). + PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()). + WithValidation(g.ValidIdentifier, "name"). + WithValidation(g.ValidIdentifierIfSet, "RenameTo"). + WithValidation(g.ExactlyOneValueSet, "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "UnsetComment", "SetTags", "UnsetTags", "ExecuteAs"), ).DropOperation( "https://docs.snowflake.com/en/sql-reference/sql/drop-procedure", g.NewQueryStruct("DropProcedure"). @@ -328,36 +255,48 @@ var ProceduresDef = g.NewInterface( SQL("PROCEDURE"). IfExists(). Name(). - ListQueryStructField( - "ArgumentTypes", - procedureArgumentType, - g.ParameterOptions().Parentheses().NoEquals(), - ).WithValidation(g.ValidIdentifier, "name"), + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). + WithValidation(g.ValidIdentifier, "name"), ).ShowOperation( "https://docs.snowflake.com/en/sql-reference/sql/show-procedures", g.DbStruct("procedureRow"). Field("created_on", "string"). Field("name", "string"). Field("schema_name", "string"). + Field("is_builtin", "string"). + Field("is_aggregate", "string"). + Field("is_ansi", "string"). Field("min_num_arguments", "int"). Field("max_num_arguments", "int"). Field("arguments", "string"). - Field("is_table_function", "string"), + Field("description", "string"). + Field("catalog_name", "string"). + Field("is_table_function", "string"). + Field("valid_for_clustering", "string"). + Field("is_secure", "sql.NullString"), g.PlainStruct("Procedure"). Field("CreatedOn", "string"). Field("Name", "string"). Field("SchemaName", "string"). + Field("IsBuiltin", "bool"). + Field("IsAggregate", "bool"). + Field("IsAnsi", "bool"). Field("MinNumArguments", "int"). Field("MaxNumArguments", "int"). Field("Arguments", "string"). - Field("IsTableFunction", "string"), + Field("Description", "string"). + Field("CatalogName", "string"). + Field("IsTableFunction", "bool"). + Field("ValidForClustering", "bool"). + Field("IsSecure", "bool"), g.NewQueryStruct("ShowProcedures"). Show(). SQL("PROCEDURES"). - OptionalLike().OptionalIn(), -).DescribeOperation( + OptionalLike(). + OptionalIn(), // TODO: 'In' struct for procedures not support keyword "CLASS" now +).ShowByIdOperation().DescribeOperation( g.DescriptionMappingKindSlice, - "https://docs.snowflake.com/en/sql-reference/sql/describe-procedure", + "https://docs.snowflake.com/en/sql-reference/sql/desc-procedure", g.DbStruct("procedureDetailRow"). Field("property", "string"). Field("value", "string"), @@ -368,9 +307,6 @@ var ProceduresDef = g.NewInterface( Describe(). SQL("PROCEDURE"). Name(). - ListQueryStructField( - "ArgumentTypes", - procedureArgumentType, - g.ParameterOptions().Parentheses().NoEquals(), - ).WithValidation(g.ValidIdentifier, "name"), + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). + WithValidation(g.ValidIdentifier, "name"), ) diff --git a/pkg/sdk/procedures_dto_builders_gen.go b/pkg/sdk/procedures_dto_builders_gen.go index fd979f07f6..e1c4328fb5 100644 --- a/pkg/sdk/procedures_dto_builders_gen.go +++ b/pkg/sdk/procedures_dto_builders_gen.go @@ -4,105 +4,94 @@ package sdk import () -func NewCreateProcedureForJavaProcedureRequest( +func NewCreateForJavaProcedureRequest( name SchemaObjectIdentifier, -) *CreateProcedureForJavaProcedureRequest { - s := CreateProcedureForJavaProcedureRequest{} + Returns ProcedureReturnsRequest, + RuntimeVersion string, + Packages []ProcedurePackageRequest, + Handler string, +) *CreateForJavaProcedureRequest { + s := CreateForJavaProcedureRequest{} s.name = name + s.Returns = Returns + s.RuntimeVersion = RuntimeVersion + s.Packages = Packages + s.Handler = Handler return &s } -func (s *CreateProcedureForJavaProcedureRequest) WithOrReplace(OrReplace *bool) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithOrReplace(OrReplace *bool) *CreateForJavaProcedureRequest { s.OrReplace = OrReplace return s } -func (s *CreateProcedureForJavaProcedureRequest) WithSecure(Secure *bool) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithSecure(Secure *bool) *CreateForJavaProcedureRequest { s.Secure = Secure return s } -func (s *CreateProcedureForJavaProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateForJavaProcedureRequest { s.Arguments = Arguments return s } -func (s *CreateProcedureForJavaProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateForJavaProcedureRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateProcedureForJavaProcedureRequest) WithReturns(Returns *ProcedureReturnsRequest) *CreateProcedureForJavaProcedureRequest { - s.Returns = Returns - return s -} - -func (s *CreateProcedureForJavaProcedureRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateProcedureForJavaProcedureRequest { - s.RuntimeVersion = RuntimeVersion - return s -} - -func (s *CreateProcedureForJavaProcedureRequest) WithPackages(Packages []ProcedurePackageRequest) *CreateProcedureForJavaProcedureRequest { - s.Packages = Packages - return s -} - -func (s *CreateProcedureForJavaProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateForJavaProcedureRequest { s.Imports = Imports return s } -func (s *CreateProcedureForJavaProcedureRequest) WithHandler(Handler string) *CreateProcedureForJavaProcedureRequest { - s.Handler = Handler - return s -} - -func (s *CreateProcedureForJavaProcedureRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateForJavaProcedureRequest { s.ExternalAccessIntegrations = ExternalAccessIntegrations return s } -func (s *CreateProcedureForJavaProcedureRequest) WithSecrets(Secrets []ProcedureSecretRequest) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithSecrets(Secrets []Secret) *CreateForJavaProcedureRequest { s.Secrets = Secrets return s } -func (s *CreateProcedureForJavaProcedureRequest) WithTargetPath(TargetPath *string) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithTargetPath(TargetPath *string) *CreateForJavaProcedureRequest { s.TargetPath = TargetPath return s } -func (s *CreateProcedureForJavaProcedureRequest) WithNullInputBehavior(NullInputBehavior ProcedureNullInputBehavior) *CreateProcedureForJavaProcedureRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForJavaProcedureRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForJavaProcedureRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateProcedureForJavaProcedureRequest) WithComment(Comment *string) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithComment(Comment *string) *CreateForJavaProcedureRequest { s.Comment = Comment return s } -func (s *CreateProcedureForJavaProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *CreateProcedureForJavaProcedureRequest { - s.ExecuteAs = &ExecuteAs +func (s *CreateForJavaProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *CreateForJavaProcedureRequest { + s.ExecuteAs = ExecuteAs return s } -func (s *CreateProcedureForJavaProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateProcedureForJavaProcedureRequest { +func (s *CreateForJavaProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateForJavaProcedureRequest { s.ProcedureDefinition = ProcedureDefinition return s } -func NewProcedureArgumentRequest() *ProcedureArgumentRequest { - return &ProcedureArgumentRequest{} -} - -func (s *ProcedureArgumentRequest) WithArgName(ArgName string) *ProcedureArgumentRequest { +func NewProcedureArgumentRequest( + ArgName string, + ArgDataType DataType, +) *ProcedureArgumentRequest { + s := ProcedureArgumentRequest{} s.ArgName = ArgName - return s + s.ArgDataType = ArgDataType + return &s } -func (s *ProcedureArgumentRequest) WithArgDataType(ArgDataType DataType) *ProcedureArgumentRequest { - s.ArgDataType = ArgDataType +func (s *ProcedureArgumentRequest) WithDefaultValue(DefaultValue *string) *ProcedureArgumentRequest { + s.DefaultValue = DefaultValue return s } @@ -120,13 +109,12 @@ func (s *ProcedureReturnsRequest) WithTable(Table *ProcedureReturnsTableRequest) return s } -func NewProcedureReturnsResultDataTypeRequest() *ProcedureReturnsResultDataTypeRequest { - return &ProcedureReturnsResultDataTypeRequest{} -} - -func (s *ProcedureReturnsResultDataTypeRequest) WithResultDataType(ResultDataType DataType) *ProcedureReturnsResultDataTypeRequest { +func NewProcedureReturnsResultDataTypeRequest( + ResultDataType DataType, +) *ProcedureReturnsResultDataTypeRequest { + s := ProcedureReturnsResultDataTypeRequest{} s.ResultDataType = ResultDataType - return s + return &s } func (s *ProcedureReturnsResultDataTypeRequest) WithNull(Null *bool) *ProcedureReturnsResultDataTypeRequest { @@ -148,357 +136,294 @@ func (s *ProcedureReturnsTableRequest) WithColumns(Columns []ProcedureColumnRequ return s } -func NewProcedureColumnRequest() *ProcedureColumnRequest { - return &ProcedureColumnRequest{} -} - -func (s *ProcedureColumnRequest) WithColumnName(ColumnName string) *ProcedureColumnRequest { +func NewProcedureColumnRequest( + ColumnName string, + ColumnDataType DataType, +) *ProcedureColumnRequest { + s := ProcedureColumnRequest{} s.ColumnName = ColumnName - return s -} - -func (s *ProcedureColumnRequest) WithColumnDataType(ColumnDataType DataType) *ProcedureColumnRequest { s.ColumnDataType = ColumnDataType - return s -} - -func NewProcedurePackageRequest() *ProcedurePackageRequest { - return &ProcedurePackageRequest{} + return &s } -func (s *ProcedurePackageRequest) WithPackage(Package string) *ProcedurePackageRequest { +func NewProcedurePackageRequest( + Package string, +) *ProcedurePackageRequest { + s := ProcedurePackageRequest{} s.Package = Package - return s -} - -func NewProcedureImportRequest() *ProcedureImportRequest { - return &ProcedureImportRequest{} + return &s } -func (s *ProcedureImportRequest) WithImport(Import string) *ProcedureImportRequest { +func NewProcedureImportRequest( + Import string, +) *ProcedureImportRequest { + s := ProcedureImportRequest{} s.Import = Import - return s -} - -func NewProcedureSecretRequest() *ProcedureSecretRequest { - return &ProcedureSecretRequest{} -} - -func (s *ProcedureSecretRequest) WithSecretVariableName(SecretVariableName string) *ProcedureSecretRequest { - s.SecretVariableName = SecretVariableName - return s -} - -func (s *ProcedureSecretRequest) WithSecretName(SecretName string) *ProcedureSecretRequest { - s.SecretName = SecretName - return s + return &s } -func NewCreateProcedureForJavaScriptProcedureRequest( +func NewCreateForJavaScriptProcedureRequest( name SchemaObjectIdentifier, -) *CreateProcedureForJavaScriptProcedureRequest { - s := CreateProcedureForJavaScriptProcedureRequest{} + ResultDataType DataType, + ProcedureDefinition string, +) *CreateForJavaScriptProcedureRequest { + s := CreateForJavaScriptProcedureRequest{} s.name = name + s.ResultDataType = ResultDataType + s.ProcedureDefinition = ProcedureDefinition return &s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithOrReplace(OrReplace *bool) *CreateProcedureForJavaScriptProcedureRequest { +func (s *CreateForJavaScriptProcedureRequest) WithOrReplace(OrReplace *bool) *CreateForJavaScriptProcedureRequest { s.OrReplace = OrReplace return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithSecure(Secure *bool) *CreateProcedureForJavaScriptProcedureRequest { +func (s *CreateForJavaScriptProcedureRequest) WithSecure(Secure *bool) *CreateForJavaScriptProcedureRequest { s.Secure = Secure return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateProcedureForJavaScriptProcedureRequest { +func (s *CreateForJavaScriptProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateForJavaScriptProcedureRequest { s.Arguments = Arguments return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateProcedureForJavaScriptProcedureRequest { +func (s *CreateForJavaScriptProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateForJavaScriptProcedureRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithReturns(Returns *ProcedureReturns2Request) *CreateProcedureForJavaScriptProcedureRequest { - s.Returns = Returns +func (s *CreateForJavaScriptProcedureRequest) WithNotNull(NotNull *bool) *CreateForJavaScriptProcedureRequest { + s.NotNull = NotNull return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithNullInputBehavior(NullInputBehavior ProcedureNullInputBehavior) *CreateProcedureForJavaScriptProcedureRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForJavaScriptProcedureRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForJavaScriptProcedureRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithComment(Comment *string) *CreateProcedureForJavaScriptProcedureRequest { +func (s *CreateForJavaScriptProcedureRequest) WithComment(Comment *string) *CreateForJavaScriptProcedureRequest { s.Comment = Comment return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *CreateProcedureForJavaScriptProcedureRequest { - s.ExecuteAs = &ExecuteAs +func (s *CreateForJavaScriptProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *CreateForJavaScriptProcedureRequest { + s.ExecuteAs = ExecuteAs return s } -func (s *CreateProcedureForJavaScriptProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateProcedureForJavaScriptProcedureRequest { - s.ProcedureDefinition = ProcedureDefinition - return s -} - -func NewProcedureReturns2Request() *ProcedureReturns2Request { - return &ProcedureReturns2Request{} -} - -func (s *ProcedureReturns2Request) WithResultDataType(ResultDataType DataType) *ProcedureReturns2Request { - s.ResultDataType = ResultDataType - return s -} - -func (s *ProcedureReturns2Request) WithNotNull(NotNull *bool) *ProcedureReturns2Request { - s.NotNull = NotNull - return s -} - -func NewCreateProcedureForPythonProcedureRequest( +func NewCreateForPythonProcedureRequest( name SchemaObjectIdentifier, -) *CreateProcedureForPythonProcedureRequest { - s := CreateProcedureForPythonProcedureRequest{} + Returns ProcedureReturnsRequest, + RuntimeVersion string, + Packages []ProcedurePackageRequest, + Handler string, +) *CreateForPythonProcedureRequest { + s := CreateForPythonProcedureRequest{} s.name = name + s.Returns = Returns + s.RuntimeVersion = RuntimeVersion + s.Packages = Packages + s.Handler = Handler return &s } -func (s *CreateProcedureForPythonProcedureRequest) WithOrReplace(OrReplace *bool) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithOrReplace(OrReplace *bool) *CreateForPythonProcedureRequest { s.OrReplace = OrReplace return s } -func (s *CreateProcedureForPythonProcedureRequest) WithSecure(Secure *bool) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithSecure(Secure *bool) *CreateForPythonProcedureRequest { s.Secure = Secure return s } -func (s *CreateProcedureForPythonProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateForPythonProcedureRequest { s.Arguments = Arguments return s } -func (s *CreateProcedureForPythonProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateForPythonProcedureRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateProcedureForPythonProcedureRequest) WithReturns(Returns *ProcedureReturnsRequest) *CreateProcedureForPythonProcedureRequest { - s.Returns = Returns - return s -} - -func (s *CreateProcedureForPythonProcedureRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateProcedureForPythonProcedureRequest { - s.RuntimeVersion = RuntimeVersion - return s -} - -func (s *CreateProcedureForPythonProcedureRequest) WithPackages(Packages []ProcedurePackageRequest) *CreateProcedureForPythonProcedureRequest { - s.Packages = Packages - return s -} - -func (s *CreateProcedureForPythonProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateForPythonProcedureRequest { s.Imports = Imports return s } -func (s *CreateProcedureForPythonProcedureRequest) WithHandler(Handler string) *CreateProcedureForPythonProcedureRequest { - s.Handler = Handler - return s -} - -func (s *CreateProcedureForPythonProcedureRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateForPythonProcedureRequest { s.ExternalAccessIntegrations = ExternalAccessIntegrations return s } -func (s *CreateProcedureForPythonProcedureRequest) WithSecrets(Secrets []ProcedureSecretRequest) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithSecrets(Secrets []Secret) *CreateForPythonProcedureRequest { s.Secrets = Secrets return s } -func (s *CreateProcedureForPythonProcedureRequest) WithNullInputBehavior(NullInputBehavior ProcedureNullInputBehavior) *CreateProcedureForPythonProcedureRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForPythonProcedureRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForPythonProcedureRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateProcedureForPythonProcedureRequest) WithComment(Comment *string) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithComment(Comment *string) *CreateForPythonProcedureRequest { s.Comment = Comment return s } -func (s *CreateProcedureForPythonProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *CreateProcedureForPythonProcedureRequest { - s.ExecuteAs = &ExecuteAs +func (s *CreateForPythonProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *CreateForPythonProcedureRequest { + s.ExecuteAs = ExecuteAs return s } -func (s *CreateProcedureForPythonProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateProcedureForPythonProcedureRequest { +func (s *CreateForPythonProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateForPythonProcedureRequest { s.ProcedureDefinition = ProcedureDefinition return s } -func NewCreateProcedureForScalaProcedureRequest( +func NewCreateForScalaProcedureRequest( name SchemaObjectIdentifier, -) *CreateProcedureForScalaProcedureRequest { - s := CreateProcedureForScalaProcedureRequest{} + Returns ProcedureReturnsRequest, + RuntimeVersion string, + Packages []ProcedurePackageRequest, + Handler string, +) *CreateForScalaProcedureRequest { + s := CreateForScalaProcedureRequest{} s.name = name + s.Returns = Returns + s.RuntimeVersion = RuntimeVersion + s.Packages = Packages + s.Handler = Handler return &s } -func (s *CreateProcedureForScalaProcedureRequest) WithOrReplace(OrReplace *bool) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithOrReplace(OrReplace *bool) *CreateForScalaProcedureRequest { s.OrReplace = OrReplace return s } -func (s *CreateProcedureForScalaProcedureRequest) WithSecure(Secure *bool) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithSecure(Secure *bool) *CreateForScalaProcedureRequest { s.Secure = Secure return s } -func (s *CreateProcedureForScalaProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateForScalaProcedureRequest { s.Arguments = Arguments return s } -func (s *CreateProcedureForScalaProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateForScalaProcedureRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateProcedureForScalaProcedureRequest) WithReturns(Returns *ProcedureReturnsRequest) *CreateProcedureForScalaProcedureRequest { - s.Returns = Returns - return s -} - -func (s *CreateProcedureForScalaProcedureRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateProcedureForScalaProcedureRequest { - s.RuntimeVersion = RuntimeVersion - return s -} - -func (s *CreateProcedureForScalaProcedureRequest) WithPackages(Packages []ProcedurePackageRequest) *CreateProcedureForScalaProcedureRequest { - s.Packages = Packages - return s -} - -func (s *CreateProcedureForScalaProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithImports(Imports []ProcedureImportRequest) *CreateForScalaProcedureRequest { s.Imports = Imports return s } -func (s *CreateProcedureForScalaProcedureRequest) WithHandler(Handler string) *CreateProcedureForScalaProcedureRequest { - s.Handler = Handler - return s -} - -func (s *CreateProcedureForScalaProcedureRequest) WithTargetPath(TargetPath *string) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithTargetPath(TargetPath *string) *CreateForScalaProcedureRequest { s.TargetPath = TargetPath return s } -func (s *CreateProcedureForScalaProcedureRequest) WithNullInputBehavior(NullInputBehavior ProcedureNullInputBehavior) *CreateProcedureForScalaProcedureRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForScalaProcedureRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForScalaProcedureRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateProcedureForScalaProcedureRequest) WithComment(Comment *string) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithComment(Comment *string) *CreateForScalaProcedureRequest { s.Comment = Comment return s } -func (s *CreateProcedureForScalaProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *CreateProcedureForScalaProcedureRequest { - s.ExecuteAs = &ExecuteAs +func (s *CreateForScalaProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *CreateForScalaProcedureRequest { + s.ExecuteAs = ExecuteAs return s } -func (s *CreateProcedureForScalaProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateProcedureForScalaProcedureRequest { +func (s *CreateForScalaProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateForScalaProcedureRequest { s.ProcedureDefinition = ProcedureDefinition return s } -func NewCreateProcedureForSQLProcedureRequest( +func NewCreateForSQLProcedureRequest( name SchemaObjectIdentifier, -) *CreateProcedureForSQLProcedureRequest { - s := CreateProcedureForSQLProcedureRequest{} + Returns ProcedureSQLReturnsRequest, + ProcedureDefinition string, +) *CreateForSQLProcedureRequest { + s := CreateForSQLProcedureRequest{} s.name = name + s.Returns = Returns + s.ProcedureDefinition = ProcedureDefinition return &s } -func (s *CreateProcedureForSQLProcedureRequest) WithOrReplace(OrReplace *bool) *CreateProcedureForSQLProcedureRequest { +func (s *CreateForSQLProcedureRequest) WithOrReplace(OrReplace *bool) *CreateForSQLProcedureRequest { s.OrReplace = OrReplace return s } -func (s *CreateProcedureForSQLProcedureRequest) WithSecure(Secure *bool) *CreateProcedureForSQLProcedureRequest { +func (s *CreateForSQLProcedureRequest) WithSecure(Secure *bool) *CreateForSQLProcedureRequest { s.Secure = Secure return s } -func (s *CreateProcedureForSQLProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateProcedureForSQLProcedureRequest { +func (s *CreateForSQLProcedureRequest) WithArguments(Arguments []ProcedureArgumentRequest) *CreateForSQLProcedureRequest { s.Arguments = Arguments return s } -func (s *CreateProcedureForSQLProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateProcedureForSQLProcedureRequest { +func (s *CreateForSQLProcedureRequest) WithCopyGrants(CopyGrants *bool) *CreateForSQLProcedureRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateProcedureForSQLProcedureRequest) WithReturns(Returns *ProcedureReturns3Request) *CreateProcedureForSQLProcedureRequest { - s.Returns = Returns - return s -} - -func (s *CreateProcedureForSQLProcedureRequest) WithNullInputBehavior(NullInputBehavior ProcedureNullInputBehavior) *CreateProcedureForSQLProcedureRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForSQLProcedureRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForSQLProcedureRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateProcedureForSQLProcedureRequest) WithComment(Comment *string) *CreateProcedureForSQLProcedureRequest { +func (s *CreateForSQLProcedureRequest) WithComment(Comment *string) *CreateForSQLProcedureRequest { s.Comment = Comment return s } -func (s *CreateProcedureForSQLProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *CreateProcedureForSQLProcedureRequest { - s.ExecuteAs = &ExecuteAs - return s -} - -func (s *CreateProcedureForSQLProcedureRequest) WithProcedureDefinition(ProcedureDefinition *string) *CreateProcedureForSQLProcedureRequest { - s.ProcedureDefinition = ProcedureDefinition +func (s *CreateForSQLProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *CreateForSQLProcedureRequest { + s.ExecuteAs = ExecuteAs return s } -func NewProcedureReturns3Request() *ProcedureReturns3Request { - return &ProcedureReturns3Request{} +func NewProcedureSQLReturnsRequest() *ProcedureSQLReturnsRequest { + return &ProcedureSQLReturnsRequest{} } -func (s *ProcedureReturns3Request) WithResultDataType(ResultDataType *ProcedureReturnsResultDataTypeRequest) *ProcedureReturns3Request { +func (s *ProcedureSQLReturnsRequest) WithResultDataType(ResultDataType *ProcedureReturnsResultDataTypeRequest) *ProcedureSQLReturnsRequest { s.ResultDataType = ResultDataType return s } -func (s *ProcedureReturns3Request) WithTable(Table *ProcedureReturnsTableRequest) *ProcedureReturns3Request { +func (s *ProcedureSQLReturnsRequest) WithTable(Table *ProcedureReturnsTableRequest) *ProcedureSQLReturnsRequest { s.Table = Table return s } -func (s *ProcedureReturns3Request) WithNotNull(NotNull *bool) *ProcedureReturns3Request { +func (s *ProcedureSQLReturnsRequest) WithNotNull(NotNull *bool) *ProcedureSQLReturnsRequest { s.NotNull = NotNull return s } func NewAlterProcedureRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *AlterProcedureRequest { s := AlterProcedureRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } @@ -507,28 +432,28 @@ func (s *AlterProcedureRequest) WithIfExists(IfExists *bool) *AlterProcedureRequ return s } -func (s *AlterProcedureRequest) WithArgumentTypes(ArgumentTypes []ProcedureArgumentTypeRequest) *AlterProcedureRequest { - s.ArgumentTypes = ArgumentTypes +func (s *AlterProcedureRequest) WithRenameTo(RenameTo *SchemaObjectIdentifier) *AlterProcedureRequest { + s.RenameTo = RenameTo return s } -func (s *AlterProcedureRequest) WithSet(Set *ProcedureSetRequest) *AlterProcedureRequest { - s.Set = Set +func (s *AlterProcedureRequest) WithSetComment(SetComment *string) *AlterProcedureRequest { + s.SetComment = SetComment return s } -func (s *AlterProcedureRequest) WithUnset(Unset *ProcedureUnsetRequest) *AlterProcedureRequest { - s.Unset = Unset +func (s *AlterProcedureRequest) WithSetLogLevel(SetLogLevel *string) *AlterProcedureRequest { + s.SetLogLevel = SetLogLevel return s } -func (s *AlterProcedureRequest) WithExecuteAs(ExecuteAs ProcedureExecuteAs) *AlterProcedureRequest { - s.ExecuteAs = &ExecuteAs +func (s *AlterProcedureRequest) WithSetTraceLevel(SetTraceLevel *string) *AlterProcedureRequest { + s.SetTraceLevel = SetTraceLevel return s } -func (s *AlterProcedureRequest) WithRenameTo(RenameTo *SchemaObjectIdentifier) *AlterProcedureRequest { - s.RenameTo = RenameTo +func (s *AlterProcedureRequest) WithUnsetComment(UnsetComment *bool) *AlterProcedureRequest { + s.UnsetComment = UnsetComment return s } @@ -542,48 +467,18 @@ func (s *AlterProcedureRequest) WithUnsetTags(UnsetTags []ObjectIdentifier) *Alt return s } -func NewProcedureArgumentTypeRequest() *ProcedureArgumentTypeRequest { - return &ProcedureArgumentTypeRequest{} -} - -func (s *ProcedureArgumentTypeRequest) WithArgDataType(ArgDataType DataType) *ProcedureArgumentTypeRequest { - s.ArgDataType = ArgDataType - return s -} - -func NewProcedureSetRequest() *ProcedureSetRequest { - return &ProcedureSetRequest{} -} - -func (s *ProcedureSetRequest) WithLogLevel(LogLevel *string) *ProcedureSetRequest { - s.LogLevel = LogLevel - return s -} - -func (s *ProcedureSetRequest) WithTraceLevel(TraceLevel *string) *ProcedureSetRequest { - s.TraceLevel = TraceLevel - return s -} - -func (s *ProcedureSetRequest) WithComment(Comment *string) *ProcedureSetRequest { - s.Comment = Comment - return s -} - -func NewProcedureUnsetRequest() *ProcedureUnsetRequest { - return &ProcedureUnsetRequest{} -} - -func (s *ProcedureUnsetRequest) WithComment(Comment *bool) *ProcedureUnsetRequest { - s.Comment = Comment +func (s *AlterProcedureRequest) WithExecuteAs(ExecuteAs *ExecuteAs) *AlterProcedureRequest { + s.ExecuteAs = ExecuteAs return s } func NewDropProcedureRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *DropProcedureRequest { s := DropProcedureRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } @@ -592,19 +487,12 @@ func (s *DropProcedureRequest) WithIfExists(IfExists *bool) *DropProcedureReques return s } -func (s *DropProcedureRequest) WithArgumentTypes(ArgumentTypes []ProcedureArgumentTypeRequest) *DropProcedureRequest { - s.ArgumentTypes = ArgumentTypes - return s -} - func NewShowProcedureRequest() *ShowProcedureRequest { return &ShowProcedureRequest{} } -func (s *ShowProcedureRequest) WithLike(pattern string) *ShowProcedureRequest { - s.Like = &Like{ - Pattern: String(pattern), - } +func (s *ShowProcedureRequest) WithLike(Like *Like) *ShowProcedureRequest { + s.Like = Like return s } @@ -615,13 +503,10 @@ func (s *ShowProcedureRequest) WithIn(In *In) *ShowProcedureRequest { func NewDescribeProcedureRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *DescribeProcedureRequest { s := DescribeProcedureRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } - -func (s *DescribeProcedureRequest) WithArgumentTypes(ArgumentTypes []ProcedureArgumentTypeRequest) *DescribeProcedureRequest { - s.ArgumentTypes = ArgumentTypes - return s -} diff --git a/pkg/sdk/procedures_dto_gen.go b/pkg/sdk/procedures_dto_gen.go index 05541b0312..89980f6e90 100644 --- a/pkg/sdk/procedures_dto_gen.go +++ b/pkg/sdk/procedures_dto_gen.go @@ -3,40 +3,41 @@ package sdk //go:generate go run ./dto-builder-generator/main.go var ( - _ optionsProvider[CreateProcedureForJavaProcedureOptions] = new(CreateProcedureForJavaProcedureRequest) - _ optionsProvider[CreateProcedureForJavaScriptProcedureOptions] = new(CreateProcedureForJavaScriptProcedureRequest) - _ optionsProvider[CreateProcedureForPythonProcedureOptions] = new(CreateProcedureForPythonProcedureRequest) - _ optionsProvider[CreateProcedureForScalaProcedureOptions] = new(CreateProcedureForScalaProcedureRequest) - _ optionsProvider[CreateProcedureForSQLProcedureOptions] = new(CreateProcedureForSQLProcedureRequest) - _ optionsProvider[AlterProcedureOptions] = new(AlterProcedureRequest) - _ optionsProvider[DropProcedureOptions] = new(DropProcedureRequest) - _ optionsProvider[ShowProcedureOptions] = new(ShowProcedureRequest) - _ optionsProvider[DescribeProcedureOptions] = new(DescribeProcedureRequest) + _ optionsProvider[CreateForJavaProcedureOptions] = new(CreateForJavaProcedureRequest) + _ optionsProvider[CreateForJavaScriptProcedureOptions] = new(CreateForJavaScriptProcedureRequest) + _ optionsProvider[CreateForPythonProcedureOptions] = new(CreateForPythonProcedureRequest) + _ optionsProvider[CreateForScalaProcedureOptions] = new(CreateForScalaProcedureRequest) + _ optionsProvider[CreateForSQLProcedureOptions] = new(CreateForSQLProcedureRequest) + _ optionsProvider[AlterProcedureOptions] = new(AlterProcedureRequest) + _ optionsProvider[DropProcedureOptions] = new(DropProcedureRequest) + _ optionsProvider[ShowProcedureOptions] = new(ShowProcedureRequest) + _ optionsProvider[DescribeProcedureOptions] = new(DescribeProcedureRequest) ) -type CreateProcedureForJavaProcedureRequest struct { +type CreateForJavaProcedureRequest struct { OrReplace *bool Secure *bool name SchemaObjectIdentifier // required Arguments []ProcedureArgumentRequest CopyGrants *bool - Returns *ProcedureReturnsRequest - RuntimeVersion *string - Packages []ProcedurePackageRequest + Returns ProcedureReturnsRequest // required + RuntimeVersion string // required + Packages []ProcedurePackageRequest // required Imports []ProcedureImportRequest - Handler string + Handler string // required ExternalAccessIntegrations []AccountObjectIdentifier - Secrets []ProcedureSecretRequest + Secrets []Secret TargetPath *string - NullInputBehavior *ProcedureNullInputBehavior + NullInputBehavior *NullInputBehavior Comment *string - ExecuteAs *ProcedureExecuteAs + ExecuteAs *ExecuteAs ProcedureDefinition *string } type ProcedureArgumentRequest struct { - ArgName string - ArgDataType DataType + ArgName string // required + ArgDataType DataType // required + DefaultValue *string } type ProcedureReturnsRequest struct { @@ -45,7 +46,7 @@ type ProcedureReturnsRequest struct { } type ProcedureReturnsResultDataTypeRequest struct { - ResultDataType DataType + ResultDataType DataType // required Null *bool NotNull *bool } @@ -55,127 +56,106 @@ type ProcedureReturnsTableRequest struct { } type ProcedureColumnRequest struct { - ColumnName string - ColumnDataType DataType + ColumnName string // required + ColumnDataType DataType // required } type ProcedurePackageRequest struct { - Package string + Package string // required } type ProcedureImportRequest struct { - Import string + Import string // required } -type ProcedureSecretRequest struct { - SecretVariableName string - SecretName string -} - -type CreateProcedureForJavaScriptProcedureRequest struct { +type CreateForJavaScriptProcedureRequest struct { OrReplace *bool Secure *bool name SchemaObjectIdentifier // required Arguments []ProcedureArgumentRequest CopyGrants *bool - Returns *ProcedureReturns2Request - NullInputBehavior *ProcedureNullInputBehavior + ResultDataType DataType // required + NotNull *bool + NullInputBehavior *NullInputBehavior Comment *string - ExecuteAs *ProcedureExecuteAs - ProcedureDefinition *string + ExecuteAs *ExecuteAs + ProcedureDefinition string // required } -type ProcedureReturns2Request struct { - ResultDataType DataType - NotNull *bool -} - -type CreateProcedureForPythonProcedureRequest struct { +type CreateForPythonProcedureRequest struct { OrReplace *bool Secure *bool name SchemaObjectIdentifier // required Arguments []ProcedureArgumentRequest CopyGrants *bool - Returns *ProcedureReturnsRequest - RuntimeVersion *string - Packages []ProcedurePackageRequest + Returns ProcedureReturnsRequest // required + RuntimeVersion string // required + Packages []ProcedurePackageRequest // required Imports []ProcedureImportRequest - Handler string + Handler string // required ExternalAccessIntegrations []AccountObjectIdentifier - Secrets []ProcedureSecretRequest - NullInputBehavior *ProcedureNullInputBehavior + Secrets []Secret + NullInputBehavior *NullInputBehavior Comment *string - ExecuteAs *ProcedureExecuteAs + ExecuteAs *ExecuteAs ProcedureDefinition *string } -type CreateProcedureForScalaProcedureRequest struct { +type CreateForScalaProcedureRequest struct { OrReplace *bool Secure *bool name SchemaObjectIdentifier // required Arguments []ProcedureArgumentRequest CopyGrants *bool - Returns *ProcedureReturnsRequest - RuntimeVersion *string - Packages []ProcedurePackageRequest + Returns ProcedureReturnsRequest // required + RuntimeVersion string // required + Packages []ProcedurePackageRequest // required Imports []ProcedureImportRequest - Handler string + Handler string // required TargetPath *string - NullInputBehavior *ProcedureNullInputBehavior + NullInputBehavior *NullInputBehavior Comment *string - ExecuteAs *ProcedureExecuteAs + ExecuteAs *ExecuteAs ProcedureDefinition *string } -type CreateProcedureForSQLProcedureRequest struct { +type CreateForSQLProcedureRequest struct { OrReplace *bool Secure *bool name SchemaObjectIdentifier // required Arguments []ProcedureArgumentRequest CopyGrants *bool - Returns *ProcedureReturns3Request - NullInputBehavior *ProcedureNullInputBehavior + Returns ProcedureSQLReturnsRequest // required + NullInputBehavior *NullInputBehavior Comment *string - ExecuteAs *ProcedureExecuteAs - ProcedureDefinition *string + ExecuteAs *ExecuteAs + ProcedureDefinition string // required } -type ProcedureReturns3Request struct { +type ProcedureSQLReturnsRequest struct { ResultDataType *ProcedureReturnsResultDataTypeRequest Table *ProcedureReturnsTableRequest NotNull *bool } type AlterProcedureRequest struct { - IfExists *bool - name SchemaObjectIdentifier // required - ArgumentTypes []ProcedureArgumentTypeRequest - Set *ProcedureSetRequest - Unset *ProcedureUnsetRequest - ExecuteAs *ProcedureExecuteAs - RenameTo *SchemaObjectIdentifier - SetTags []TagAssociation - UnsetTags []ObjectIdentifier -} - -type ProcedureArgumentTypeRequest struct { - ArgDataType DataType -} - -type ProcedureSetRequest struct { - LogLevel *string - TraceLevel *string - Comment *string -} - -type ProcedureUnsetRequest struct { - Comment *bool + IfExists *bool + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required + RenameTo *SchemaObjectIdentifier + SetComment *string + SetLogLevel *string + SetTraceLevel *string + UnsetComment *bool + SetTags []TagAssociation + UnsetTags []ObjectIdentifier + ExecuteAs *ExecuteAs } type DropProcedureRequest struct { - IfExists *bool - name SchemaObjectIdentifier // required - ArgumentTypes []ProcedureArgumentTypeRequest + IfExists *bool + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required } type ShowProcedureRequest struct { @@ -184,6 +164,6 @@ type ShowProcedureRequest struct { } type DescribeProcedureRequest struct { - name SchemaObjectIdentifier // required - ArgumentTypes []ProcedureArgumentTypeRequest + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required } diff --git a/pkg/sdk/procedures_gen.go b/pkg/sdk/procedures_gen.go index 5812828942..3afad0b022 100644 --- a/pkg/sdk/procedures_gen.go +++ b/pkg/sdk/procedures_gen.go @@ -1,13 +1,16 @@ package sdk -import "context" +import ( + "context" + "database/sql" +) type Procedures interface { - CreateProcedureForJava(ctx context.Context, request *CreateProcedureForJavaProcedureRequest) error - CreateProcedureForJavaScript(ctx context.Context, request *CreateProcedureForJavaScriptProcedureRequest) error - CreateProcedureForPython(ctx context.Context, request *CreateProcedureForPythonProcedureRequest) error - CreateProcedureForScala(ctx context.Context, request *CreateProcedureForScalaProcedureRequest) error - CreateProcedureForSQL(ctx context.Context, request *CreateProcedureForSQLProcedureRequest) error + CreateForJava(ctx context.Context, request *CreateForJavaProcedureRequest) error + CreateForJavaScript(ctx context.Context, request *CreateForJavaScriptProcedureRequest) error + CreateForPython(ctx context.Context, request *CreateForPythonProcedureRequest) error + CreateForScala(ctx context.Context, request *CreateForScalaProcedureRequest) error + CreateForSQL(ctx context.Context, request *CreateForSQLProcedureRequest) error Alter(ctx context.Context, request *AlterProcedureRequest) error Drop(ctx context.Context, request *DropProcedureRequest) error Show(ctx context.Context, request *ShowProcedureRequest) ([]Procedure, error) @@ -15,48 +18,34 @@ type Procedures interface { Describe(ctx context.Context, request *DescribeProcedureRequest) ([]ProcedureDetail, error) } -type ProcedureNullInputBehavior string - -const ( - ProcedureNullInputBehaviorCalledOnNullInput ProcedureNullInputBehavior = "CALLED ON NULL INPUT" - ProcedureNullInputBehaviorReturnNullInput ProcedureNullInputBehavior = "RETURN NULL ON NULL INPUT" - ProcedureNullInputBehaviorStrict ProcedureNullInputBehavior = "STRICT" -) - -type ProcedureExecuteAs string - -const ( - ProcedureExecuteAsCaller ProcedureExecuteAs = "EXECUTE AS CALLER" - ProcedureExecuteAsOwner ProcedureExecuteAs = "EXECUTE AS OWNER" -) - -// CreateProcedureForJavaProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure. -type CreateProcedureForJavaProcedureOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *ProcedureReturns `ddl:"keyword" sql:"RETURNS"` - languageJava bool `ddl:"static" sql:"LANGUAGE JAVA"` - RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` - Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` - Secrets []ProcedureSecret `ddl:"parameter,parentheses" sql:"SECRETS"` - TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` - NullInputBehavior *ProcedureNullInputBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +// CreateForJavaProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure#java-handler. +type CreateForJavaProcedureOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns ProcedureReturns `ddl:"keyword" sql:"RETURNS"` + languageJava bool `ddl:"static" sql:"LANGUAGE JAVA"` + RuntimeVersion string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` + Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` + Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` + ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` + Secrets []Secret `ddl:"parameter,parentheses" sql:"SECRETS"` + TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + ExecuteAs *ExecuteAs `ddl:"keyword"` + ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } type ProcedureArgument struct { - ArgName string `ddl:"keyword,no_quotes"` - ArgDataType DataType `ddl:"keyword,no_quotes"` + ArgName string `ddl:"keyword,no_quotes"` + ArgDataType DataType `ddl:"keyword,no_quotes"` + DefaultValue *string `ddl:"parameter,no_equals" sql:"DEFAULT"` } type ProcedureReturns struct { @@ -65,7 +54,7 @@ type ProcedureReturns struct { } type ProcedureReturnsResultDataType struct { - ResultDataType DataType `ddl:"keyword"` + ResultDataType DataType `ddl:"keyword,no_quotes"` Null *bool `ddl:"keyword" sql:"NULL"` NotNull *bool `ddl:"keyword" sql:"NOT NULL"` } @@ -87,96 +76,87 @@ type ProcedureImport struct { Import string `ddl:"keyword,single_quotes"` } -type ProcedureSecret struct { - SecretVariableName string `ddl:"keyword,single_quotes"` - SecretName string `ddl:"parameter,no_quotes"` -} - -// CreateProcedureForJavaScriptProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure. -type CreateProcedureForJavaScriptProcedureOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *ProcedureReturns2 `ddl:"keyword" sql:"RETURNS"` - languageJavascript bool `ddl:"static" sql:"LANGUAGE JAVASCRIPT"` - NullInputBehavior *ProcedureNullInputBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` -} - -type ProcedureReturns2 struct { - ResultDataType DataType `ddl:"keyword"` - NotNull *bool `ddl:"keyword" sql:"NOT NULL"` -} - -// CreateProcedureForPythonProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure. -type CreateProcedureForPythonProcedureOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *ProcedureReturns `ddl:"keyword" sql:"RETURNS"` - languagePython bool `ddl:"static" sql:"LANGUAGE PYTHON"` - RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` - Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` - Secrets []ProcedureSecret `ddl:"parameter,parentheses" sql:"SECRETS"` - NullInputBehavior *ProcedureNullInputBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` -} - -// CreateProcedureForScalaProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure. -type CreateProcedureForScalaProcedureOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *ProcedureReturns `ddl:"keyword" sql:"RETURNS"` - languageScala bool `ddl:"static" sql:"LANGUAGE SCALA"` - RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` - Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` - NullInputBehavior *ProcedureNullInputBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` -} - -// CreateProcedureForSQLProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure. -type CreateProcedureForSQLProcedureOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *ProcedureReturns3 `ddl:"keyword" sql:"RETURNS"` - languageSql bool `ddl:"static" sql:"LANGUAGE SQL"` - NullInputBehavior *ProcedureNullInputBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` -} - -type ProcedureReturns3 struct { +// CreateForJavaScriptProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure#javascript-handler. +type CreateForJavaScriptProcedureOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + ResultDataType DataType `ddl:"parameter,no_equals" sql:"RETURNS"` + NotNull *bool `ddl:"keyword" sql:"NOT NULL"` + languageJavascript bool `ddl:"static" sql:"LANGUAGE JAVASCRIPT"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + ExecuteAs *ExecuteAs `ddl:"keyword"` + ProcedureDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +} + +// CreateForPythonProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure#python-handler. +type CreateForPythonProcedureOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns ProcedureReturns `ddl:"keyword" sql:"RETURNS"` + languagePython bool `ddl:"static" sql:"LANGUAGE PYTHON"` + RuntimeVersion string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` + Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` + Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` + ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` + Secrets []Secret `ddl:"parameter,parentheses" sql:"SECRETS"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + ExecuteAs *ExecuteAs `ddl:"keyword"` + ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +} + +// CreateForScalaProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure#scala-handler. +type CreateForScalaProcedureOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns ProcedureReturns `ddl:"keyword" sql:"RETURNS"` + languageScala bool `ddl:"static" sql:"LANGUAGE SCALA"` + RuntimeVersion string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Packages []ProcedurePackage `ddl:"parameter,parentheses" sql:"PACKAGES"` + Imports []ProcedureImport `ddl:"parameter,parentheses" sql:"IMPORTS"` + Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` + TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + ExecuteAs *ExecuteAs `ddl:"keyword"` + ProcedureDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +} + +// CreateForSQLProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-procedure#snowflake-scripting-handler. +type CreateForSQLProcedureOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []ProcedureArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns ProcedureSQLReturns `ddl:"keyword" sql:"RETURNS"` + languageSql bool `ddl:"static" sql:"LANGUAGE SQL"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + ExecuteAs *ExecuteAs `ddl:"keyword"` + ProcedureDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +} + +type ProcedureSQLReturns struct { ResultDataType *ProcedureReturnsResultDataType `ddl:"keyword"` Table *ProcedureReturnsTable `ddl:"keyword" sql:"TABLE"` NotNull *bool `ddl:"keyword" sql:"NOT NULL"` @@ -184,40 +164,28 @@ type ProcedureReturns3 struct { // AlterProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-procedure. type AlterProcedureOptions struct { - alter bool `ddl:"static" sql:"ALTER"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []ProcedureArgumentType `ddl:"parameter,parentheses,no_equals"` - Set *ProcedureSet `ddl:"keyword" sql:"SET"` - Unset *ProcedureUnset `ddl:"keyword" sql:"UNSET"` - ExecuteAs *ProcedureExecuteAs `ddl:"keyword"` - RenameTo *SchemaObjectIdentifier `ddl:"identifier" sql:"RENAME TO"` - SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"` - UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"` -} - -type ProcedureArgumentType struct { - ArgDataType DataType `ddl:"keyword,no_quotes"` -} - -type ProcedureSet struct { - LogLevel *string `ddl:"parameter,single_quotes" sql:"LOG_LEVEL"` - TraceLevel *string `ddl:"parameter,single_quotes" sql:"TRACE_LEVEL"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` -} - -type ProcedureUnset struct { - Comment *bool `ddl:"keyword" sql:"COMMENT"` + alter bool `ddl:"static" sql:"ALTER"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + ArgumentDataTypes []DataType `ddl:"keyword,parentheses"` + RenameTo *SchemaObjectIdentifier `ddl:"identifier" sql:"RENAME TO"` + SetComment *string `ddl:"parameter,single_quotes" sql:"SET COMMENT"` + SetLogLevel *string `ddl:"parameter,single_quotes" sql:"SET LOG_LEVEL"` + SetTraceLevel *string `ddl:"parameter,single_quotes" sql:"SET TRACE_LEVEL"` + UnsetComment *bool `ddl:"keyword" sql:"UNSET COMMENT"` + SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"` + UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"` + ExecuteAs *ExecuteAs `ddl:"keyword"` } // DropProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-procedure. type DropProcedureOptions struct { - drop bool `ddl:"static" sql:"DROP"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []ProcedureArgumentType `ddl:"parameter,parentheses,no_equals"` + drop bool `ddl:"static" sql:"DROP"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + ArgumentDataTypes []DataType `ddl:"keyword,parentheses"` } // ShowProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/show-procedures. @@ -229,31 +197,45 @@ type ShowProcedureOptions struct { } type procedureRow struct { - CreatedOn string `db:"created_on"` - Name string `db:"name"` - SchemaName string `db:"schema_name"` - MinNumArguments int `db:"min_num_arguments"` - MaxNumArguments int `db:"max_num_arguments"` - Arguments string `db:"arguments"` - IsTableFunction string `db:"is_table_function"` + CreatedOn string `db:"created_on"` + Name string `db:"name"` + SchemaName string `db:"schema_name"` + IsBuiltin string `db:"is_builtin"` + IsAggregate string `db:"is_aggregate"` + IsAnsi string `db:"is_ansi"` + MinNumArguments int `db:"min_num_arguments"` + MaxNumArguments int `db:"max_num_arguments"` + Arguments string `db:"arguments"` + Description string `db:"description"` + CatalogName string `db:"catalog_name"` + IsTableFunction string `db:"is_table_function"` + ValidForClustering string `db:"valid_for_clustering"` + IsSecure sql.NullString `db:"is_secure"` } type Procedure struct { - CreatedOn string - Name string - SchemaName string - MinNumArguments int - MaxNumArguments int - Arguments string - IsTableFunction string -} - -// DescribeProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/describe-procedure. + CreatedOn string + Name string + SchemaName string + IsBuiltin bool + IsAggregate bool + IsAnsi bool + MinNumArguments int + MaxNumArguments int + Arguments string + Description string + CatalogName string + IsTableFunction bool + ValidForClustering bool + IsSecure bool +} + +// DescribeProcedureOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-procedure. type DescribeProcedureOptions struct { - describe bool `ddl:"static" sql:"DESCRIBE"` - procedure bool `ddl:"static" sql:"PROCEDURE"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []ProcedureArgumentType `ddl:"parameter,parentheses,no_equals"` + describe bool `ddl:"static" sql:"DESCRIBE"` + procedure bool `ddl:"static" sql:"PROCEDURE"` + name SchemaObjectIdentifier `ddl:"identifier"` + ArgumentDataTypes []DataType `ddl:"keyword,parentheses"` } type procedureDetailRow struct { diff --git a/pkg/sdk/procedures_gen_test.go b/pkg/sdk/procedures_gen_test.go index 6f05b7babe..c6adf66045 100644 --- a/pkg/sdk/procedures_gen_test.go +++ b/pkg/sdk/procedures_gen_test.go @@ -6,17 +6,17 @@ import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" ) -func TestProcedures_CreateProcedureForJava(t *testing.T) { +func TestProcedures_CreateForJava(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateProcedureForJavaProcedureOptions { - return &CreateProcedureForJavaProcedureOptions{ + defaultOpts := func() *CreateForJavaProcedureOptions { + return &CreateForJavaProcedureOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - var opts *CreateProcedureForJavaProcedureOptions = nil + var opts *CreateForJavaProcedureOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -33,25 +33,26 @@ func TestProcedures_CreateProcedureForJava(t *testing.T) { opts.Arguments = []ProcedureArgument{ { ArgName: "id", - ArgDataType: "INTEGER", + ArgDataType: DataTypeNumber, }, { - ArgName: "name", - ArgDataType: "VARCHAR", + ArgName: "name", + ArgDataType: DataTypeVARCHAR, + DefaultValue: String("'test'"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &ProcedureReturns{ + opts.Returns = ProcedureReturns{ Table: &ProcedureReturnsTable{ Columns: []ProcedureColumn{ { ColumnName: "country_code", - ColumnDataType: "CHAR", + ColumnDataType: DataTypeVARCHAR, }, }, }, } - opts.RuntimeVersion = String("1.8") + opts.RuntimeVersion = "1.8" opts.Packages = []ProcedurePackage{ { Package: "com.snowflake:snowpark:1.2.0", @@ -66,38 +67,36 @@ func TestProcedures_CreateProcedureForJava(t *testing.T) { opts.ExternalAccessIntegrations = []AccountObjectIdentifier{ NewAccountObjectIdentifier("ext_integration"), } - opts.Secrets = []ProcedureSecret{ + opts.Secrets = []Secret{ { - SecretVariableName: "variable1", - SecretName: "name1", + VariableName: "variable1", + Name: "name1", }, { - SecretVariableName: "variable2", - SecretName: "name2", + VariableName: "variable2", + Name: "name2", }, } opts.TargetPath = String("@~/testfunc.jar") - behavior := ProcedureNullInputBehaviorStrict - opts.NullInputBehavior = &behavior + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorStrict) opts.Comment = String("test comment") - executeAs := ProcedureExecuteAsCaller - opts.ExecuteAs = &executeAs + opts.ExecuteAs = ExecuteAsPointer(ExecuteAsCaller) opts.ProcedureDefinition = String("return id + name;") - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (id INTEGER, name VARCHAR) COPY GRANTS RETURNS TABLE (country_code CHAR) LANGUAGE JAVA RUNTIME_VERSION = '1.8' PACKAGES = ('com.snowflake:snowpark:1.2.0') IMPORTS = ('test_jar.jar') HANDLER = 'TestFunc.echoVarchar' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) TARGET_PATH = '@~/testfunc.jar' STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return id + name;'`, id.FullyQualifiedName()) + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (id NUMBER, name VARCHAR DEFAULT 'test') COPY GRANTS RETURNS TABLE (country_code VARCHAR) LANGUAGE JAVA RUNTIME_VERSION = '1.8' PACKAGES = ('com.snowflake:snowpark:1.2.0') IMPORTS = ('test_jar.jar') HANDLER = 'TestFunc.echoVarchar' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) TARGET_PATH = '@~/testfunc.jar' STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return id + name;'`, id.FullyQualifiedName()) }) } -func TestProcedures_CreateProcedureForJavaScript(t *testing.T) { +func TestProcedures_CreateForJavaScript(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateProcedureForJavaScriptProcedureOptions { - return &CreateProcedureForJavaScriptProcedureOptions{ + defaultOpts := func() *CreateForJavaScriptProcedureOptions { + return &CreateForJavaScriptProcedureOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - var opts *CreateProcedureForJavaScriptProcedureOptions = nil + var opts *CreateForJavaScriptProcedureOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -113,36 +112,33 @@ func TestProcedures_CreateProcedureForJavaScript(t *testing.T) { opts.Secure = Bool(true) opts.Arguments = []ProcedureArgument{ { - ArgName: "d", - ArgDataType: "DOUBLE", + ArgName: "d", + ArgDataType: "DOUBLE", + DefaultValue: String("1.0"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &ProcedureReturns2{ - ResultDataType: "DOUBLE", - NotNull: Bool(true), - } - behavior := ProcedureNullInputBehaviorStrict - opts.NullInputBehavior = &behavior + opts.ResultDataType = "DOUBLE" + opts.NotNull = Bool(true) + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorStrict) opts.Comment = String("test comment") - executeAs := ProcedureExecuteAsCaller - opts.ExecuteAs = &executeAs - opts.ProcedureDefinition = String("return 1;") - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (d DOUBLE) COPY GRANTS RETURNS DOUBLE NOT NULL LANGUAGE JAVASCRIPT STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return 1;'`, id.FullyQualifiedName()) + opts.ExecuteAs = ExecuteAsPointer(ExecuteAsCaller) + opts.ProcedureDefinition = "return 1;" + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (d DOUBLE DEFAULT 1.0) COPY GRANTS RETURNS DOUBLE NOT NULL LANGUAGE JAVASCRIPT STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return 1;'`, id.FullyQualifiedName()) }) } -func TestProcedures_CreateProcedureForPython(t *testing.T) { +func TestProcedures_CreateForPython(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateProcedureForPythonProcedureOptions { - return &CreateProcedureForPythonProcedureOptions{ + defaultOpts := func() *CreateForPythonProcedureOptions { + return &CreateForPythonProcedureOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - var opts *CreateProcedureForPythonProcedureOptions = nil + var opts *CreateForPythonProcedureOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -158,18 +154,19 @@ func TestProcedures_CreateProcedureForPython(t *testing.T) { opts.Secure = Bool(true) opts.Arguments = []ProcedureArgument{ { - ArgName: "i", - ArgDataType: "int", + ArgName: "i", + ArgDataType: "int", + DefaultValue: String("1"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &ProcedureReturns{ + opts.Returns = ProcedureReturns{ ResultDataType: &ProcedureReturnsResultDataType{ ResultDataType: "VARIANT", Null: Bool(true), }, } - opts.RuntimeVersion = String("3.8") + opts.RuntimeVersion = "3.8" opts.Packages = []ProcedurePackage{ { Package: "numpy", @@ -190,37 +187,35 @@ func TestProcedures_CreateProcedureForPython(t *testing.T) { opts.ExternalAccessIntegrations = []AccountObjectIdentifier{ NewAccountObjectIdentifier("ext_integration"), } - opts.Secrets = []ProcedureSecret{ + opts.Secrets = []Secret{ { - SecretVariableName: "variable1", - SecretName: "name1", + VariableName: "variable1", + Name: "name1", }, { - SecretVariableName: "variable2", - SecretName: "name2", + VariableName: "variable2", + Name: "name2", }, } - behavior := ProcedureNullInputBehaviorStrict - opts.NullInputBehavior = &behavior + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorStrict) opts.Comment = String("test comment") - executeAs := ProcedureExecuteAsCaller - opts.ExecuteAs = &executeAs + opts.ExecuteAs = ExecuteAsPointer(ExecuteAsCaller) opts.ProcedureDefinition = String("import numpy as np") - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (i int) COPY GRANTS RETURNS VARIANT NULL LANGUAGE PYTHON RUNTIME_VERSION = '3.8' PACKAGES = ('numpy', 'pandas') IMPORTS = ('numpy', 'pandas') HANDLER = 'udf' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'import numpy as np'`, id.FullyQualifiedName()) + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (i int DEFAULT 1) COPY GRANTS RETURNS VARIANT NULL LANGUAGE PYTHON RUNTIME_VERSION = '3.8' PACKAGES = ('numpy', 'pandas') IMPORTS = ('numpy', 'pandas') HANDLER = 'udf' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'import numpy as np'`, id.FullyQualifiedName()) }) } -func TestProcedures_CreateProcedureForScala(t *testing.T) { +func TestProcedures_CreateForScala(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateProcedureForScalaProcedureOptions { - return &CreateProcedureForScalaProcedureOptions{ + defaultOpts := func() *CreateForScalaProcedureOptions { + return &CreateForScalaProcedureOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - var opts *CreateProcedureForScalaProcedureOptions = nil + var opts *CreateForScalaProcedureOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -236,18 +231,19 @@ func TestProcedures_CreateProcedureForScala(t *testing.T) { opts.Secure = Bool(true) opts.Arguments = []ProcedureArgument{ { - ArgName: "x", - ArgDataType: "VARCHAR", + ArgName: "x", + ArgDataType: "VARCHAR", + DefaultValue: String("'test'"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &ProcedureReturns{ + opts.Returns = ProcedureReturns{ ResultDataType: &ProcedureReturnsResultDataType{ ResultDataType: "VARCHAR", NotNull: Bool(true), }, } - opts.RuntimeVersion = String("2.0") + opts.RuntimeVersion = "2.0" opts.Packages = []ProcedurePackage{ { Package: "com.snowflake:snowpark:1.2.0", @@ -260,27 +256,25 @@ func TestProcedures_CreateProcedureForScala(t *testing.T) { } opts.Handler = "Echo.echoVarchar" opts.TargetPath = String("@~/testfunc.jar") - behavior := ProcedureNullInputBehaviorStrict - opts.NullInputBehavior = &behavior + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorStrict) opts.Comment = String("test comment") - executeAs := ProcedureExecuteAsCaller - opts.ExecuteAs = &executeAs + opts.ExecuteAs = ExecuteAsPointer(ExecuteAsCaller) opts.ProcedureDefinition = String("return x") - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (x VARCHAR) COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SCALA RUNTIME_VERSION = '2.0' PACKAGES = ('com.snowflake:snowpark:1.2.0') IMPORTS = ('@udf_libs/echohandler.jar') HANDLER = 'Echo.echoVarchar' TARGET_PATH = '@~/testfunc.jar' STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return x'`, id.FullyQualifiedName()) + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (x VARCHAR DEFAULT 'test') COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SCALA RUNTIME_VERSION = '2.0' PACKAGES = ('com.snowflake:snowpark:1.2.0') IMPORTS = ('@udf_libs/echohandler.jar') HANDLER = 'Echo.echoVarchar' TARGET_PATH = '@~/testfunc.jar' STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS 'return x'`, id.FullyQualifiedName()) }) } -func TestProcedures_CreateProcedureForSQL(t *testing.T) { +func TestProcedures_CreateForSQL(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateProcedureForSQLProcedureOptions { - return &CreateProcedureForSQLProcedureOptions{ + defaultOpts := func() *CreateForSQLProcedureOptions { + return &CreateForSQLProcedureOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - var opts *CreateProcedureForSQLProcedureOptions = nil + var opts *CreateForSQLProcedureOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -296,24 +290,23 @@ func TestProcedures_CreateProcedureForSQL(t *testing.T) { opts.Secure = Bool(true) opts.Arguments = []ProcedureArgument{ { - ArgName: "message", - ArgDataType: "VARCHAR", + ArgName: "message", + ArgDataType: "VARCHAR", + DefaultValue: String("'test'"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &ProcedureReturns3{ + opts.Returns = ProcedureSQLReturns{ ResultDataType: &ProcedureReturnsResultDataType{ ResultDataType: "VARCHAR", }, NotNull: Bool(true), } - behavior := ProcedureNullInputBehaviorStrict - opts.NullInputBehavior = &behavior + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorStrict) opts.Comment = String("test comment") - executeAs := ProcedureExecuteAsCaller - opts.ExecuteAs = &executeAs - opts.ProcedureDefinition = String("3.141592654::FLOAT") - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (message VARCHAR) COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SQL STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS '3.141592654::FLOAT'`, id.FullyQualifiedName()) + opts.ExecuteAs = ExecuteAsPointer(ExecuteAsCaller) + opts.ProcedureDefinition = "3.141592654::FLOAT" + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE SECURE PROCEDURE %s (message VARCHAR DEFAULT 'test') COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SQL STRICT COMMENT = 'test comment' EXECUTE AS CALLER AS '3.141592654::FLOAT'`, id.FullyQualifiedName()) }) } @@ -339,14 +332,7 @@ func TestProcedures_Drop(t *testing.T) { t.Run("all options", func(t *testing.T) { opts := defaultOpts() opts.IfExists = Bool(true) - opts.ArgumentTypes = []ProcedureArgumentType{ - { - ArgDataType: "VARCHAR", - }, - { - ArgDataType: "NUMBER", - }, - } + opts.ArgumentDataTypes = []DataType{DataTypeVARCHAR, DataTypeNumber} assertOptsValidAndSQLEquals(t, opts, `DROP PROCEDURE IF EXISTS %s (VARCHAR, NUMBER)`, id.FullyQualifiedName()) }) } @@ -356,16 +342,9 @@ func TestProcedures_Alter(t *testing.T) { defaultOpts := func() *AlterProcedureOptions { return &AlterProcedureOptions{ - name: id, - IfExists: Bool(true), - ArgumentTypes: []ProcedureArgumentType{ - { - ArgDataType: "VARCHAR", - }, - { - ArgDataType: "NUMBER", - }, - }, + name: id, + IfExists: Bool(true), + ArgumentDataTypes: []DataType{DataTypeVARCHAR, DataTypeNumber}, } } @@ -380,6 +359,18 @@ func TestProcedures_Alter(t *testing.T) { assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) + t.Run("validation: exactly one field should be present", func(t *testing.T) { + opts := defaultOpts() + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterProcedureOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "UnsetComment", "SetTags", "UnsetTags", "ExecuteAs")) + }) + + t.Run("validation: exactly one field should be present", func(t *testing.T) { + opts := defaultOpts() + opts.SetLogLevel = String("DEBUG") + opts.UnsetComment = Bool(true) + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterProcedureOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "UnsetComment", "SetTags", "UnsetTags", "ExecuteAs")) + }) + t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) @@ -389,40 +380,32 @@ func TestProcedures_Alter(t *testing.T) { t.Run("alter: execute as", func(t *testing.T) { opts := defaultOpts() - executeAs := ProcedureExecuteAsCaller + executeAs := ExecuteAsCaller opts.ExecuteAs = &executeAs assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) EXECUTE AS CALLER`, id.FullyQualifiedName()) }) t.Run("alter: set log level", func(t *testing.T) { opts := defaultOpts() - opts.Set = &ProcedureSet{ - LogLevel: String("DEBUG"), - } + opts.SetLogLevel = String("DEBUG") assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) SET LOG_LEVEL = 'DEBUG'`, id.FullyQualifiedName()) }) t.Run("alter: set trace level", func(t *testing.T) { opts := defaultOpts() - opts.Set = &ProcedureSet{ - TraceLevel: String("DEBUG"), - } + opts.SetTraceLevel = String("DEBUG") assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) SET TRACE_LEVEL = 'DEBUG'`, id.FullyQualifiedName()) }) t.Run("alter: set comment", func(t *testing.T) { opts := defaultOpts() - opts.Set = &ProcedureSet{ - Comment: String("comment"), - } + opts.SetComment = String("comment") assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) SET COMMENT = 'comment'`, id.FullyQualifiedName()) }) t.Run("alter: unset comment", func(t *testing.T) { opts := defaultOpts() - opts.Unset = &ProcedureUnset{ - Comment: Bool(true), - } + opts.UnsetComment = Bool(true) assertOptsValidAndSQLEquals(t, opts, `ALTER PROCEDURE IF EXISTS %s (VARCHAR, NUMBER) UNSET COMMENT`, id.FullyQualifiedName()) }) @@ -457,12 +440,6 @@ func TestProcedures_Show(t *testing.T) { assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) - t.Run("validation: empty like", func(t *testing.T) { - opts := defaultOpts() - opts.Like = &Like{} - assertOptsInvalidJoinedErrors(t, opts, ErrPatternRequiredForLikeKeyword) - }) - t.Run("show with empty options", func(t *testing.T) { opts := defaultOpts() assertOptsValidAndSQLEquals(t, opts, `SHOW PROCEDURES`) @@ -507,6 +484,7 @@ func TestProcedures_Describe(t *testing.T) { t.Run("all options", func(t *testing.T) { opts := defaultOpts() - assertOptsValidAndSQLEquals(t, opts, `DESCRIBE PROCEDURE %s`, id.FullyQualifiedName()) + opts.ArgumentDataTypes = []DataType{DataTypeVARCHAR, DataTypeNumber} + assertOptsValidAndSQLEquals(t, opts, `DESCRIBE PROCEDURE %s (VARCHAR, NUMBER)`, id.FullyQualifiedName()) }) } diff --git a/pkg/sdk/procedures_impl_gen.go b/pkg/sdk/procedures_impl_gen.go index f409b88884..6c088ff053 100644 --- a/pkg/sdk/procedures_impl_gen.go +++ b/pkg/sdk/procedures_impl_gen.go @@ -12,27 +12,27 @@ type procedures struct { client *Client } -func (v *procedures) CreateProcedureForJava(ctx context.Context, request *CreateProcedureForJavaProcedureRequest) error { +func (v *procedures) CreateForJava(ctx context.Context, request *CreateForJavaProcedureRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *procedures) CreateProcedureForJavaScript(ctx context.Context, request *CreateProcedureForJavaScriptProcedureRequest) error { +func (v *procedures) CreateForJavaScript(ctx context.Context, request *CreateForJavaScriptProcedureRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *procedures) CreateProcedureForPython(ctx context.Context, request *CreateProcedureForPythonProcedureRequest) error { +func (v *procedures) CreateForPython(ctx context.Context, request *CreateForPythonProcedureRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *procedures) CreateProcedureForScala(ctx context.Context, request *CreateProcedureForScalaProcedureRequest) error { +func (v *procedures) CreateForScala(ctx context.Context, request *CreateForScalaProcedureRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *procedures) CreateProcedureForSQL(ctx context.Context, request *CreateProcedureForSQLProcedureRequest) error { +func (v *procedures) CreateForSQL(ctx context.Context, request *CreateForSQLProcedureRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } @@ -58,7 +58,7 @@ func (v *procedures) Show(ctx context.Context, request *ShowProcedureRequest) ([ } func (v *procedures) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*Procedure, error) { - request := NewShowProcedureRequest().WithLike(id.Name()) + request := NewShowProcedureRequest().WithIn(&In{Database: NewAccountObjectIdentifier(id.DatabaseName())}).WithLike(&Like{String(id.Name())}) procedures, err := v.Show(ctx, request) if err != nil { return nil, err @@ -75,8 +75,8 @@ func (v *procedures) Describe(ctx context.Context, request *DescribeProcedureReq return convertRows[procedureDetailRow, ProcedureDetail](rows), nil } -func (r *CreateProcedureForJavaProcedureRequest) toOpts() *CreateProcedureForJavaProcedureOptions { - opts := &CreateProcedureForJavaProcedureOptions{ +func (r *CreateForJavaProcedureRequest) toOpts() *CreateForJavaProcedureOptions { + opts := &CreateForJavaProcedureOptions{ OrReplace: r.OrReplace, Secure: r.Secure, name: r.name, @@ -87,44 +87,42 @@ func (r *CreateProcedureForJavaProcedureRequest) toOpts() *CreateProcedureForJav Handler: r.Handler, ExternalAccessIntegrations: r.ExternalAccessIntegrations, - - TargetPath: r.TargetPath, - - Comment: r.Comment, - - ProcedureDefinition: r.ProcedureDefinition, + Secrets: r.Secrets, + TargetPath: r.TargetPath, + NullInputBehavior: r.NullInputBehavior, + Comment: r.Comment, + ExecuteAs: r.ExecuteAs, + ProcedureDefinition: r.ProcedureDefinition, } if r.Arguments != nil { s := make([]ProcedureArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = ProcedureArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &ProcedureReturns{} - if r.Returns.ResultDataType != nil { - opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ - ResultDataType: r.Returns.ResultDataType.ResultDataType, - Null: r.Returns.ResultDataType.Null, - NotNull: r.Returns.ResultDataType.NotNull, - } + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, + Null: r.Returns.ResultDataType.Null, + NotNull: r.Returns.ResultDataType.NotNull, } - if r.Returns.Table != nil { - opts.Returns.Table = &ProcedureReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = ProcedureColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &ProcedureReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = ProcedureColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } if r.Packages != nil { @@ -145,56 +143,39 @@ func (r *CreateProcedureForJavaProcedureRequest) toOpts() *CreateProcedureForJav } opts.Imports = s } - if r.Secrets != nil { - s := make([]ProcedureSecret, len(r.Secrets)) - for i, v := range r.Secrets { - s[i] = ProcedureSecret{ - SecretVariableName: v.SecretVariableName, - SecretName: v.SecretName, - } - } - opts.Secrets = s - } - opts.NullInputBehavior = r.NullInputBehavior - opts.ExecuteAs = r.ExecuteAs return opts } -func (r *CreateProcedureForJavaScriptProcedureRequest) toOpts() *CreateProcedureForJavaScriptProcedureOptions { - opts := &CreateProcedureForJavaScriptProcedureOptions{ +func (r *CreateForJavaScriptProcedureRequest) toOpts() *CreateForJavaScriptProcedureOptions { + opts := &CreateForJavaScriptProcedureOptions{ OrReplace: r.OrReplace, Secure: r.Secure, name: r.name, - CopyGrants: r.CopyGrants, - - Comment: r.Comment, - + CopyGrants: r.CopyGrants, + ResultDataType: r.ResultDataType, + NotNull: r.NotNull, + NullInputBehavior: r.NullInputBehavior, + Comment: r.Comment, + ExecuteAs: r.ExecuteAs, ProcedureDefinition: r.ProcedureDefinition, } if r.Arguments != nil { s := make([]ProcedureArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = ProcedureArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &ProcedureReturns2{ - ResultDataType: r.Returns.ResultDataType, - NotNull: r.Returns.NotNull, - } - } - opts.NullInputBehavior = r.NullInputBehavior - opts.ExecuteAs = r.ExecuteAs return opts } -func (r *CreateProcedureForPythonProcedureRequest) toOpts() *CreateProcedureForPythonProcedureOptions { - opts := &CreateProcedureForPythonProcedureOptions{ +func (r *CreateForPythonProcedureRequest) toOpts() *CreateForPythonProcedureOptions { + opts := &CreateForPythonProcedureOptions{ OrReplace: r.OrReplace, Secure: r.Secure, name: r.name, @@ -205,42 +186,41 @@ func (r *CreateProcedureForPythonProcedureRequest) toOpts() *CreateProcedureForP Handler: r.Handler, ExternalAccessIntegrations: r.ExternalAccessIntegrations, - - Comment: r.Comment, - - ProcedureDefinition: r.ProcedureDefinition, + Secrets: r.Secrets, + NullInputBehavior: r.NullInputBehavior, + Comment: r.Comment, + ExecuteAs: r.ExecuteAs, + ProcedureDefinition: r.ProcedureDefinition, } if r.Arguments != nil { s := make([]ProcedureArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = ProcedureArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &ProcedureReturns{} - if r.Returns.ResultDataType != nil { - opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ - ResultDataType: r.Returns.ResultDataType.ResultDataType, - Null: r.Returns.ResultDataType.Null, - NotNull: r.Returns.ResultDataType.NotNull, - } + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, + Null: r.Returns.ResultDataType.Null, + NotNull: r.Returns.ResultDataType.NotNull, } - if r.Returns.Table != nil { - opts.Returns.Table = &ProcedureReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = ProcedureColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &ProcedureReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = ProcedureColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } if r.Packages != nil { @@ -261,23 +241,11 @@ func (r *CreateProcedureForPythonProcedureRequest) toOpts() *CreateProcedureForP } opts.Imports = s } - if r.Secrets != nil { - s := make([]ProcedureSecret, len(r.Secrets)) - for i, v := range r.Secrets { - s[i] = ProcedureSecret{ - SecretVariableName: v.SecretVariableName, - SecretName: v.SecretName, - } - } - opts.Secrets = s - } - opts.NullInputBehavior = r.NullInputBehavior - opts.ExecuteAs = r.ExecuteAs return opts } -func (r *CreateProcedureForScalaProcedureRequest) toOpts() *CreateProcedureForScalaProcedureOptions { - opts := &CreateProcedureForScalaProcedureOptions{ +func (r *CreateForScalaProcedureRequest) toOpts() *CreateForScalaProcedureOptions { + opts := &CreateForScalaProcedureOptions{ OrReplace: r.OrReplace, Secure: r.Secure, name: r.name, @@ -286,44 +254,42 @@ func (r *CreateProcedureForScalaProcedureRequest) toOpts() *CreateProcedureForSc RuntimeVersion: r.RuntimeVersion, - Handler: r.Handler, - TargetPath: r.TargetPath, - - Comment: r.Comment, - + Handler: r.Handler, + TargetPath: r.TargetPath, + NullInputBehavior: r.NullInputBehavior, + Comment: r.Comment, + ExecuteAs: r.ExecuteAs, ProcedureDefinition: r.ProcedureDefinition, } if r.Arguments != nil { s := make([]ProcedureArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = ProcedureArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &ProcedureReturns{} - if r.Returns.ResultDataType != nil { - opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ - ResultDataType: r.Returns.ResultDataType.ResultDataType, - Null: r.Returns.ResultDataType.Null, - NotNull: r.Returns.ResultDataType.NotNull, - } + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, + Null: r.Returns.ResultDataType.Null, + NotNull: r.Returns.ResultDataType.NotNull, } - if r.Returns.Table != nil { - opts.Returns.Table = &ProcedureReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = ProcedureColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &ProcedureReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = ProcedureColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } if r.Packages != nil { @@ -344,108 +310,77 @@ func (r *CreateProcedureForScalaProcedureRequest) toOpts() *CreateProcedureForSc } opts.Imports = s } - opts.NullInputBehavior = r.NullInputBehavior - opts.ExecuteAs = r.ExecuteAs return opts } -func (r *CreateProcedureForSQLProcedureRequest) toOpts() *CreateProcedureForSQLProcedureOptions { - opts := &CreateProcedureForSQLProcedureOptions{ +func (r *CreateForSQLProcedureRequest) toOpts() *CreateForSQLProcedureOptions { + opts := &CreateForSQLProcedureOptions{ OrReplace: r.OrReplace, Secure: r.Secure, name: r.name, CopyGrants: r.CopyGrants, - Comment: r.Comment, - + NullInputBehavior: r.NullInputBehavior, + Comment: r.Comment, + ExecuteAs: r.ExecuteAs, ProcedureDefinition: r.ProcedureDefinition, } if r.Arguments != nil { s := make([]ProcedureArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = ProcedureArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &ProcedureReturns3{ - NotNull: r.Returns.NotNull, + opts.Returns.NotNull = r.Returns.NotNull + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, } - if r.Returns.ResultDataType != nil { - opts.Returns.ResultDataType = &ProcedureReturnsResultDataType{ - ResultDataType: r.Returns.ResultDataType.ResultDataType, - } - } - if r.Returns.Table != nil { - opts.Returns.Table = &ProcedureReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = ProcedureColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &ProcedureReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]ProcedureColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = ProcedureColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } - opts.NullInputBehavior = r.NullInputBehavior - opts.ExecuteAs = r.ExecuteAs return opts } func (r *AlterProcedureRequest) toOpts() *AlterProcedureOptions { opts := &AlterProcedureOptions{ - IfExists: r.IfExists, - name: r.name, - - RenameTo: r.RenameTo, - SetTags: r.SetTags, - UnsetTags: r.UnsetTags, - } - if r.ArgumentTypes != nil { - s := make([]ProcedureArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = ProcedureArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s - } - if r.Set != nil { - opts.Set = &ProcedureSet{ - LogLevel: r.Set.LogLevel, - TraceLevel: r.Set.TraceLevel, - Comment: r.Set.Comment, - } - } - if r.Unset != nil { - opts.Unset = &ProcedureUnset{ - Comment: r.Unset.Comment, - } + IfExists: r.IfExists, + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, + RenameTo: r.RenameTo, + SetComment: r.SetComment, + SetLogLevel: r.SetLogLevel, + SetTraceLevel: r.SetTraceLevel, + UnsetComment: r.UnsetComment, + SetTags: r.SetTags, + UnsetTags: r.UnsetTags, + ExecuteAs: r.ExecuteAs, } - opts.ExecuteAs = r.ExecuteAs return opts } func (r *DropProcedureRequest) toOpts() *DropProcedureOptions { opts := &DropProcedureOptions{ - IfExists: r.IfExists, - name: r.name, - } - if r.ArgumentTypes != nil { - s := make([]ProcedureArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = ProcedureArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s + IfExists: r.IfExists, + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, } return opts } @@ -458,34 +393,36 @@ func (r *ShowProcedureRequest) toOpts() *ShowProcedureOptions { return opts } -func (r procedureRow) convert() *Procedure { - return &Procedure{ - CreatedOn: r.CreatedOn, - Name: r.Name, - SchemaName: r.SchemaName, - MinNumArguments: r.MinNumArguments, - MaxNumArguments: r.MaxNumArguments, - Arguments: r.Arguments, - IsTableFunction: r.IsTableFunction, - } -} - func (r *DescribeProcedureRequest) toOpts() *DescribeProcedureOptions { opts := &DescribeProcedureOptions{ - name: r.name, - } - if r.ArgumentTypes != nil { - s := make([]ProcedureArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = ProcedureArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, } return opts } +func (r procedureRow) convert() *Procedure { + e := &Procedure{ + CreatedOn: r.CreatedOn, + Name: r.Name, + SchemaName: r.SchemaName, + IsBuiltin: r.IsBuiltin == "Y", + IsAggregate: r.IsAggregate == "Y", + IsAnsi: r.IsAnsi == "Y", + MinNumArguments: r.MinNumArguments, + MaxNumArguments: r.MaxNumArguments, + Arguments: r.Arguments, + Description: r.Description, + CatalogName: r.CatalogName, + IsTableFunction: r.IsTableFunction == "Y", + ValidForClustering: r.ValidForClustering == "Y", + } + if r.IsSecure.Valid { + e.IsSecure = r.IsSecure.String == "Y" + } + return e +} + func (r procedureDetailRow) convert() *ProcedureDetail { return &ProcedureDetail{ Property: r.Property, diff --git a/pkg/sdk/procedures_validations_gen.go b/pkg/sdk/procedures_validations_gen.go index 655d38e2b0..2bba03dc0a 100644 --- a/pkg/sdk/procedures_validations_gen.go +++ b/pkg/sdk/procedures_validations_gen.go @@ -1,25 +1,20 @@ package sdk +import "errors" + var ( - _ validatable = new(CreateProcedureForJavaProcedureOptions) - _ validatable = new(CreateProcedureForJavaScriptProcedureOptions) - _ validatable = new(CreateProcedureForPythonProcedureOptions) - _ validatable = new(CreateProcedureForScalaProcedureOptions) - _ validatable = new(CreateProcedureForSQLProcedureOptions) + _ validatable = new(CreateForJavaProcedureOptions) + _ validatable = new(CreateForJavaScriptProcedureOptions) + _ validatable = new(CreateForPythonProcedureOptions) + _ validatable = new(CreateForScalaProcedureOptions) + _ validatable = new(CreateForSQLProcedureOptions) + _ validatable = new(AlterProcedureOptions) + _ validatable = new(DropProcedureOptions) + _ validatable = new(ShowProcedureOptions) + _ validatable = new(DescribeProcedureOptions) ) -func (v *ProcedureReturns) validate() error { - if v == nil { - return ErrNilOptions - } - var errs []error - if ok := exactlyOneValueSet(v.ResultDataType, v.Table); !ok { - errs = append(errs, errOneOf("Returns.ResultDataType", "Returns.Table")) - } - return JoinErrors(errs...) -} - -func (opts *CreateProcedureForJavaProcedureOptions) validate() error { +func (opts *CreateForJavaProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -27,13 +22,13 @@ func (opts *CreateProcedureForJavaProcedureOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if opts.ProcedureDefinition == nil && opts.TargetPath != nil { + errs = append(errs, errors.New("TARGET_PATH must be nil when AS is nil")) } return JoinErrors(errs...) } -func (opts *CreateProcedureForJavaScriptProcedureOptions) validate() error { +func (opts *CreateForJavaScriptProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -44,7 +39,7 @@ func (opts *CreateProcedureForJavaScriptProcedureOptions) validate() error { return JoinErrors(errs...) } -func (opts *CreateProcedureForPythonProcedureOptions) validate() error { +func (opts *CreateForPythonProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -52,13 +47,10 @@ func (opts *CreateProcedureForPythonProcedureOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) - } return JoinErrors(errs...) } -func (opts *CreateProcedureForScalaProcedureOptions) validate() error { +func (opts *CreateForScalaProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -66,13 +58,13 @@ func (opts *CreateProcedureForScalaProcedureOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if opts.ProcedureDefinition == nil && opts.TargetPath != nil { + errs = append(errs, errors.New("TARGET_PATH must be nil when AS is nil")) } return JoinErrors(errs...) } -func (opts *CreateProcedureForSQLProcedureOptions) validate() error { +func (opts *CreateForSQLProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -91,32 +83,35 @@ func (opts *AlterProcedureOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } + if opts.RenameTo != nil && !ValidObjectIdentifier(opts.RenameTo) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + if !exactlyOneValueSet(opts.RenameTo, opts.SetComment, opts.SetLogLevel, opts.SetTraceLevel, opts.UnsetComment, opts.SetTags, opts.UnsetTags, opts.ExecuteAs) { + errs = append(errs, errExactlyOneOf("AlterProcedureOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "UnsetComment", "SetTags", "UnsetTags", "ExecuteAs")) + } return JoinErrors(errs...) } -func (opts *ShowProcedureOptions) validate() error { +func (opts *DropProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } var errs []error - if valueSet(opts.Like) && !valueSet(opts.Like.Pattern) { - errs = append(errs, ErrPatternRequiredForLikeKeyword) + if !ValidObjectIdentifier(opts.name) { + errs = append(errs, ErrInvalidObjectIdentifier) } return JoinErrors(errs...) } -func (opts *DescribeProcedureOptions) validate() error { +func (opts *ShowProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } var errs []error - if !ValidObjectIdentifier(opts.name) { - errs = append(errs, ErrInvalidObjectIdentifier) - } return JoinErrors(errs...) } -func (opts *DropProcedureOptions) validate() error { +func (opts *DescribeProcedureOptions) validate() error { if opts == nil { return ErrNilOptions } diff --git a/pkg/sdk/testint/procedures_integration_test.go b/pkg/sdk/testint/procedures_integration_test.go index 4189a154dd..fd2f30cc11 100644 --- a/pkg/sdk/testint/procedures_integration_test.go +++ b/pkg/sdk/testint/procedures_integration_test.go @@ -1,7 +1,6 @@ package testint import ( - "context" "errors" "testing" @@ -14,22 +13,13 @@ import ( func TestInt_CreateProcedures(t *testing.T) { client := testClient(t) - ctx := context.Background() + ctx := testContext(t) - _, warehouseCleanup := createWarehouse(t, client) - t.Cleanup(warehouseCleanup) - databaseTest, databaseCleanup := createDatabase(t, client) - t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) - t.Cleanup(schemaCleanup) + databaseTest, schemaTest := testDb(t), testSchema(t) - cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, argumentTypes []sdk.DataType) func() { + cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, ats []sdk.DataType) func() { return func() { - es := []sdk.ProcedureArgumentTypeRequest{} - for _, item := range argumentTypes { - es = append(es, *sdk.NewProcedureArgumentTypeRequest().WithArgDataType(item)) - } - err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id).WithArgumentTypes(es)) + err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id, ats)) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } @@ -38,34 +28,32 @@ func TestInt_CreateProcedures(t *testing.T) { } t.Run("create procedure for Java: returns result data type", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-java#reading-a-dynamically-specified-file-with-inputstream name := "file_reader_java_proc_snowflakefile" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - import java.io.InputStream; - import java.io.IOException; - import java.nio.charset.StandardCharsets; - import com.snowflake.snowpark_java.types.SnowflakeFile; - import com.snowflake.snowpark_java.Session; - class FileReader { - public String execute(Session session, String fileName) throws IOException { - InputStream input = SnowflakeFile.newInstance(fileName).getInputStream(); - return new String(input.readAllBytes(), StandardCharsets.UTF_8); - } - }` - resultDataType := sdk.NewProcedureReturnsResultDataTypeRequest().WithResultDataType(sdk.DataTypeVARCHAR) - procedureReturns := sdk.NewProcedureReturnsRequest().WithResultDataType(resultDataType) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("input").WithArgDataType(sdk.DataTypeVARCHAR) - procedurePackage := sdk.NewProcedurePackageRequest().WithPackage("com.snowflake:snowpark:latest") - request := sdk.NewCreateProcedureForJavaProcedureRequest(id). + definition := ` + import java.io.InputStream; + import java.io.IOException; + import java.nio.charset.StandardCharsets; + import com.snowflake.snowpark_java.types.SnowflakeFile; + import com.snowflake.snowpark_java.Session; + class FileReader { + public String execute(Session session, String fileName) throws IOException { + InputStream input = SnowflakeFile.newInstance(fileName).getInputStream(); + return new String(input.readAllBytes(), StandardCharsets.UTF_8); + } + }` + + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewProcedureReturnsRequest().WithResultDataType(dt) + argument := sdk.NewProcedureArgumentRequest("input", sdk.DataTypeVARCHAR) + packages := []sdk.ProcedurePackageRequest{*sdk.NewProcedurePackageRequest("com.snowflake:snowpark:latest")} + request := sdk.NewCreateForJavaProcedureRequest(id, *returns, "11", packages, "FileReader.execute"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("11")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithHandler("FileReader.execute"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForJava(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForJava(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -75,35 +63,32 @@ func TestInt_CreateProcedures(t *testing.T) { }) t.Run("create procedure for Java: returns table", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-java#specifying-return-column-names-and-types name := "filter_by_role" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - import com.snowflake.snowpark_java.*; - public class Filter { - public DataFrame filterByRole(Session session, String tableName, String role) { - DataFrame table = session.table(tableName); - DataFrame filteredRows = table.filter(Functions.col("role").equal_to(Functions.lit(role))); - return filteredRows; - } - }` - column1 := sdk.NewProcedureColumnRequest().WithColumnName("id").WithColumnDataType(sdk.DataTypeNumber) - column2 := sdk.NewProcedureColumnRequest().WithColumnName("name").WithColumnDataType(sdk.DataTypeVARCHAR) - column3 := sdk.NewProcedureColumnRequest().WithColumnName("role").WithColumnDataType(sdk.DataTypeVARCHAR) - procedureReturnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) - procedureReturns := sdk.NewProcedureReturnsRequest().WithTable(procedureReturnsTable) - procedureArgument1 := sdk.NewProcedureArgumentRequest().WithArgName("table_name").WithArgDataType(sdk.DataTypeVARCHAR) - procedureArgument2 := sdk.NewProcedureArgumentRequest().WithArgName("role").WithArgDataType(sdk.DataTypeVARCHAR) - procedurePackage := sdk.NewProcedurePackageRequest().WithPackage("com.snowflake:snowpark:latest") - request := sdk.NewCreateProcedureForJavaProcedureRequest(id). + definition := ` + import com.snowflake.snowpark_java.*; + public class Filter { + public DataFrame filterByRole(Session session, String tableName, String role) { + DataFrame table = session.table(tableName); + DataFrame filteredRows = table.filter(Functions.col("role").equal_to(Functions.lit(role))); + return filteredRows; + } + }` + column1 := sdk.NewProcedureColumnRequest("id", sdk.DataTypeNumber) + column2 := sdk.NewProcedureColumnRequest("name", sdk.DataTypeVARCHAR) + column3 := sdk.NewProcedureColumnRequest("role", sdk.DataTypeVARCHAR) + returnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) + returns := sdk.NewProcedureReturnsRequest().WithTable(returnsTable) + arg1 := sdk.NewProcedureArgumentRequest("table_name", sdk.DataTypeVARCHAR) + arg2 := sdk.NewProcedureArgumentRequest("role", sdk.DataTypeVARCHAR) + packages := []sdk.ProcedurePackageRequest{*sdk.NewProcedurePackageRequest("com.snowflake:snowpark:latest")} + request := sdk.NewCreateForJavaProcedureRequest(id, *returns, "11", packages, "Filter.filterByRole"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("11")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument1, *procedureArgument2}). - WithReturns(procedureReturns). - WithHandler("Filter.filterByRole"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForJava(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*arg1, *arg2}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForJava(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR, sdk.DataTypeVARCHAR})) @@ -113,32 +98,29 @@ func TestInt_CreateProcedures(t *testing.T) { }) t.Run("create procedure for Javascript", func(t *testing.T) { + // https://docs.snowflake.com/en/sql-reference/sql/create-procedure#examples name := "stproc1" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - var sql_command = "INSERT INTO stproc_test_table1 (num_col1) VALUES (" + FLOAT_PARAM1 + ")"; - try { - snowflake.execute ( - {sqlText: sql_command} - ); - return "Succeeded."; // Return a success/error indicator. - } - catch (err) { - return "Failed: " + err; // Return a success/error indicator. - }` - procedureReturns := sdk.NewProcedureReturns2Request().WithResultDataType("STRING") - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("FLOAT_PARAM1").WithArgDataType("FLOAT") - request := sdk.NewCreateProcedureForJavaScriptProcedureRequest(id). - WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithNullInputBehavior(sdk.ProcedureNullInputBehaviorStrict). - WithExecuteAs(sdk.ProcedureExecuteAsCaller). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForJavaScript(ctx, request) - require.NoError(t, err) - t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{"FLOAT"})) + definition := ` + var sql_command = "INSERT INTO stproc_test_table1 (num_col1) VALUES (" + FLOAT_PARAM1 + ")"; + try { + snowflake.execute ( + {sqlText: sql_command} + ); + return "Succeeded."; // Return a success/error indicator. + } + catch (err) { + return "Failed: " + err; // Return a success/error indicator. + }` + argument := sdk.NewProcedureArgumentRequest("FLOAT_PARAM1", sdk.DataTypeFloat) + request := sdk.NewCreateForJavaScriptProcedureRequest(id, sdk.DataTypeString, definition). + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithNullInputBehavior(sdk.NullInputBehaviorPointer(sdk.NullInputBehaviorStrict)). + WithExecuteAs(sdk.ExecuteAsPointer(sdk.ExecuteAsCaller)) + err := client.Procedures.CreateForJavaScript(ctx, request) + require.NoError(t, err) + t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeFloat})) procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest()) require.NoError(t, err) @@ -146,33 +128,30 @@ func TestInt_CreateProcedures(t *testing.T) { }) t.Run("create procedure for Scala: returns result data type", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-scala#reading-a-dynamically-specified-file-with-snowflakefile name := "file_reader_scala_proc_snowflakefile" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - import java.io.InputStream - import java.nio.charset.StandardCharsets - import com.snowflake.snowpark_java.types.SnowflakeFile - import com.snowflake.snowpark_java.Session - object FileReader { - def execute(session: Session, fileName: String): String = { - var input: InputStream = SnowflakeFile.newInstance(fileName).getInputStream() - return new String(input.readAllBytes(), StandardCharsets.UTF_8) - } - }` - resultDataType := sdk.NewProcedureReturnsResultDataTypeRequest().WithResultDataType(sdk.DataTypeVARCHAR) - procedureReturns := sdk.NewProcedureReturnsRequest().WithResultDataType(resultDataType) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("input").WithArgDataType(sdk.DataTypeVARCHAR) - procedurePackage := sdk.NewProcedurePackageRequest().WithPackage("com.snowflake:snowpark:latest") - request := sdk.NewCreateProcedureForScalaProcedureRequest(id). + definition := ` + import java.io.InputStream + import java.nio.charset.StandardCharsets + import com.snowflake.snowpark_java.types.SnowflakeFile + import com.snowflake.snowpark_java.Session + object FileReader { + def execute(session: Session, fileName: String): String = { + var input: InputStream = SnowflakeFile.newInstance(fileName).getInputStream() + return new String(input.readAllBytes(), StandardCharsets.UTF_8) + } + }` + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewProcedureReturnsRequest().WithResultDataType(dt) + argument := sdk.NewProcedureArgumentRequest("input", sdk.DataTypeVARCHAR) + packages := []sdk.ProcedurePackageRequest{*sdk.NewProcedurePackageRequest("com.snowflake:snowpark:latest")} + request := sdk.NewCreateForScalaProcedureRequest(id, *returns, "2.12", packages, "FileReader.execute"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("2.12")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithHandler("FileReader.execute"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForScala(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForScala(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -182,36 +161,33 @@ func TestInt_CreateProcedures(t *testing.T) { }) t.Run("create procedure for Scala: returns table", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-scala#specifying-return-column-names-and-types name := "filter_by_role" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - import com.snowflake.snowpark.functions._ - import com.snowflake.snowpark._ - object Filter { - def filterByRole(session: Session, tableName: String, role: String): DataFrame = { - val table = session.table(tableName) - val filteredRows = table.filter(col("role") === role) - return filteredRows - } - }` - column1 := sdk.NewProcedureColumnRequest().WithColumnName("id").WithColumnDataType(sdk.DataTypeNumber) - column2 := sdk.NewProcedureColumnRequest().WithColumnName("name").WithColumnDataType(sdk.DataTypeVARCHAR) - column3 := sdk.NewProcedureColumnRequest().WithColumnName("role").WithColumnDataType(sdk.DataTypeVARCHAR) - procedureReturnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) - procedureReturns := sdk.NewProcedureReturnsRequest().WithTable(procedureReturnsTable) - procedureArgument1 := sdk.NewProcedureArgumentRequest().WithArgName("table_name").WithArgDataType(sdk.DataTypeVARCHAR) - procedureArgument2 := sdk.NewProcedureArgumentRequest().WithArgName("role").WithArgDataType(sdk.DataTypeVARCHAR) - procedurePackage := sdk.NewProcedurePackageRequest().WithPackage("com.snowflake:snowpark:latest") - request := sdk.NewCreateProcedureForScalaProcedureRequest(id). + definition := ` + import com.snowflake.snowpark.functions._ + import com.snowflake.snowpark._ + object Filter { + def filterByRole(session: Session, tableName: String, role: String): DataFrame = { + val table = session.table(tableName) + val filteredRows = table.filter(col("role") === role) + return filteredRows + } + }` + column1 := sdk.NewProcedureColumnRequest("id", sdk.DataTypeNumber) + column2 := sdk.NewProcedureColumnRequest("name", sdk.DataTypeVARCHAR) + column3 := sdk.NewProcedureColumnRequest("role", sdk.DataTypeVARCHAR) + returnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) + returns := sdk.NewProcedureReturnsRequest().WithTable(returnsTable) + arg1 := sdk.NewProcedureArgumentRequest("table_name", sdk.DataTypeVARCHAR) + arg2 := sdk.NewProcedureArgumentRequest("role", sdk.DataTypeVARCHAR) + packages := []sdk.ProcedurePackageRequest{*sdk.NewProcedurePackageRequest("com.snowflake:snowpark:latest")} + request := sdk.NewCreateForScalaProcedureRequest(id, *returns, "2.12", packages, "Filter.filterByRole"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("2.12")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument1, *procedureArgument2}). - WithReturns(procedureReturns). - WithHandler("Filter.filterByRole"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForScala(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*arg1, *arg2}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForScala(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR, sdk.DataTypeVARCHAR})) @@ -221,30 +197,29 @@ func TestInt_CreateProcedures(t *testing.T) { }) t.Run("create procedure for Python: returns result data type", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-python#running-concurrent-tasks-with-worker-processes name := "joblib_multiprocessing_proc" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` + definition := ` import joblib from math import sqrt def joblib_multiprocessing(session, i): result = joblib.Parallel(n_jobs=-1)(joblib.delayed(sqrt)(i ** 2) for i in range(10)) return str(result)` - resultDataType := sdk.NewProcedureReturnsResultDataTypeRequest().WithResultDataType("STRING") - procedureReturns := sdk.NewProcedureReturnsRequest().WithResultDataType(resultDataType) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("i").WithArgDataType("INT") - procedurePackage1 := sdk.NewProcedurePackageRequest().WithPackage("snowflake-snowpark-python") - procedurePackage2 := sdk.NewProcedurePackageRequest().WithPackage("joblib") - request := sdk.NewCreateProcedureForPythonProcedureRequest(id). + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeString) + returns := sdk.NewProcedureReturnsRequest().WithResultDataType(dt) + argument := sdk.NewProcedureArgumentRequest("i", "INT") + packages := []sdk.ProcedurePackageRequest{ + *sdk.NewProcedurePackageRequest("snowflake-snowpark-python"), + *sdk.NewProcedurePackageRequest("joblib"), + } + request := sdk.NewCreateForPythonProcedureRequest(id, *returns, "3.8", packages, "joblib_multiprocessing"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("3.8")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithHandler("joblib_multiprocessing"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage1, *procedurePackage2}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForPython(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForPython(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{"string"})) @@ -254,31 +229,28 @@ def joblib_multiprocessing(session, i): }) t.Run("create procedure for Python: returns table", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-python#specifying-return-column-names-and-types name := "filterByRole" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` + definition := ` from snowflake.snowpark.functions import col def filter_by_role(session, table_name, role): df = session.table(table_name) return df.filter(col("role") == role)` - column1 := sdk.NewProcedureColumnRequest().WithColumnName("id").WithColumnDataType(sdk.DataTypeNumber) - column2 := sdk.NewProcedureColumnRequest().WithColumnName("name").WithColumnDataType(sdk.DataTypeVARCHAR) - column3 := sdk.NewProcedureColumnRequest().WithColumnName("role").WithColumnDataType(sdk.DataTypeVARCHAR) - procedureReturnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) - procedureReturns := sdk.NewProcedureReturnsRequest().WithTable(procedureReturnsTable) - procedureArgument1 := sdk.NewProcedureArgumentRequest().WithArgName("table_name").WithArgDataType(sdk.DataTypeVARCHAR) - procedureArgument2 := sdk.NewProcedureArgumentRequest().WithArgName("role").WithArgDataType(sdk.DataTypeVARCHAR) - procedurePackage := sdk.NewProcedurePackageRequest().WithPackage("snowflake-snowpark-python") - request := sdk.NewCreateProcedureForPythonProcedureRequest(id). + column1 := sdk.NewProcedureColumnRequest("id", sdk.DataTypeNumber) + column2 := sdk.NewProcedureColumnRequest("name", sdk.DataTypeVARCHAR) + column3 := sdk.NewProcedureColumnRequest("role", sdk.DataTypeVARCHAR) + eeturnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2, *column3}) + returns := sdk.NewProcedureReturnsRequest().WithTable(eeturnsTable) + arg1 := sdk.NewProcedureArgumentRequest("table_name", sdk.DataTypeVARCHAR) + arg2 := sdk.NewProcedureArgumentRequest("role", sdk.DataTypeVARCHAR) + packages := []sdk.ProcedurePackageRequest{*sdk.NewProcedurePackageRequest("snowflake-snowpark-python")} + request := sdk.NewCreateForPythonProcedureRequest(id, *returns, "3.8", packages, "filter_by_role"). WithOrReplace(sdk.Bool(true)). - WithRuntimeVersion(sdk.String("3.8")). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument1, *procedureArgument2}). - WithReturns(procedureReturns). - WithHandler("filter_by_role"). - WithPackages([]sdk.ProcedurePackageRequest{*procedurePackage}). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForPython(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*arg1, *arg2}). + WithProcedureDefinition(sdk.String(definition)) + err := client.Procedures.CreateForPython(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR, sdk.DataTypeVARCHAR})) @@ -288,23 +260,22 @@ def filter_by_role(session, table_name, role): }) t.Run("create procedure for SQL: returns result data type", func(t *testing.T) { + // https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-snowflake-scripting name := "output_message" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - BEGIN - RETURN message; - END;` + definition := ` + BEGIN + RETURN message; + END;` - resultDataType := sdk.NewProcedureReturnsResultDataTypeRequest().WithResultDataType(sdk.DataTypeVARCHAR) - procedureReturns := sdk.NewProcedureReturns3Request().WithResultDataType(resultDataType).WithNotNull(sdk.Bool(true)) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("message").WithArgDataType(sdk.DataTypeVARCHAR) - request := sdk.NewCreateProcedureForSQLProcedureRequest(id). + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) + argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) + request := sdk.NewCreateForSQLProcedureRequest(id, *returns, definition). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForSQL(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}) + err := client.Procedures.CreateForSQL(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -317,23 +288,21 @@ def filter_by_role(session, table_name, role): name := "find_invoice_by_id" id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) - as := ` - DECLARE - res RESULTSET DEFAULT (SELECT * FROM invoices WHERE id = :id); - BEGIN - RETURN TABLE(res); - END;` - column1 := sdk.NewProcedureColumnRequest().WithColumnName("id").WithColumnDataType("INTEGER") - column2 := sdk.NewProcedureColumnRequest().WithColumnName("price").WithColumnDataType("NUMBER(12,2)") - procedureReturnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2}) - procedureReturns := sdk.NewProcedureReturns3Request().WithTable(procedureReturnsTable) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("id").WithArgDataType(sdk.DataTypeVARCHAR) - request := sdk.NewCreateProcedureForSQLProcedureRequest(id). + definition := ` + DECLARE + res RESULTSET DEFAULT (SELECT * FROM invoices WHERE id = :id); + BEGIN + RETURN TABLE(res); + END;` + column1 := sdk.NewProcedureColumnRequest("id", "INTEGER") + column2 := sdk.NewProcedureColumnRequest("price", "NUMBER(12,2)") + returnsTable := sdk.NewProcedureReturnsTableRequest().WithColumns([]sdk.ProcedureColumnRequest{*column1, *column2}) + returns := sdk.NewProcedureSQLReturnsRequest().WithTable(returnsTable) + argument := sdk.NewProcedureArgumentRequest("id", sdk.DataTypeVARCHAR) + request := sdk.NewCreateForSQLProcedureRequest(id, *returns, definition). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForSQL(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}) + err := client.Procedures.CreateForSQL(ctx, request) require.NoError(t, err) t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -343,26 +312,38 @@ def filter_by_role(session, table_name, role): }) } -func TestInt_AlterAndShowProcedures(t *testing.T) { +func TestInt_OtherProcedureFunctions(t *testing.T) { client := testClient(t) - ctx := context.Background() - - _, warehouseCleanup := createWarehouse(t, client) - t.Cleanup(warehouseCleanup) - databaseTest, databaseCleanup := createDatabase(t, client) - t.Cleanup(databaseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, databaseTest) - t.Cleanup(schemaCleanup) + ctx := testContext(t) + + databaseTest, schemaTest := testDb(t), testSchema(t) tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) t.Cleanup(tagCleanup) - cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, argumentTypes []sdk.DataType) func() { + assertProcedure := func(t *testing.T, id sdk.SchemaObjectIdentifier, secure bool) { + t.Helper() + + procedure, err := client.Procedures.ShowByID(ctx, id) + require.NoError(t, err) + + assert.NotEmpty(t, procedure.CreatedOn) + assert.Equal(t, id.Name(), procedure.Name) + assert.Equal(t, false, procedure.IsBuiltin) + assert.Equal(t, false, procedure.IsAggregate) + assert.Equal(t, false, procedure.IsAnsi) + assert.Equal(t, 1, procedure.MinNumArguments) + assert.Equal(t, 1, procedure.MaxNumArguments) + assert.NotEmpty(t, procedure.Arguments) + assert.NotEmpty(t, procedure.Description) + assert.NotEmpty(t, procedure.CatalogName) + assert.Equal(t, false, procedure.IsTableFunction) + assert.Equal(t, false, procedure.ValidForClustering) + assert.Equal(t, secure, procedure.IsSecure) + } + + cleanupProcedureHandle := func(id sdk.SchemaObjectIdentifier, ats []sdk.DataType) func() { return func() { - es := []sdk.ProcedureArgumentTypeRequest{} - for _, item := range argumentTypes { - es = append(es, *sdk.NewProcedureArgumentTypeRequest().WithArgDataType(item)) - } - err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id).WithArgumentTypes(es)) + err := client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id, ats)) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } @@ -373,21 +354,20 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { createProcedureForSQLHandle := func(t *testing.T, cleanup bool) *sdk.Procedure { t.Helper() - as := ` + definition := ` BEGIN RETURN message; END;` id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) - resultDataType := sdk.NewProcedureReturnsResultDataTypeRequest().WithResultDataType(sdk.DataTypeVARCHAR) - procedureReturns := sdk.NewProcedureReturns3Request().WithResultDataType(resultDataType).WithNotNull(sdk.Bool(true)) - procedureArgument := sdk.NewProcedureArgumentRequest().WithArgName("message").WithArgDataType(sdk.DataTypeVARCHAR) - request := sdk.NewCreateProcedureForSQLProcedureRequest(id). + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) + argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) + request := sdk.NewCreateForSQLProcedureRequest(id, *returns, definition). + WithSecure(sdk.Bool(true)). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.ProcedureArgumentRequest{*procedureArgument}). - WithReturns(procedureReturns). - WithExecuteAs(sdk.ProcedureExecuteAsCaller). - WithProcedureDefinition(sdk.String(as)) - err := client.Procedures.CreateProcedureForSQL(ctx, request) + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithExecuteAs(sdk.ExecuteAsPointer(sdk.ExecuteAsCaller)) + err := client.Procedures.CreateForSQL(ctx, request) require.NoError(t, err) if cleanup { t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) @@ -397,8 +377,8 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { return procedure } - defaultArgumentTypes := []sdk.ProcedureArgumentTypeRequest{ - *sdk.NewProcedureArgumentTypeRequest().WithArgDataType(sdk.DataTypeVARCHAR), + defaultAlterRequest := func(id sdk.SchemaObjectIdentifier) *sdk.AlterProcedureRequest { + return sdk.NewAlterProcedureRequest(id, []sdk.DataType{sdk.DataTypeVARCHAR}) } t.Run("alter procedure: rename", func(t *testing.T) { @@ -406,8 +386,7 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) - request := sdk.NewAlterProcedureRequest(id).WithRenameTo(&nid).WithArgumentTypes(defaultArgumentTypes) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithRenameTo(&nid)) if err != nil { t.Cleanup(cleanupProcedureHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) } else { @@ -427,49 +406,45 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - set := sdk.NewProcedureSetRequest().WithLogLevel(sdk.String("DEBUG")) - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetLogLevel(sdk.String("DEBUG"))) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("alter procedure: set trace level", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - set := sdk.NewProcedureSetRequest().WithTraceLevel(sdk.String("ALWAYS")) - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetTraceLevel(sdk.String("ALWAYS"))) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("alter procedure: set comment", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - set := sdk.NewProcedureSetRequest().WithComment(sdk.String("comment")) - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetComment(sdk.String("comment"))) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("alter procedure: unset comment", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - unset := sdk.NewProcedureUnsetRequest().WithComment(sdk.Bool(true)) - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnset(unset) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithUnsetComment(sdk.Bool(true))) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("alter procedure: set execute as", func(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithExecuteAs(sdk.ProcedureExecuteAsOwner) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithExecuteAs(sdk.ExecuteAsPointer(sdk.ExecuteAsOwner))) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("alter procedure: set and unset tags", func(t *testing.T) { @@ -479,19 +454,19 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { setTags := []sdk.TagAssociation{ { Name: tagTest.ID(), - Value: "abc", + Value: "v1", }, } - request := sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSetTags(setTags) - err := client.Procedures.Alter(ctx, request) + err := client.Procedures.Alter(ctx, defaultAlterRequest(id).WithSetTags(setTags)) require.NoError(t, err) + assertProcedure(t, id, true) unsetTags := []sdk.ObjectIdentifier{ tagTest.ID(), } - request = sdk.NewAlterProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnsetTags(unsetTags) - err = client.Procedures.Alter(ctx, request) + err = client.Procedures.Alter(ctx, defaultAlterRequest(id).WithUnsetTags(unsetTags)) require.NoError(t, err) + assertProcedure(t, id, true) }) t.Run("show procedure for SQL: without like", func(t *testing.T) { @@ -510,7 +485,7 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { f1 := createProcedureForSQLHandle(t, true) f2 := createProcedureForSQLHandle(t, true) - procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(f1.Name)) + procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(&sdk.Like{Pattern: &f1.Name})) require.NoError(t, err) require.Equal(t, 1, len(procedures)) @@ -519,7 +494,7 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { }) t.Run("show procedure for SQL: no matches", func(t *testing.T) { - procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(random.String())) + procedures, err := client.Procedures.Show(ctx, sdk.NewShowProcedureRequest().WithLike(&sdk.Like{Pattern: sdk.String(random.String())})) require.NoError(t, err) require.Equal(t, 0, len(procedures)) }) @@ -528,9 +503,36 @@ func TestInt_AlterAndShowProcedures(t *testing.T) { f := createProcedureForSQLHandle(t, true) id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - request := sdk.NewDescribeProcedureRequest(id).WithArgumentTypes(defaultArgumentTypes) + request := sdk.NewDescribeProcedureRequest(id, []sdk.DataType{sdk.DataTypeString}) details, err := client.Procedures.Describe(ctx, request) require.NoError(t, err) - require.Greater(t, len(details), 0) + pairs := make(map[string]string) + for _, detail := range details { + pairs[detail.Property] = detail.Value + } + require.Equal(t, "SQL", pairs["language"]) + require.Equal(t, "CALLER", pairs["execute as"]) + require.Equal(t, "(MESSAGE VARCHAR)", pairs["signature"]) + require.Equal(t, "\n\tBEGIN\n\t\tRETURN message;\n\tEND;", pairs["body"]) + }) + + t.Run("drop procedure for SQL", func(t *testing.T) { + definition := ` + BEGIN + RETURN message; + END;` + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.String()) + dt := sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewProcedureSQLReturnsRequest().WithResultDataType(dt).WithNotNull(sdk.Bool(true)) + argument := sdk.NewProcedureArgumentRequest("message", sdk.DataTypeVARCHAR) + request := sdk.NewCreateForSQLProcedureRequest(id, *returns, definition). + WithOrReplace(sdk.Bool(true)). + WithArguments([]sdk.ProcedureArgumentRequest{*argument}). + WithExecuteAs(sdk.ExecuteAsPointer(sdk.ExecuteAsCaller)) + err := client.Procedures.CreateForSQL(ctx, request) + require.NoError(t, err) + + err = client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id, []sdk.DataType{sdk.DataTypeVARCHAR})) + require.NoError(t, err) }) }