From 17ef49f54533d3cbd08bf2147ba5f4c8eecb7a07 Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Mon, 4 Dec 2023 23:01:00 -0800 Subject: [PATCH] update functions --- pkg/sdk/common_types.go | 39 ++ pkg/sdk/functions_def.go | 296 ++++--------- pkg/sdk/functions_dto_builders_gen.go | 406 ++++++++--------- pkg/sdk/functions_dto_gen.go | 161 ++++--- pkg/sdk/functions_gen.go | 366 +++++++--------- pkg/sdk/functions_gen_test.go | 302 +++++++------ pkg/sdk/functions_impl_gen.go | 408 +++++++----------- pkg/sdk/functions_validations_gen.go | 104 +++-- pkg/sdk/poc/generator/keyword_builders.go | 4 +- pkg/sdk/testint/functions_integration_test.go | 315 +++++++------- 10 files changed, 1106 insertions(+), 1295 deletions(-) diff --git a/pkg/sdk/common_types.go b/pkg/sdk/common_types.go index 57a4f862e0..b2a41d1e80 100644 --- a/pkg/sdk/common_types.go +++ b/pkg/sdk/common_types.go @@ -207,3 +207,42 @@ func (row *propertyRow) toBoolProperty() *BoolProperty { Description: row.Description, } } + +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 ReturnResultsBehavior string + +var ( + ReturnResultsBehaviorVolatile ReturnResultsBehavior = "VOLATILE" + ReturnResultsBehaviorImmutable ReturnResultsBehavior = "IMMUTABLE" +) + +func ReturnResultsBehaviorPointer(v ReturnResultsBehavior) *ReturnResultsBehavior { + return &v +} + +type ReturnNullValues string + +var ( + ReturnNullValuesNull ReturnNullValues = "NULL" + ReturnNullValuesNotNull ReturnNullValues = "NOT NULL" +) + +func ReturnNullValuesPointer(v ReturnNullValues) *ReturnNullValues { + return &v +} + +type Secret struct { + VariableName string `ddl:"keyword,single_quotes"` + Name string `ddl:"parameter,no_quotes"` +} diff --git a/pkg/sdk/functions_def.go b/pkg/sdk/functions_def.go index 0d9fed671a..55f7250820 100644 --- a/pkg/sdk/functions_def.go +++ b/pkg/sdk/functions_def.go @@ -5,24 +5,22 @@ import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/gen //go:generate go run ./poc/main.go var functionArgument = g.NewQueryStruct("FunctionArgument"). - Text("ArgName", g.KeywordOptions().NoQuotes()). - Text("ArgDataType", g.KeywordOptions().NoQuotes()). - OptionalTextAssignment("Default", g.ParameterOptions().SingleQuotes()) - -var functionArgumentType = g.NewQueryStruct("FunctionArgumentType"). - 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 functionColumn = g.NewQueryStruct("FunctionColumn"). - Text("ColumnName", g.KeywordOptions().NoQuotes()). - Text("ColumnDataType", g.KeywordOptions().NoQuotes()) - -var functionSecret = g.NewQueryStruct("FunctionSecret"). - Text("SecretVariableName", g.KeywordOptions().SingleQuotes()). - Text("SecretName", g.KeywordOptions().NoQuotes()) + Text("ColumnName", g.KeywordOptions().NoQuotes().Required()). + PredefinedQueryStructField("ColumnDataType", "DataType", g.KeywordOptions().NoQuotes().Required()) var functionReturns = g.NewQueryStruct("FunctionReturns"). - OptionalText("ResultDataType", g.KeywordOptions()). - QueryStructField( + OptionalQueryStructField( + "ResultDataType", + g.NewQueryStruct("FunctionReturnsResultDataType"). + PredefinedQueryStructField("ResultDataType", "DataType", g.KeywordOptions().NoQuotes().Required()), + g.KeywordOptions(), + ). + OptionalQueryStructField( "Table", g.NewQueryStruct("FunctionReturnsTable"). ListQueryStructField( @@ -31,27 +29,11 @@ var functionReturns = g.NewQueryStruct("FunctionReturns"). g.ParameterOptions().Parentheses().NoEquals(), ), g.KeywordOptions().SQL("TABLE"), - ) - -var functionSet = g.NewQueryStruct("FunctionSet"). - OptionalTextAssignment("LOG_LEVEL", g.ParameterOptions().SingleQuotes()). - OptionalTextAssignment("TRACE_LEVEL", g.ParameterOptions().SingleQuotes()). - OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - OptionalSQL("SECURE") - -var functionUnset = g.NewQueryStruct("FunctionUnset"). - OptionalSQL("SECURE"). - OptionalSQL("COMMENT"). - OptionalSQL("LOG_LEVEL"). - OptionalSQL("TRACE_LEVEL") + ).WithValidation(g.ExactlyOneValueSet, "ResultDataType", "Table") var ( - functionNullOrNot = g.NewQueryStruct("FunctionNullOrNot").OptionalSQL("NULL").OptionalSQL("NOT NULL") - functionStrictOrNot = g.NewQueryStruct("FunctionStrictOrNot").OptionalSQL("STRICT").OptionalSQL("CALLED ON NULL INPUT") - functionVolatileOrNot = g.NewQueryStruct("FunctionVolatileOrNot").OptionalSQL("VOLATILE").OptionalSQL("IMMUTABLE") - functionImports = g.NewQueryStruct("FunctionImports").Text("Import", g.KeywordOptions().SingleQuotes()) - functionPackages = g.NewQueryStruct("FunctionPackages").Text("Package", g.KeywordOptions().SingleQuotes()) - functionDefinition = g.NewQueryStruct("FunctionDefinition").Text("Definition", g.KeywordOptions()) + functionImports = g.NewQueryStruct("FunctionImports").Text("Import", g.KeywordOptions().SingleQuotes()) + functionPackages = g.NewQueryStruct("FunctionPackages").Text("Package", g.KeywordOptions().SingleQuotes()) ) var FunctionsDef = g.NewInterface( @@ -59,9 +41,9 @@ var FunctionsDef = g.NewInterface( "Function", g.KindOfT[SchemaObjectIdentifier](), ).CustomOperation( - "CreateFunctionForJava", - "https://docs.snowflake.com/en/sql-reference/sql/create-function", - g.NewQueryStruct("CreateFunctionForJava"). + "CreateForJava", + "https://docs.snowflake.com/en/sql-reference/sql/create-function#java-handler", + g.NewQueryStruct("CreateForJava"). Create(). OrReplace(). OptionalSQL("TEMPORARY"). @@ -77,25 +59,13 @@ var FunctionsDef = g.NewInterface( QueryStructField( "Returns", functionReturns, - g.KeywordOptions().SQL("RETURNS"), - ). - OptionalQueryStructField( - "NullOrNot", - functionNullOrNot, - g.KeywordOptions(), + g.KeywordOptions().SQL("RETURNS").Required(), ). + PredefinedQueryStructField("ReturnNullValues", "*ReturnNullValues", g.KeywordOptions()). SQL("LANGUAGE JAVA"). - OptionalQueryStructField( - "StrictOrNot", - functionStrictOrNot, - g.KeywordOptions(), - ). - OptionalQueryStructField( - "VolatileOrNot", - functionVolatileOrNot, - g.KeywordOptions(), - ). - TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). + PredefinedQueryStructField("ReturnResultsBehavior", "*ReturnResultsBehavior", g.KeywordOptions()). + OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). ListQueryStructField( "Imports", @@ -107,30 +77,22 @@ var FunctionsDef = g.NewInterface( functionPackages, g.ParameterOptions().Parentheses().SQL("PACKAGES"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()). - ListQueryStructField( - "Secrets", - functionSecret, - g.ParameterOptions().Parentheses().SQL("SECRETS"), - ). + ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()). OptionalTextAssignment("TARGET_PATH", g.ParameterOptions().SingleQuotes()). - QueryStructField( - "FunctionDefinition", - functionDefinition, - g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS"), - ). - WithValidation(g.ValidIdentifier, "name"), + PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"). + WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"), ).CustomOperation( - "CreateFunctionForJavascript", - "https://docs.snowflake.com/en/sql-reference/sql/create-function", - g.NewQueryStruct("CreateFunctionForJavascript"). + "CreateForJavascript", + "https://docs.snowflake.com/en/sql-reference/sql/create-function#javascript-handler", + g.NewQueryStruct("CreateForJavascript"). Create(). OrReplace(). OptionalSQL("TEMPORARY"). OptionalSQL("SECURE"). SQL("FUNCTION"). - IfNotExists(). Name(). ListQueryStructField( "Arguments", @@ -140,35 +102,19 @@ var FunctionsDef = g.NewInterface( QueryStructField( "Returns", functionReturns, - g.KeywordOptions().SQL("RETURNS"), - ). - OptionalQueryStructField( - "NullOrNot", - functionNullOrNot, - g.KeywordOptions(), + g.KeywordOptions().SQL("RETURNS").Required(), ). + PredefinedQueryStructField("ReturnNullValues", "*ReturnNullValues", g.KeywordOptions()). SQL("LANGUAGE JAVASCRIPT"). - OptionalQueryStructField( - "StrictOrNot", - functionStrictOrNot, - g.KeywordOptions(), - ). - OptionalQueryStructField( - "VolatileOrNot", - functionVolatileOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). + PredefinedQueryStructField("ReturnResultsBehavior", "*ReturnResultsBehavior", g.KeywordOptions()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - QueryStructField( - "FunctionDefinition", - functionDefinition, - g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS"), - ). + PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()). WithValidation(g.ValidIdentifier, "name"), ).CustomOperation( - "CreateFunctionForPython", - "https://docs.snowflake.com/en/sql-reference/sql/create-function", - g.NewQueryStruct("CreateFunctionForPython"). + "CreateForPython", + "https://docs.snowflake.com/en/sql-reference/sql/create-function#python-handler", + g.NewQueryStruct("CreateForPython"). Create(). OrReplace(). OptionalSQL("TEMPORARY"). @@ -184,25 +130,13 @@ var FunctionsDef = g.NewInterface( QueryStructField( "Returns", functionReturns, - g.KeywordOptions().SQL("RETURNS"), - ). - OptionalQueryStructField( - "NullOrNot", - functionNullOrNot, - g.KeywordOptions(), + g.KeywordOptions().SQL("RETURNS").Required(), ). + PredefinedQueryStructField("ReturnNullValues", "*ReturnNullValues", g.KeywordOptions()). SQL("LANGUAGE PYTHON"). - OptionalQueryStructField( - "StrictOrNot", - functionStrictOrNot, - g.KeywordOptions(), - ). - OptionalQueryStructField( - "VolatileOrNot", - functionVolatileOrNot, - g.KeywordOptions(), - ). - OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). + PredefinedQueryStructField("ReturnResultsBehavior", "*ReturnResultsBehavior", g.KeywordOptions()). + TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). ListQueryStructField( "Imports", @@ -214,23 +148,16 @@ var FunctionsDef = g.NewInterface( functionPackages, g.ParameterOptions().Parentheses().SQL("PACKAGES"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()). - ListQueryStructField( - "Secrets", - functionSecret, - g.ParameterOptions().Parentheses().SQL("SECRETS"), - ). - QueryStructField( - "FunctionDefinition", - functionDefinition, - g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS"), - ). - WithValidation(g.ValidIdentifier, "name"), + ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()). + PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"). + WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"), ).CustomOperation( - "CreateFunctionForScala", - "https://docs.snowflake.com/en/sql-reference/sql/create-function", - g.NewQueryStruct("CreateFunctionForScala"). + "CreateForScala", + "https://docs.snowflake.com/en/sql-reference/sql/create-function#scala-handler", + g.NewQueryStruct("CreateForScala"). Create(). OrReplace(). OptionalSQL("TEMPORARY"). @@ -243,27 +170,11 @@ var FunctionsDef = g.NewInterface( functionArgument, g.ParameterOptions().Parentheses().NoEquals()). OptionalSQL("COPY GRANTS"). - QueryStructField( - "Returns", - functionReturns, - g.KeywordOptions().SQL("RETURNS"), - ). - OptionalQueryStructField( - "NullOrNot", - functionNullOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("ResultDataType", "DataType", g.ParameterOptions().NoEquals().SQL("RETURNS").Required()). + PredefinedQueryStructField("ReturnNullValues", "*ReturnNullValues", g.KeywordOptions()). SQL("LANGUAGE SCALA"). - OptionalQueryStructField( - "StrictOrNot", - functionStrictOrNot, - g.KeywordOptions(), - ). - OptionalQueryStructField( - "VolatileOrNot", - functionVolatileOrNot, - g.KeywordOptions(), - ). + PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()). + PredefinedQueryStructField("ReturnResultsBehavior", "*ReturnResultsBehavior", g.KeywordOptions()). OptionalTextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes()). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). ListQueryStructField( @@ -276,24 +187,20 @@ var FunctionsDef = g.NewInterface( functionPackages, g.ParameterOptions().Parentheses().SQL("PACKAGES"), ). - TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes()). + TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()). OptionalTextAssignment("TARGET_PATH", g.ParameterOptions().SingleQuotes()). - QueryStructField( - "FunctionDefinition", - functionDefinition, - g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS"), - ). - WithValidation(g.ValidIdentifier, "name"), + PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")). + WithValidation(g.ValidIdentifier, "name"). + WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"), ).CustomOperation( - "CreateFunctionForSQL", - "https://docs.snowflake.com/en/sql-reference/sql/create-function", - g.NewQueryStruct("CreateFunctionForSQL"). + "CreateForSQL", + "https://docs.snowflake.com/en/sql-reference/sql/create-function#sql-handler", + g.NewQueryStruct("CreateForSQL"). Create(). OrReplace(). OptionalSQL("TEMPORARY"). OptionalSQL("SECURE"). SQL("FUNCTION"). - IfNotExists(). Name(). ListQueryStructField( "Arguments", @@ -303,25 +210,13 @@ var FunctionsDef = g.NewInterface( QueryStructField( "Returns", functionReturns, - g.KeywordOptions().SQL("RETURNS"), - ). - OptionalQueryStructField( - "NullOrNot", - functionNullOrNot, - g.KeywordOptions(), - ). - OptionalQueryStructField( - "VolatileOrNot", - functionVolatileOrNot, - g.KeywordOptions(), + g.KeywordOptions().SQL("RETURNS").Required(), ). + PredefinedQueryStructField("ReturnNullValues", "*ReturnNullValues", g.KeywordOptions()). + PredefinedQueryStructField("ReturnResultsBehavior", "*ReturnResultsBehavior", g.KeywordOptions()). OptionalSQL("MEMOIZABLE"). OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). - QueryStructField( - "FunctionDefinition", - functionDefinition, - g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS"), - ). + PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()). WithValidation(g.ValidIdentifier, "name"), ).AlterOperation( "https://docs.snowflake.com/en/sql-reference/sql/alter-function", @@ -330,24 +225,21 @@ var FunctionsDef = g.NewInterface( SQL("FUNCTION"). IfExists(). Name(). - ListQueryStructField( - "ArgumentTypes", - functionArgumentType, - g.ParameterOptions().Parentheses().NoEquals()). - OptionalQueryStructField( - "Set", - functionSet, - g.KeywordOptions().SQL("SET"), - ). - OptionalQueryStructField( - "Unset", - functionUnset, - g.KeywordOptions().SQL("UNSET"), - ). + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). Identifier("RenameTo", g.KindOfTPointer[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). - SetTags().UnsetTags(). + OptionalTextAssignment("SET COMMENT", g.ParameterOptions().SingleQuotes()). + OptionalTextAssignment("SET LOG_LEVEL", g.ParameterOptions().SingleQuotes()). + OptionalTextAssignment("SET TRACE_LEVEL", g.ParameterOptions().SingleQuotes()). + OptionalSQL("SET SECURE"). + OptionalSQL("UNSET SECURE"). + OptionalSQL("UNSET LOG_LEVEL"). + OptionalSQL("UNSET TRACE_LEVEL"). + OptionalSQL("UNSET COMMENT"). + OptionalSetTags(). + OptionalUnsetTags(). WithValidation(g.ValidIdentifier, "name"). - WithValidation(g.ExactlyOneValueSet, "Set", "Unset", "SetTags", "UnsetTags", "RenameTo"), + WithValidation(g.ValidIdentifierIfSet, "RenameTo"). + WithValidation(g.ExactlyOneValueSet, "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "SetSecure", "UnsetLogLevel", "UnsetTraceLevel", "UnsetSecure", "UnsetComment", "SetTags", "UnsetTags"), ).DropOperation( "https://docs.snowflake.com/en/sql-reference/sql/drop-function", g.NewQueryStruct("DropFunction"). @@ -355,10 +247,7 @@ var FunctionsDef = g.NewInterface( SQL("FUNCTION"). IfExists(). Name(). - ListQueryStructField( - "ArgumentTypes", - functionArgumentType, - g.ParameterOptions().Parentheses().NoEquals()). + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). WithValidation(g.ValidIdentifier, "name"), ).ShowOperation( "https://docs.snowflake.com/en/sql-reference/sql/show-user-functions", @@ -366,20 +255,20 @@ var FunctionsDef = g.NewInterface( Field("created_on", "string"). Field("name", "string"). Field("schema_name", "string"). - Field("is_builtin", "bool"). - Field("is_aggregate", "bool"). - Field("is_ansi", "bool"). + 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("description", "string"). Field("catalog_name", "string"). - Field("is_table_function", "bool"). - Field("valid_for_clustering", "bool"). - Field("is_secure", "string"). + Field("is_table_function", "string"). + Field("valid_for_clustering", "string"). + Field("is_secure", "sql.NullString"). Field("is_external_function", "string"). Field("language", "string"). - Field("is_memoizable", "string"), + Field("is_memoizable", "sql.NullString"), g.PlainStruct("Function"). Field("CreatedOn", "string"). Field("Name", "string"). @@ -390,6 +279,8 @@ var FunctionsDef = g.NewInterface( Field("MinNumArguments", "int"). Field("MaxNumArguments", "int"). Field("Arguments", "string"). + Field("Description", "string"). + Field("CatalogName", "string"). Field("IsTableFunction", "bool"). Field("ValidForClustering", "bool"). Field("IsSecure", "bool"). @@ -401,7 +292,7 @@ var FunctionsDef = g.NewInterface( SQL("USER FUNCTIONS"). OptionalLike(). OptionalIn(), -).DescribeOperation( +).ShowByIdOperation().DescribeOperation( g.DescriptionMappingKindSlice, "https://docs.snowflake.com/en/sql-reference/sql/desc-function", g.DbStruct("functionDetailRow"). @@ -414,9 +305,6 @@ var FunctionsDef = g.NewInterface( Describe(). SQL("FUNCTION"). Name(). - ListQueryStructField( - "ArgumentTypes", - functionArgumentType, - g.ParameterOptions().Parentheses().NoEquals()). + PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()). WithValidation(g.ValidIdentifier, "name"), ) diff --git a/pkg/sdk/functions_dto_builders_gen.go b/pkg/sdk/functions_dto_builders_gen.go index e81c4d0430..60fade6825 100644 --- a/pkg/sdk/functions_dto_builders_gen.go +++ b/pkg/sdk/functions_dto_builders_gen.go @@ -4,116 +4,115 @@ package sdk import () -func NewCreateFunctionForJavaFunctionRequest( +func NewCreateForJavaFunctionRequest( name SchemaObjectIdentifier, - returns *FunctionReturnsRequest, - handler string, - functionDefinition string, -) *CreateFunctionForJavaFunctionRequest { - s := CreateFunctionForJavaFunctionRequest{} + Returns FunctionReturnsRequest, + Handler string, +) *CreateForJavaFunctionRequest { + s := CreateForJavaFunctionRequest{} s.name = name - s.Returns = returns - s.Handler = handler - s.FunctionDefinition = functionDefinition + s.Returns = Returns + s.Handler = Handler return &s } -func (s *CreateFunctionForJavaFunctionRequest) WithOrReplace(OrReplace *bool) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithOrReplace(OrReplace *bool) *CreateForJavaFunctionRequest { s.OrReplace = OrReplace return s } -func (s *CreateFunctionForJavaFunctionRequest) WithTemporary(Temporary *bool) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithTemporary(Temporary *bool) *CreateForJavaFunctionRequest { s.Temporary = Temporary return s } -func (s *CreateFunctionForJavaFunctionRequest) WithSecure(Secure *bool) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithSecure(Secure *bool) *CreateForJavaFunctionRequest { s.Secure = Secure return s } -func (s *CreateFunctionForJavaFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateForJavaFunctionRequest { s.IfNotExists = IfNotExists return s } -func (s *CreateFunctionForJavaFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateForJavaFunctionRequest { s.Arguments = Arguments return s } -func (s *CreateFunctionForJavaFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateForJavaFunctionRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateFunctionForJavaFunctionRequest) WithReturnNullValues(ReturnNullValues FunctionReturnNullValues) *CreateFunctionForJavaFunctionRequest { - s.ReturnNullValues = &ReturnNullValues +func (s *CreateForJavaFunctionRequest) WithReturnNullValues(ReturnNullValues *ReturnNullValues) *CreateForJavaFunctionRequest { + s.ReturnNullValues = ReturnNullValues return s } -func (s *CreateFunctionForJavaFunctionRequest) WithNullInputBehavior(NullInputBehavior FunctionNullInputBehavior) *CreateFunctionForJavaFunctionRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForJavaFunctionRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForJavaFunctionRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateFunctionForJavaFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior FunctionReturnResultsBehavior) *CreateFunctionForJavaFunctionRequest { - s.ReturnResultsBehavior = &ReturnResultsBehavior +func (s *CreateForJavaFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior *ReturnResultsBehavior) *CreateForJavaFunctionRequest { + s.ReturnResultsBehavior = ReturnResultsBehavior return s } -func (s *CreateFunctionForJavaFunctionRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateForJavaFunctionRequest { s.RuntimeVersion = RuntimeVersion return s } -func (s *CreateFunctionForJavaFunctionRequest) WithComment(Comment *string) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithComment(Comment *string) *CreateForJavaFunctionRequest { s.Comment = Comment return s } -func (s *CreateFunctionForJavaFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateForJavaFunctionRequest { s.Imports = Imports return s } -func (s *CreateFunctionForJavaFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateForJavaFunctionRequest { s.Packages = Packages return s } -func (s *CreateFunctionForJavaFunctionRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateForJavaFunctionRequest { s.ExternalAccessIntegrations = ExternalAccessIntegrations return s } -func (s *CreateFunctionForJavaFunctionRequest) WithSecrets(Secrets []FunctionSecretRequest) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithSecrets(Secrets []Secret) *CreateForJavaFunctionRequest { s.Secrets = Secrets return s } -func (s *CreateFunctionForJavaFunctionRequest) WithTargetPath(TargetPath *string) *CreateFunctionForJavaFunctionRequest { +func (s *CreateForJavaFunctionRequest) WithTargetPath(TargetPath *string) *CreateForJavaFunctionRequest { s.TargetPath = TargetPath return s } -func NewFunctionArgumentRequest() *FunctionArgumentRequest { - return &FunctionArgumentRequest{} -} - -func (s *FunctionArgumentRequest) WithArgName(ArgName string) *FunctionArgumentRequest { - s.ArgName = ArgName +func (s *CreateForJavaFunctionRequest) WithFunctionDefinition(FunctionDefinition *string) *CreateForJavaFunctionRequest { + s.FunctionDefinition = FunctionDefinition return s } -func (s *FunctionArgumentRequest) WithArgDataType(ArgDataType DataType) *FunctionArgumentRequest { +func NewFunctionArgumentRequest( + ArgName string, + ArgDataType DataType, +) *FunctionArgumentRequest { + s := FunctionArgumentRequest{} + s.ArgName = ArgName s.ArgDataType = ArgDataType - return s + return &s } -func (s *FunctionArgumentRequest) WithDefault(Default *string) *FunctionArgumentRequest { - s.Default = Default +func (s *FunctionArgumentRequest) WithDefaultValue(DefaultValue *string) *FunctionArgumentRequest { + s.DefaultValue = DefaultValue return s } @@ -121,8 +120,8 @@ func NewFunctionReturnsRequest() *FunctionReturnsRequest { return &FunctionReturnsRequest{} } -func (s *FunctionReturnsRequest) WithResultDataType(ResultDataType DataType) *FunctionReturnsRequest { - s.ResultDataType = &ResultDataType +func (s *FunctionReturnsRequest) WithResultDataType(ResultDataType *FunctionReturnsResultDataTypeRequest) *FunctionReturnsRequest { + s.ResultDataType = ResultDataType return s } @@ -131,6 +130,14 @@ func (s *FunctionReturnsRequest) WithTable(Table *FunctionReturnsTableRequest) * return s } +func NewFunctionReturnsResultDataTypeRequest( + ResultDataType DataType, +) *FunctionReturnsResultDataTypeRequest { + s := FunctionReturnsResultDataTypeRequest{} + s.ResultDataType = ResultDataType + return &s +} + func NewFunctionReturnsTableRequest() *FunctionReturnsTableRequest { return &FunctionReturnsTableRequest{} } @@ -140,18 +147,14 @@ func (s *FunctionReturnsTableRequest) WithColumns(Columns []FunctionColumnReques return s } -func NewFunctionColumnRequest() *FunctionColumnRequest { - return &FunctionColumnRequest{} -} - -func (s *FunctionColumnRequest) WithColumnName(ColumnName string) *FunctionColumnRequest { +func NewFunctionColumnRequest( + ColumnName string, + ColumnDataType DataType, +) *FunctionColumnRequest { + s := FunctionColumnRequest{} s.ColumnName = ColumnName - return s -} - -func (s *FunctionColumnRequest) WithColumnDataType(ColumnDataType DataType) *FunctionColumnRequest { s.ColumnDataType = ColumnDataType - return s + return &s } func NewFunctionImportsRequest() *FunctionImportsRequest { @@ -172,318 +175,303 @@ func (s *FunctionPackagesRequest) WithPackage(Package string) *FunctionPackagesR return s } -func NewFunctionSecretRequest() *FunctionSecretRequest { - return &FunctionSecretRequest{} -} - -func (s *FunctionSecretRequest) WithSecretVariableName(SecretVariableName string) *FunctionSecretRequest { - s.SecretVariableName = SecretVariableName - return s -} - -func (s *FunctionSecretRequest) WithSecretName(SecretName string) *FunctionSecretRequest { - s.SecretName = SecretName - return s -} - -func NewCreateFunctionForJavascriptFunctionRequest( +func NewCreateForJavascriptFunctionRequest( name SchemaObjectIdentifier, - returns *FunctionReturnsRequest, - functionDefinition string, -) *CreateFunctionForJavascriptFunctionRequest { - s := CreateFunctionForJavascriptFunctionRequest{} + Returns FunctionReturnsRequest, + FunctionDefinition *string, +) *CreateForJavascriptFunctionRequest { + s := CreateForJavascriptFunctionRequest{} s.name = name - s.FunctionDefinition = functionDefinition + s.Returns = Returns + s.FunctionDefinition = FunctionDefinition return &s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithOrReplace(OrReplace *bool) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithOrReplace(OrReplace *bool) *CreateForJavascriptFunctionRequest { s.OrReplace = OrReplace return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithTemporary(Temporary *bool) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithTemporary(Temporary *bool) *CreateForJavascriptFunctionRequest { s.Temporary = Temporary return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithSecure(Secure *bool) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithSecure(Secure *bool) *CreateForJavascriptFunctionRequest { s.Secure = Secure return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateFunctionForJavascriptFunctionRequest { - s.IfNotExists = IfNotExists - return s -} - -func (s *CreateFunctionForJavascriptFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateForJavascriptFunctionRequest { s.Arguments = Arguments return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateForJavascriptFunctionRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithReturnNullValues(ReturnNullValues FunctionReturnNullValues) *CreateFunctionForJavascriptFunctionRequest { - s.ReturnNullValues = &ReturnNullValues +func (s *CreateForJavascriptFunctionRequest) WithReturnNullValues(ReturnNullValues *ReturnNullValues) *CreateForJavascriptFunctionRequest { + s.ReturnNullValues = ReturnNullValues return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithNullInputBehavior(NullInputBehavior FunctionNullInputBehavior) *CreateFunctionForJavascriptFunctionRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForJavascriptFunctionRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForJavascriptFunctionRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior FunctionReturnResultsBehavior) *CreateFunctionForJavascriptFunctionRequest { - s.ReturnResultsBehavior = &ReturnResultsBehavior +func (s *CreateForJavascriptFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior *ReturnResultsBehavior) *CreateForJavascriptFunctionRequest { + s.ReturnResultsBehavior = ReturnResultsBehavior return s } -func (s *CreateFunctionForJavascriptFunctionRequest) WithComment(Comment *string) *CreateFunctionForJavascriptFunctionRequest { +func (s *CreateForJavascriptFunctionRequest) WithComment(Comment *string) *CreateForJavascriptFunctionRequest { s.Comment = Comment return s } -func NewCreateFunctionForPythonFunctionRequest( +func NewCreateForPythonFunctionRequest( name SchemaObjectIdentifier, - returns *FunctionReturnsRequest, - runtimeVersion string, - handler string, - functionDefinition string, -) *CreateFunctionForPythonFunctionRequest { - s := CreateFunctionForPythonFunctionRequest{} + Returns FunctionReturnsRequest, + RuntimeVersion string, + Handler string, +) *CreateForPythonFunctionRequest { + s := CreateForPythonFunctionRequest{} s.name = name - s.Returns = returns - s.RuntimeVersion = runtimeVersion - s.Handler = handler - s.FunctionDefinition = functionDefinition + s.Returns = Returns + s.RuntimeVersion = RuntimeVersion + s.Handler = Handler return &s } -func (s *CreateFunctionForPythonFunctionRequest) WithOrReplace(OrReplace *bool) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithOrReplace(OrReplace *bool) *CreateForPythonFunctionRequest { s.OrReplace = OrReplace return s } -func (s *CreateFunctionForPythonFunctionRequest) WithTemporary(Temporary *bool) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithTemporary(Temporary *bool) *CreateForPythonFunctionRequest { s.Temporary = Temporary return s } -func (s *CreateFunctionForPythonFunctionRequest) WithSecure(Secure *bool) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithSecure(Secure *bool) *CreateForPythonFunctionRequest { s.Secure = Secure return s } -func (s *CreateFunctionForPythonFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateForPythonFunctionRequest { s.IfNotExists = IfNotExists return s } -func (s *CreateFunctionForPythonFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateForPythonFunctionRequest { s.Arguments = Arguments return s } -func (s *CreateFunctionForPythonFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateForPythonFunctionRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateFunctionForPythonFunctionRequest) WithReturnNullValues(ReturnNullValues FunctionReturnNullValues) *CreateFunctionForPythonFunctionRequest { - s.ReturnNullValues = &ReturnNullValues +func (s *CreateForPythonFunctionRequest) WithReturnNullValues(ReturnNullValues *ReturnNullValues) *CreateForPythonFunctionRequest { + s.ReturnNullValues = ReturnNullValues return s } -func (s *CreateFunctionForPythonFunctionRequest) WithNullInputBehavior(NullInputBehavior FunctionNullInputBehavior) *CreateFunctionForPythonFunctionRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForPythonFunctionRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForPythonFunctionRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateFunctionForPythonFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior FunctionReturnResultsBehavior) *CreateFunctionForPythonFunctionRequest { - s.ReturnResultsBehavior = &ReturnResultsBehavior +func (s *CreateForPythonFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior *ReturnResultsBehavior) *CreateForPythonFunctionRequest { + s.ReturnResultsBehavior = ReturnResultsBehavior return s } -func (s *CreateFunctionForPythonFunctionRequest) WithComment(Comment *string) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithComment(Comment *string) *CreateForPythonFunctionRequest { s.Comment = Comment return s } -func (s *CreateFunctionForPythonFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateForPythonFunctionRequest { s.Imports = Imports return s } -func (s *CreateFunctionForPythonFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateForPythonFunctionRequest { s.Packages = Packages return s } -func (s *CreateFunctionForPythonFunctionRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithExternalAccessIntegrations(ExternalAccessIntegrations []AccountObjectIdentifier) *CreateForPythonFunctionRequest { s.ExternalAccessIntegrations = ExternalAccessIntegrations return s } -func (s *CreateFunctionForPythonFunctionRequest) WithSecrets(Secrets []FunctionSecretRequest) *CreateFunctionForPythonFunctionRequest { +func (s *CreateForPythonFunctionRequest) WithSecrets(Secrets []Secret) *CreateForPythonFunctionRequest { s.Secrets = Secrets return s } -func NewCreateFunctionForScalaFunctionRequest( +func (s *CreateForPythonFunctionRequest) WithFunctionDefinition(FunctionDefinition *string) *CreateForPythonFunctionRequest { + s.FunctionDefinition = FunctionDefinition + return s +} + +func NewCreateForScalaFunctionRequest( name SchemaObjectIdentifier, - returns *FunctionReturnsRequest, - handler string, - functionDefinition string, -) *CreateFunctionForScalaFunctionRequest { - s := CreateFunctionForScalaFunctionRequest{} + ResultDataType DataType, + Handler string, +) *CreateForScalaFunctionRequest { + s := CreateForScalaFunctionRequest{} s.name = name - s.Returns = returns - s.Handler = handler - s.FunctionDefinition = functionDefinition + s.ResultDataType = ResultDataType + s.Handler = Handler return &s } -func (s *CreateFunctionForScalaFunctionRequest) WithOrReplace(OrReplace *bool) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithOrReplace(OrReplace *bool) *CreateForScalaFunctionRequest { s.OrReplace = OrReplace return s } -func (s *CreateFunctionForScalaFunctionRequest) WithTemporary(Temporary *bool) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithTemporary(Temporary *bool) *CreateForScalaFunctionRequest { s.Temporary = Temporary return s } -func (s *CreateFunctionForScalaFunctionRequest) WithSecure(Secure *bool) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithSecure(Secure *bool) *CreateForScalaFunctionRequest { s.Secure = Secure return s } -func (s *CreateFunctionForScalaFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateForScalaFunctionRequest { s.IfNotExists = IfNotExists return s } -func (s *CreateFunctionForScalaFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateForScalaFunctionRequest { s.Arguments = Arguments return s } -func (s *CreateFunctionForScalaFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateForScalaFunctionRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateFunctionForScalaFunctionRequest) WithReturnNullValues(ReturnNullValues FunctionReturnNullValues) *CreateFunctionForScalaFunctionRequest { - s.ReturnNullValues = &ReturnNullValues +func (s *CreateForScalaFunctionRequest) WithReturnNullValues(ReturnNullValues *ReturnNullValues) *CreateForScalaFunctionRequest { + s.ReturnNullValues = ReturnNullValues return s } -func (s *CreateFunctionForScalaFunctionRequest) WithNullInputBehavior(NullInputBehavior FunctionNullInputBehavior) *CreateFunctionForScalaFunctionRequest { - s.NullInputBehavior = &NullInputBehavior +func (s *CreateForScalaFunctionRequest) WithNullInputBehavior(NullInputBehavior *NullInputBehavior) *CreateForScalaFunctionRequest { + s.NullInputBehavior = NullInputBehavior return s } -func (s *CreateFunctionForScalaFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior FunctionReturnResultsBehavior) *CreateFunctionForScalaFunctionRequest { - s.ReturnResultsBehavior = &ReturnResultsBehavior +func (s *CreateForScalaFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior *ReturnResultsBehavior) *CreateForScalaFunctionRequest { + s.ReturnResultsBehavior = ReturnResultsBehavior return s } -func (s *CreateFunctionForScalaFunctionRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithRuntimeVersion(RuntimeVersion *string) *CreateForScalaFunctionRequest { s.RuntimeVersion = RuntimeVersion return s } -func (s *CreateFunctionForScalaFunctionRequest) WithComment(Comment *string) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithComment(Comment *string) *CreateForScalaFunctionRequest { s.Comment = Comment return s } -func (s *CreateFunctionForScalaFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithImports(Imports []FunctionImportsRequest) *CreateForScalaFunctionRequest { s.Imports = Imports return s } -func (s *CreateFunctionForScalaFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithPackages(Packages []FunctionPackagesRequest) *CreateForScalaFunctionRequest { s.Packages = Packages return s } -func (s *CreateFunctionForScalaFunctionRequest) WithTargetPath(TargetPath *string) *CreateFunctionForScalaFunctionRequest { +func (s *CreateForScalaFunctionRequest) WithTargetPath(TargetPath *string) *CreateForScalaFunctionRequest { s.TargetPath = TargetPath return s } -func NewCreateFunctionForSQLFunctionRequest( +func (s *CreateForScalaFunctionRequest) WithFunctionDefinition(FunctionDefinition *string) *CreateForScalaFunctionRequest { + s.FunctionDefinition = FunctionDefinition + return s +} + +func NewCreateForSQLFunctionRequest( name SchemaObjectIdentifier, - returns *FunctionReturnsRequest, - functionDefinition string, -) *CreateFunctionForSQLFunctionRequest { - s := CreateFunctionForSQLFunctionRequest{} + Returns FunctionReturnsRequest, + FunctionDefinition *string, +) *CreateForSQLFunctionRequest { + s := CreateForSQLFunctionRequest{} s.name = name - s.Returns = returns - s.FunctionDefinition = functionDefinition + s.Returns = Returns + s.FunctionDefinition = FunctionDefinition return &s } -func (s *CreateFunctionForSQLFunctionRequest) WithOrReplace(OrReplace *bool) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithOrReplace(OrReplace *bool) *CreateForSQLFunctionRequest { s.OrReplace = OrReplace return s } -func (s *CreateFunctionForSQLFunctionRequest) WithTemporary(Temporary *bool) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithTemporary(Temporary *bool) *CreateForSQLFunctionRequest { s.Temporary = Temporary return s } -func (s *CreateFunctionForSQLFunctionRequest) WithSecure(Secure *bool) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithSecure(Secure *bool) *CreateForSQLFunctionRequest { s.Secure = Secure return s } -func (s *CreateFunctionForSQLFunctionRequest) WithIfNotExists(IfNotExists *bool) *CreateFunctionForSQLFunctionRequest { - s.IfNotExists = IfNotExists - return s -} - -func (s *CreateFunctionForSQLFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithArguments(Arguments []FunctionArgumentRequest) *CreateForSQLFunctionRequest { s.Arguments = Arguments return s } -func (s *CreateFunctionForSQLFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithCopyGrants(CopyGrants *bool) *CreateForSQLFunctionRequest { s.CopyGrants = CopyGrants return s } -func (s *CreateFunctionForSQLFunctionRequest) WithReturnNullValues(ReturnNullValues FunctionReturnNullValues) *CreateFunctionForSQLFunctionRequest { - s.ReturnNullValues = &ReturnNullValues +func (s *CreateForSQLFunctionRequest) WithReturnNullValues(ReturnNullValues *ReturnNullValues) *CreateForSQLFunctionRequest { + s.ReturnNullValues = ReturnNullValues return s } -func (s *CreateFunctionForSQLFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior FunctionReturnResultsBehavior) *CreateFunctionForSQLFunctionRequest { - s.ReturnResultsBehavior = &ReturnResultsBehavior +func (s *CreateForSQLFunctionRequest) WithReturnResultsBehavior(ReturnResultsBehavior *ReturnResultsBehavior) *CreateForSQLFunctionRequest { + s.ReturnResultsBehavior = ReturnResultsBehavior return s } -func (s *CreateFunctionForSQLFunctionRequest) WithMemoizable(Memoizable *bool) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithMemoizable(Memoizable *bool) *CreateForSQLFunctionRequest { s.Memoizable = Memoizable return s } -func (s *CreateFunctionForSQLFunctionRequest) WithComment(Comment *string) *CreateFunctionForSQLFunctionRequest { +func (s *CreateForSQLFunctionRequest) WithComment(Comment *string) *CreateForSQLFunctionRequest { s.Comment = Comment return s } func NewAlterFunctionRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *AlterFunctionRequest { s := AlterFunctionRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } @@ -492,98 +480,68 @@ func (s *AlterFunctionRequest) WithIfExists(IfExists *bool) *AlterFunctionReques return s } -func (s *AlterFunctionRequest) WithArgumentTypes(ArgumentTypes []FunctionArgumentTypeRequest) *AlterFunctionRequest { - s.ArgumentTypes = ArgumentTypes - return s -} - -func (s *AlterFunctionRequest) WithSet(Set *FunctionSetRequest) *AlterFunctionRequest { - s.Set = Set - return s -} - -func (s *AlterFunctionRequest) WithUnset(Unset *FunctionUnsetRequest) *AlterFunctionRequest { - s.Unset = Unset - return s -} - func (s *AlterFunctionRequest) WithRenameTo(RenameTo *SchemaObjectIdentifier) *AlterFunctionRequest { s.RenameTo = RenameTo return s } -func (s *AlterFunctionRequest) WithSetTags(SetTags []TagAssociation) *AlterFunctionRequest { - s.SetTags = SetTags +func (s *AlterFunctionRequest) WithSetComment(SetComment *string) *AlterFunctionRequest { + s.SetComment = SetComment return s } -func (s *AlterFunctionRequest) WithUnsetTags(UnsetTags []ObjectIdentifier) *AlterFunctionRequest { - s.UnsetTags = UnsetTags - return s -} - -func NewFunctionArgumentTypeRequest() *FunctionArgumentTypeRequest { - return &FunctionArgumentTypeRequest{} -} - -func (s *FunctionArgumentTypeRequest) WithArgDataType(ArgDataType DataType) *FunctionArgumentTypeRequest { - s.ArgDataType = ArgDataType +func (s *AlterFunctionRequest) WithSetLogLevel(SetLogLevel *string) *AlterFunctionRequest { + s.SetLogLevel = SetLogLevel return s } -func NewFunctionSetRequest() *FunctionSetRequest { - return &FunctionSetRequest{} -} - -func (s *FunctionSetRequest) WithLogLevel(LogLevel *string) *FunctionSetRequest { - s.LogLevel = LogLevel +func (s *AlterFunctionRequest) WithSetTraceLevel(SetTraceLevel *string) *AlterFunctionRequest { + s.SetTraceLevel = SetTraceLevel return s } -func (s *FunctionSetRequest) WithTraceLevel(TraceLevel *string) *FunctionSetRequest { - s.TraceLevel = TraceLevel +func (s *AlterFunctionRequest) WithSetSecure(SetSecure *bool) *AlterFunctionRequest { + s.SetSecure = SetSecure return s } -func (s *FunctionSetRequest) WithComment(Comment *string) *FunctionSetRequest { - s.Comment = Comment +func (s *AlterFunctionRequest) WithUnsetSecure(UnsetSecure *bool) *AlterFunctionRequest { + s.UnsetSecure = UnsetSecure return s } -func (s *FunctionSetRequest) WithSecure(Secure *bool) *FunctionSetRequest { - s.Secure = Secure +func (s *AlterFunctionRequest) WithUnsetLogLevel(UnsetLogLevel *bool) *AlterFunctionRequest { + s.UnsetLogLevel = UnsetLogLevel return s } -func NewFunctionUnsetRequest() *FunctionUnsetRequest { - return &FunctionUnsetRequest{} -} - -func (s *FunctionUnsetRequest) WithSecure(Secure *bool) *FunctionUnsetRequest { - s.Secure = Secure +func (s *AlterFunctionRequest) WithUnsetTraceLevel(UnsetTraceLevel *bool) *AlterFunctionRequest { + s.UnsetTraceLevel = UnsetTraceLevel return s } -func (s *FunctionUnsetRequest) WithComment(Comment *bool) *FunctionUnsetRequest { - s.Comment = Comment +func (s *AlterFunctionRequest) WithUnsetComment(UnsetComment *bool) *AlterFunctionRequest { + s.UnsetComment = UnsetComment return s } -func (s *FunctionUnsetRequest) WithLogLevel(LogLevel *bool) *FunctionUnsetRequest { - s.LogLevel = LogLevel +func (s *AlterFunctionRequest) WithSetTags(SetTags []TagAssociation) *AlterFunctionRequest { + s.SetTags = SetTags return s } -func (s *FunctionUnsetRequest) WithTraceLevel(TraceLevel *bool) *FunctionUnsetRequest { - s.TraceLevel = TraceLevel +func (s *AlterFunctionRequest) WithUnsetTags(UnsetTags []ObjectIdentifier) *AlterFunctionRequest { + s.UnsetTags = UnsetTags return s } func NewDropFunctionRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *DropFunctionRequest { s := DropFunctionRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } @@ -592,17 +550,12 @@ func (s *DropFunctionRequest) WithIfExists(IfExists *bool) *DropFunctionRequest return s } -func (s *DropFunctionRequest) WithArgumentTypes(ArgumentTypes []FunctionArgumentTypeRequest) *DropFunctionRequest { - s.ArgumentTypes = ArgumentTypes - return s -} - func NewShowFunctionRequest() *ShowFunctionRequest { return &ShowFunctionRequest{} } -func (s *ShowFunctionRequest) WithLike(pattern string) *ShowFunctionRequest { - s.Like = &Like{Pattern: String(pattern)} +func (s *ShowFunctionRequest) WithLike(Like *Like) *ShowFunctionRequest { + s.Like = Like return s } @@ -613,13 +566,10 @@ func (s *ShowFunctionRequest) WithIn(In *In) *ShowFunctionRequest { func NewDescribeFunctionRequest( name SchemaObjectIdentifier, + ArgumentDataTypes []DataType, ) *DescribeFunctionRequest { s := DescribeFunctionRequest{} s.name = name + s.ArgumentDataTypes = ArgumentDataTypes return &s } - -func (s *DescribeFunctionRequest) WithArgumentTypes(ArgumentTypes []FunctionArgumentTypeRequest) *DescribeFunctionRequest { - s.ArgumentTypes = ArgumentTypes - return s -} diff --git a/pkg/sdk/functions_dto_gen.go b/pkg/sdk/functions_dto_gen.go index 3c908a9c67..74a0713df5 100644 --- a/pkg/sdk/functions_dto_gen.go +++ b/pkg/sdk/functions_dto_gen.go @@ -3,18 +3,18 @@ package sdk //go:generate go run ./dto-builder-generator/main.go var ( - _ optionsProvider[CreateFunctionForJavaFunctionOptions] = new(CreateFunctionForJavaFunctionRequest) - _ optionsProvider[CreateFunctionForJavascriptFunctionOptions] = new(CreateFunctionForJavascriptFunctionRequest) - _ optionsProvider[CreateFunctionForPythonFunctionOptions] = new(CreateFunctionForPythonFunctionRequest) - _ optionsProvider[CreateFunctionForScalaFunctionOptions] = new(CreateFunctionForScalaFunctionRequest) - _ optionsProvider[CreateFunctionForSQLFunctionOptions] = new(CreateFunctionForSQLFunctionRequest) - _ optionsProvider[AlterFunctionOptions] = new(AlterFunctionRequest) - _ optionsProvider[DropFunctionOptions] = new(DropFunctionRequest) - _ optionsProvider[ShowFunctionOptions] = new(ShowFunctionRequest) - _ optionsProvider[DescribeFunctionOptions] = new(DescribeFunctionRequest) + _ optionsProvider[CreateForJavaFunctionOptions] = new(CreateForJavaFunctionRequest) + _ optionsProvider[CreateForJavascriptFunctionOptions] = new(CreateForJavascriptFunctionRequest) + _ optionsProvider[CreateForPythonFunctionOptions] = new(CreateForPythonFunctionRequest) + _ optionsProvider[CreateForScalaFunctionOptions] = new(CreateForScalaFunctionRequest) + _ optionsProvider[CreateForSQLFunctionOptions] = new(CreateForSQLFunctionRequest) + _ optionsProvider[AlterFunctionOptions] = new(AlterFunctionRequest) + _ optionsProvider[DropFunctionOptions] = new(DropFunctionRequest) + _ optionsProvider[ShowFunctionOptions] = new(ShowFunctionRequest) + _ optionsProvider[DescribeFunctionOptions] = new(DescribeFunctionRequest) ) -type CreateFunctionForJavaFunctionRequest struct { +type CreateForJavaFunctionRequest struct { OrReplace *bool Temporary *bool Secure *bool @@ -22,39 +22,43 @@ type CreateFunctionForJavaFunctionRequest struct { name SchemaObjectIdentifier // required Arguments []FunctionArgumentRequest CopyGrants *bool - Returns *FunctionReturnsRequest - ReturnNullValues *FunctionReturnNullValues - NullInputBehavior *FunctionNullInputBehavior - ReturnResultsBehavior *FunctionReturnResultsBehavior + Returns FunctionReturnsRequest // required + ReturnNullValues *ReturnNullValues + NullInputBehavior *NullInputBehavior + ReturnResultsBehavior *ReturnResultsBehavior RuntimeVersion *string Comment *string Imports []FunctionImportsRequest Packages []FunctionPackagesRequest - Handler string + Handler string // required ExternalAccessIntegrations []AccountObjectIdentifier - Secrets []FunctionSecretRequest + Secrets []Secret TargetPath *string - FunctionDefinition string + FunctionDefinition *string } type FunctionArgumentRequest struct { - ArgName string - ArgDataType DataType - Default *string + ArgName string // required + ArgDataType DataType // required + DefaultValue *string } type FunctionReturnsRequest struct { - ResultDataType *DataType + ResultDataType *FunctionReturnsResultDataTypeRequest Table *FunctionReturnsTableRequest } +type FunctionReturnsResultDataTypeRequest struct { + ResultDataType DataType // required +} + type FunctionReturnsTableRequest struct { Columns []FunctionColumnRequest } type FunctionColumnRequest struct { - ColumnName string - ColumnDataType DataType + ColumnName string // required + ColumnDataType DataType // required } type FunctionImportsRequest struct { @@ -65,28 +69,22 @@ type FunctionPackagesRequest struct { Package string } -type FunctionSecretRequest struct { - SecretVariableName string - SecretName string -} - -type CreateFunctionForJavascriptFunctionRequest struct { +type CreateForJavascriptFunctionRequest struct { OrReplace *bool Temporary *bool Secure *bool - IfNotExists *bool name SchemaObjectIdentifier // required Arguments []FunctionArgumentRequest CopyGrants *bool - Returns *FunctionReturnsRequest - ReturnNullValues *FunctionReturnNullValues - NullInputBehavior *FunctionNullInputBehavior - ReturnResultsBehavior *FunctionReturnResultsBehavior + Returns FunctionReturnsRequest // required + ReturnNullValues *ReturnNullValues + NullInputBehavior *NullInputBehavior + ReturnResultsBehavior *ReturnResultsBehavior Comment *string - FunctionDefinition string + FunctionDefinition *string // required } -type CreateFunctionForPythonFunctionRequest struct { +type CreateForPythonFunctionRequest struct { OrReplace *bool Temporary *bool Secure *bool @@ -94,21 +92,21 @@ type CreateFunctionForPythonFunctionRequest struct { name SchemaObjectIdentifier // required Arguments []FunctionArgumentRequest CopyGrants *bool - Returns *FunctionReturnsRequest - ReturnNullValues *FunctionReturnNullValues - NullInputBehavior *FunctionNullInputBehavior - ReturnResultsBehavior *FunctionReturnResultsBehavior - RuntimeVersion string + Returns FunctionReturnsRequest // required + ReturnNullValues *ReturnNullValues + NullInputBehavior *NullInputBehavior + ReturnResultsBehavior *ReturnResultsBehavior + RuntimeVersion string // required Comment *string Imports []FunctionImportsRequest Packages []FunctionPackagesRequest - Handler string + Handler string // required ExternalAccessIntegrations []AccountObjectIdentifier - Secrets []FunctionSecretRequest - FunctionDefinition string + Secrets []Secret + FunctionDefinition *string } -type CreateFunctionForScalaFunctionRequest struct { +type CreateForScalaFunctionRequest struct { OrReplace *bool Temporary *bool Secure *bool @@ -116,68 +114,55 @@ type CreateFunctionForScalaFunctionRequest struct { name SchemaObjectIdentifier // required Arguments []FunctionArgumentRequest CopyGrants *bool - Returns *FunctionReturnsRequest - ReturnNullValues *FunctionReturnNullValues - NullInputBehavior *FunctionNullInputBehavior - ReturnResultsBehavior *FunctionReturnResultsBehavior + ResultDataType DataType // required + ReturnNullValues *ReturnNullValues + NullInputBehavior *NullInputBehavior + ReturnResultsBehavior *ReturnResultsBehavior RuntimeVersion *string Comment *string Imports []FunctionImportsRequest Packages []FunctionPackagesRequest - Handler string + Handler string // required TargetPath *string - FunctionDefinition string + FunctionDefinition *string } -type CreateFunctionForSQLFunctionRequest struct { +type CreateForSQLFunctionRequest struct { OrReplace *bool Temporary *bool Secure *bool - IfNotExists *bool name SchemaObjectIdentifier // required Arguments []FunctionArgumentRequest CopyGrants *bool - Returns *FunctionReturnsRequest - ReturnNullValues *FunctionReturnNullValues - ReturnResultsBehavior *FunctionReturnResultsBehavior + Returns FunctionReturnsRequest // required + ReturnNullValues *ReturnNullValues + ReturnResultsBehavior *ReturnResultsBehavior Memoizable *bool Comment *string - FunctionDefinition string + FunctionDefinition *string // required } type AlterFunctionRequest struct { - IfExists *bool - name SchemaObjectIdentifier // required - ArgumentTypes []FunctionArgumentTypeRequest - Set *FunctionSetRequest - Unset *FunctionUnsetRequest - RenameTo *SchemaObjectIdentifier - SetTags []TagAssociation - UnsetTags []ObjectIdentifier -} - -type FunctionArgumentTypeRequest struct { - ArgDataType DataType -} - -type FunctionSetRequest struct { - LogLevel *string - TraceLevel *string - Comment *string - Secure *bool -} - -type FunctionUnsetRequest struct { - Secure *bool - Comment *bool - LogLevel *bool - TraceLevel *bool + IfExists *bool + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required + RenameTo *SchemaObjectIdentifier + SetComment *string + SetLogLevel *string + SetTraceLevel *string + SetSecure *bool + UnsetSecure *bool + UnsetLogLevel *bool + UnsetTraceLevel *bool + UnsetComment *bool + SetTags []TagAssociation + UnsetTags []ObjectIdentifier } type DropFunctionRequest struct { - IfExists *bool - name SchemaObjectIdentifier // required - ArgumentTypes []FunctionArgumentTypeRequest + IfExists *bool + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required } type ShowFunctionRequest struct { @@ -186,6 +171,6 @@ type ShowFunctionRequest struct { } type DescribeFunctionRequest struct { - name SchemaObjectIdentifier // required - ArgumentTypes []FunctionArgumentTypeRequest + name SchemaObjectIdentifier // required + ArgumentDataTypes []DataType // required } diff --git a/pkg/sdk/functions_gen.go b/pkg/sdk/functions_gen.go index 81765ade0d..3e57959dee 100644 --- a/pkg/sdk/functions_gen.go +++ b/pkg/sdk/functions_gen.go @@ -1,13 +1,16 @@ package sdk -import "context" +import ( + "context" + "database/sql" +) type Functions interface { - CreateFunctionForJava(ctx context.Context, request *CreateFunctionForJavaFunctionRequest) error - CreateFunctionForJavascript(ctx context.Context, request *CreateFunctionForJavascriptFunctionRequest) error - CreateFunctionForPython(ctx context.Context, request *CreateFunctionForPythonFunctionRequest) error - CreateFunctionForScala(ctx context.Context, request *CreateFunctionForScalaFunctionRequest) error - CreateFunctionForSQL(ctx context.Context, request *CreateFunctionForSQLFunctionRequest) error + CreateForJava(ctx context.Context, request *CreateForJavaFunctionRequest) error + CreateForJavascript(ctx context.Context, request *CreateForJavascriptFunctionRequest) error + CreateForPython(ctx context.Context, request *CreateForPythonFunctionRequest) error + CreateForScala(ctx context.Context, request *CreateForScalaFunctionRequest) error + CreateForSQL(ctx context.Context, request *CreateForSQLFunctionRequest) error Alter(ctx context.Context, request *AlterFunctionRequest) error Drop(ctx context.Context, request *DropFunctionRequest) error Show(ctx context.Context, request *ShowFunctionRequest) ([]Function, error) @@ -15,64 +18,46 @@ type Functions interface { Describe(ctx context.Context, request *DescribeFunctionRequest) ([]FunctionDetail, error) } -type FunctionNullInputBehavior string - -var ( - FunctionNullInputBehaviorCalledOnNullInput FunctionNullInputBehavior = "CALLED ON NULL INPUT" - FunctionNullInputBehaviorReturnNullInput FunctionNullInputBehavior = "RETURN NULL ON NULL INPUT" - FunctionNullInputBehaviorStrict FunctionNullInputBehavior = "STRICT" -) - -type FunctionReturnResultsBehavior string - -var ( - FunctionReturnResultsBehaviorVolatile FunctionReturnResultsBehavior = "VOLATILE" - FunctionReturnResultsBehaviorImmutable FunctionReturnResultsBehavior = "IMMUTABLE" -) - -type FunctionReturnNullValues string - -var ( - FunctionReturnNullValuesNull FunctionReturnNullValues = "NULL" - FunctionReturnNullValuesNotNull FunctionReturnNullValues = "NOT NULL" -) - -// CreateFunctionForJavaFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function. -type CreateFunctionForJavaFunctionOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - function bool `ddl:"static" sql:"FUNCTION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *FunctionReturns `ddl:"keyword" sql:"RETURNS"` - ReturnNullValues *FunctionReturnNullValues `ddl:"keyword"` - languageJava bool `ddl:"static" sql:"LANGUAGE JAVA"` - NullInputBehavior *FunctionNullInputBehavior `ddl:"keyword"` - ReturnResultsBehavior *FunctionReturnResultsBehavior `ddl:"keyword"` - RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` - Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` - Secrets []FunctionSecret `ddl:"parameter,parentheses" sql:"SECRETS"` - TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` - FunctionDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +// CreateForJavaFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function#java-handler. +type CreateForJavaFunctionOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + function bool `ddl:"static" sql:"FUNCTION"` + IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns FunctionReturns `ddl:"keyword" sql:"RETURNS"` + ReturnNullValues *ReturnNullValues `ddl:"keyword"` + languageJava bool `ddl:"static" sql:"LANGUAGE JAVA"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + ReturnResultsBehavior *ReturnResultsBehavior `ddl:"keyword"` + RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` + Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` + 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"` + FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } type FunctionArgument struct { - ArgName string `ddl:"keyword,no_quotes"` - ArgDataType DataType `ddl:"keyword,no_quotes"` - Default *string `ddl:"parameter,no_quotes" sql:"DEFAULT"` + ArgName string `ddl:"keyword,no_quotes"` + ArgDataType DataType `ddl:"keyword,no_quotes"` + DefaultValue *string `ddl:"parameter,no_equals" sql:"DEFAULT"` } type FunctionReturns struct { - ResultDataType *DataType `ddl:"keyword"` - Table *FunctionReturnsTable `ddl:"keyword" sql:"TABLE"` + ResultDataType *FunctionReturnsResultDataType `ddl:"keyword"` + Table *FunctionReturnsTable `ddl:"keyword" sql:"TABLE"` +} + +type FunctionReturnsResultDataType struct { + ResultDataType DataType `ddl:"keyword,no_quotes"` } type FunctionReturnsTable struct { @@ -92,140 +77,121 @@ type FunctionPackages struct { Package string `ddl:"keyword,single_quotes"` } -type FunctionSecret struct { - SecretVariableName string `ddl:"keyword,single_quotes"` - SecretName string `ddl:"parameter,no_quotes"` +// CreateForJavascriptFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function#javascript-handler. +type CreateForJavascriptFunctionOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + function bool `ddl:"static" sql:"FUNCTION"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns FunctionReturns `ddl:"keyword" sql:"RETURNS"` + ReturnNullValues *ReturnNullValues `ddl:"keyword"` + languageJavascript bool `ddl:"static" sql:"LANGUAGE JAVASCRIPT"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + ReturnResultsBehavior *ReturnResultsBehavior `ddl:"keyword"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } -// CreateFunctionForJavascriptFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function. -type CreateFunctionForJavascriptFunctionOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - function bool `ddl:"static" sql:"FUNCTION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *FunctionReturns `ddl:"keyword" sql:"RETURNS"` - ReturnNullValues *FunctionReturnNullValues `ddl:"keyword"` - languageJavascript bool `ddl:"static" sql:"LANGUAGE JAVASCRIPT"` - NullInputBehavior *FunctionNullInputBehavior `ddl:"keyword"` - ReturnResultsBehavior *FunctionReturnResultsBehavior `ddl:"keyword"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - FunctionDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +// CreateForPythonFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function#python-handler. +type CreateForPythonFunctionOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + function bool `ddl:"static" sql:"FUNCTION"` + IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns FunctionReturns `ddl:"keyword" sql:"RETURNS"` + ReturnNullValues *ReturnNullValues `ddl:"keyword"` + languagePython bool `ddl:"static" sql:"LANGUAGE PYTHON"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + ReturnResultsBehavior *ReturnResultsBehavior `ddl:"keyword"` + RuntimeVersion string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` + Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` + Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` + ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` + Secrets []Secret `ddl:"parameter,parentheses" sql:"SECRETS"` + FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } -// CreateFunctionForPythonFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function. -type CreateFunctionForPythonFunctionOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - function bool `ddl:"static" sql:"FUNCTION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *FunctionReturns `ddl:"keyword" sql:"RETURNS"` - ReturnNullValues *FunctionReturnNullValues `ddl:"keyword"` - languagePython bool `ddl:"static" sql:"LANGUAGE PYTHON"` - NullInputBehavior *FunctionNullInputBehavior `ddl:"keyword"` - ReturnResultsBehavior *FunctionReturnResultsBehavior `ddl:"keyword"` - RuntimeVersion string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` - Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"` - Secrets []FunctionSecret `ddl:"parameter,parentheses" sql:"SECRETS"` - FunctionDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +// CreateForScalaFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function#scala-handler. +type CreateForScalaFunctionOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + function bool `ddl:"static" sql:"FUNCTION"` + IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + ResultDataType DataType `ddl:"parameter,no_equals" sql:"RETURNS"` + ReturnNullValues *ReturnNullValues `ddl:"keyword"` + languageScala bool `ddl:"static" sql:"LANGUAGE SCALA"` + NullInputBehavior *NullInputBehavior `ddl:"keyword"` + ReturnResultsBehavior *ReturnResultsBehavior `ddl:"keyword"` + RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` + Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` + Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` + TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` + FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } -// CreateFunctionForScalaFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function. -type CreateFunctionForScalaFunctionOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - function bool `ddl:"static" sql:"FUNCTION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *FunctionReturns `ddl:"keyword" sql:"RETURNS"` - ReturnNullValues *FunctionReturnNullValues `ddl:"keyword"` - languageScala bool `ddl:"static" sql:"LANGUAGE SCALA"` - NullInputBehavior *FunctionNullInputBehavior `ddl:"keyword"` - ReturnResultsBehavior *FunctionReturnResultsBehavior `ddl:"keyword"` - RuntimeVersion *string `ddl:"parameter,single_quotes" sql:"RUNTIME_VERSION"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - Imports []FunctionImports `ddl:"parameter,parentheses" sql:"IMPORTS"` - Packages []FunctionPackages `ddl:"parameter,parentheses" sql:"PACKAGES"` - Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"` - TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"` - FunctionDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` -} - -// CreateFunctionForSQLFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function. -type CreateFunctionForSQLFunctionOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` - Secure *bool `ddl:"keyword" sql:"SECURE"` - function bool `ddl:"static" sql:"FUNCTION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` - CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` - Returns *FunctionReturns `ddl:"keyword" sql:"RETURNS"` - ReturnNullValues *FunctionReturnNullValues `ddl:"keyword"` - ReturnResultsBehavior *FunctionReturnResultsBehavior `ddl:"keyword"` - Memoizable *bool `ddl:"keyword" sql:"MEMOIZABLE"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` - FunctionDefinition string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` +// CreateForSQLFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-function#sql-handler. +type CreateForSQLFunctionOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + Temporary *bool `ddl:"keyword" sql:"TEMPORARY"` + Secure *bool `ddl:"keyword" sql:"SECURE"` + function bool `ddl:"static" sql:"FUNCTION"` + name SchemaObjectIdentifier `ddl:"identifier"` + Arguments []FunctionArgument `ddl:"parameter,parentheses,no_equals"` + CopyGrants *bool `ddl:"keyword" sql:"COPY GRANTS"` + Returns FunctionReturns `ddl:"keyword" sql:"RETURNS"` + ReturnNullValues *ReturnNullValues `ddl:"keyword"` + ReturnResultsBehavior *ReturnResultsBehavior `ddl:"keyword"` + Memoizable *bool `ddl:"keyword" sql:"MEMOIZABLE"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"` } // AlterFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-function. type AlterFunctionOptions struct { - alter bool `ddl:"static" sql:"ALTER"` - function bool `ddl:"static" sql:"FUNCTION"` - IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []FunctionArgumentType `ddl:"parameter,parentheses,no_equals"` - Set *FunctionSet `ddl:"keyword" sql:"SET"` - Unset *FunctionUnset `ddl:"keyword" sql:"UNSET"` - RenameTo *SchemaObjectIdentifier `ddl:"identifier" sql:"RENAME TO"` - SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"` - UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"` -} - -type FunctionArgumentType struct { - ArgDataType DataType `ddl:"keyword,no_quotes"` -} - -type FunctionSet 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"` - Secure *bool `ddl:"keyword" sql:"SECURE"` -} - -type FunctionUnset struct { - Secure *bool `ddl:"keyword" sql:"SECURE"` - Comment *bool `ddl:"keyword" sql:"COMMENT"` - LogLevel *bool `ddl:"keyword" sql:"LOG_LEVEL"` - TraceLevel *bool `ddl:"keyword" sql:"TRACE_LEVEL"` + alter bool `ddl:"static" sql:"ALTER"` + function bool `ddl:"static" sql:"FUNCTION"` + 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"` + SetSecure *bool `ddl:"keyword" sql:"SET SECURE"` + UnsetSecure *bool `ddl:"keyword" sql:"UNSET SECURE"` + UnsetLogLevel *bool `ddl:"keyword" sql:"UNSET LOG_LEVEL"` + UnsetTraceLevel *bool `ddl:"keyword" sql:"UNSET TRACE_LEVEL"` + UnsetComment *bool `ddl:"keyword" sql:"UNSET COMMENT"` + SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"` + UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"` } // DropFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-function. type DropFunctionOptions struct { - drop bool `ddl:"static" sql:"DROP"` - function bool `ddl:"static" sql:"FUNCTION"` - IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []FunctionArgumentType `ddl:"parameter,parentheses,no_equals"` + drop bool `ddl:"static" sql:"DROP"` + function bool `ddl:"static" sql:"FUNCTION"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name SchemaObjectIdentifier `ddl:"identifier"` + ArgumentDataTypes []DataType `ddl:"keyword,parentheses"` } // ShowFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/show-user-functions. @@ -237,30 +203,30 @@ type ShowFunctionOptions struct { } type functionRow struct { - 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 string `db:"is_secure"` - IsExternalFunction string `db:"is_external_function"` - Language string `db:"language"` - IsMemoizable string `db:"is_memoizable"` + 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"` + IsExternalFunction string `db:"is_external_function"` + Language string `db:"language"` + IsMemoizable sql.NullString `db:"is_memoizable"` } type Function struct { CreatedOn string Name string SchemaName string - IsBuiltIn bool + IsBuiltin bool IsAggregate bool IsAnsi bool MinNumArguments int @@ -278,10 +244,10 @@ type Function struct { // DescribeFunctionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-function. type DescribeFunctionOptions struct { - describe bool `ddl:"static" sql:"DESCRIBE"` - function bool `ddl:"static" sql:"FUNCTION"` - name SchemaObjectIdentifier `ddl:"identifier"` - ArgumentTypes []FunctionArgumentType `ddl:"parameter,parentheses,no_equals"` + describe bool `ddl:"static" sql:"DESCRIBE"` + function bool `ddl:"static" sql:"FUNCTION"` + name SchemaObjectIdentifier `ddl:"identifier"` + ArgumentDataTypes []DataType `ddl:"keyword,parentheses"` } type functionDetailRow struct { diff --git a/pkg/sdk/functions_gen_test.go b/pkg/sdk/functions_gen_test.go index 46f6359913..bc04a445cc 100644 --- a/pkg/sdk/functions_gen_test.go +++ b/pkg/sdk/functions_gen_test.go @@ -1,22 +1,23 @@ package sdk import ( + "errors" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" ) -func TestFunctions_CreateFunctionForJava(t *testing.T) { +func TestFunctions_CreateForJava(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateFunctionForJavaFunctionOptions { - return &CreateFunctionForJavaFunctionOptions{ + defaultOpts := func() *CreateForJavaFunctionOptions { + return &CreateForJavaFunctionOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - opts := (*CreateFunctionForJavaFunctionOptions)(nil) + opts := (*CreateForJavaFunctionOptions)(nil) assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -26,24 +27,37 @@ func TestFunctions_CreateFunctionForJava(t *testing.T) { assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) + t.Run("validation: function definition", func(t *testing.T) { + opts := defaultOpts() + opts.TargetPath = String("@~/testfunc.jar") + opts.Packages = []FunctionPackages{ + { + Package: "com.snowflake:snowpark:1.2.0", + }, + } + assertOptsInvalidJoinedErrors(t, opts, errors.New("TARGET_PATH must be nil when AS is nil")) + assertOptsInvalidJoinedErrors(t, opts, errors.New("PACKAGES must be empty when AS is nil")) + assertOptsInvalidJoinedErrors(t, opts, errors.New("IMPORTS must not be empty when AS is nil")) + }) + t.Run("all options", func(t *testing.T) { opts := defaultOpts() opts.OrReplace = Bool(true) opts.Temporary = Bool(true) opts.Secure = Bool(true) - opts.IfNotExists = Bool(true) opts.Arguments = []FunctionArgument{ { ArgName: "id", ArgDataType: DataTypeNumber, }, { - ArgName: "name", - ArgDataType: DataTypeVARCHAR, + ArgName: "name", + ArgDataType: DataTypeVARCHAR, + DefaultValue: String("'test'"), }, } opts.CopyGrants = Bool(true) - opts.Returns = &FunctionReturns{ + opts.Returns = FunctionReturns{ Table: &FunctionReturnsTable{ Columns: []FunctionColumn{ { @@ -57,12 +71,9 @@ func TestFunctions_CreateFunctionForJava(t *testing.T) { }, }, } - returnNullValues := FunctionReturnNullValuesNotNull - opts.ReturnNullValues = &returnNullValues - nullInputBehavior := FunctionNullInputBehaviorCalledOnNullInput - opts.NullInputBehavior = &nullInputBehavior - returnResultsBehavior := FunctionReturnResultsBehaviorImmutable - opts.ReturnResultsBehavior = &returnResultsBehavior + opts.ReturnNullValues = ReturnNullValuesPointer(ReturnNullValuesNotNull) + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorCalledOnNullInput) + opts.ReturnResultsBehavior = ReturnResultsBehaviorPointer(ReturnResultsBehaviorImmutable) opts.RuntimeVersion = String("2.0") opts.Comment = String("comment") opts.Imports = []FunctionImports{ @@ -79,33 +90,33 @@ func TestFunctions_CreateFunctionForJava(t *testing.T) { opts.ExternalAccessIntegrations = []AccountObjectIdentifier{ NewAccountObjectIdentifier("ext_integration"), } - opts.Secrets = []FunctionSecret{ + opts.Secrets = []Secret{ { - SecretVariableName: "variable1", - SecretName: "name1", + VariableName: "variable1", + Name: "name1", }, { - SecretVariableName: "variable2", - SecretName: "name2", + VariableName: "variable2", + Name: "name2", }, } opts.TargetPath = String("@~/testfunc.jar") - opts.FunctionDefinition = "return id + name;" - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION IF NOT EXISTS %s (id NUMBER, name VARCHAR) COPY GRANTS RETURNS TABLE (country_code VARCHAR, country_name VARCHAR) NOT NULL LANGUAGE JAVA CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '2.0' COMMENT = 'comment' IMPORTS = ('@~/my_decrement_udf_package_dir/my_decrement_udf_jar.jar') PACKAGES = ('com.snowflake:snowpark:1.2.0') HANDLER = 'TestFunc.echoVarchar' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) TARGET_PATH = '@~/testfunc.jar' AS 'return id + name;'`, id.FullyQualifiedName()) + opts.FunctionDefinition = String("return id + name;") + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (id NUMBER, name VARCHAR DEFAULT 'test') COPY GRANTS RETURNS TABLE (country_code VARCHAR, country_name VARCHAR) NOT NULL LANGUAGE JAVA CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '2.0' COMMENT = 'comment' IMPORTS = ('@~/my_decrement_udf_package_dir/my_decrement_udf_jar.jar') PACKAGES = ('com.snowflake:snowpark:1.2.0') HANDLER = 'TestFunc.echoVarchar' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) TARGET_PATH = '@~/testfunc.jar' AS 'return id + name;'`, id.FullyQualifiedName()) }) } -func TestFunctions_CreateFunctionForJavascript(t *testing.T) { +func TestFunctions_CreateForJavascript(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateFunctionForJavascriptFunctionOptions { - return &CreateFunctionForJavascriptFunctionOptions{ + defaultOpts := func() *CreateForJavascriptFunctionOptions { + return &CreateForJavascriptFunctionOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - opts := (*CreateFunctionForJavascriptFunctionOptions)(nil) + opts := (*CreateForJavascriptFunctionOptions)(nil) assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -122,38 +133,37 @@ func TestFunctions_CreateFunctionForJavascript(t *testing.T) { opts.Secure = Bool(true) opts.Arguments = []FunctionArgument{ { - ArgName: "d", - ArgDataType: DataTypeFloat, + ArgName: "d", + ArgDataType: DataTypeFloat, + DefaultValue: String("1.0"), }, } opts.CopyGrants = Bool(true) - float := DataTypeFloat - opts.Returns = &FunctionReturns{ - ResultDataType: &float, - } - returnNullValues := FunctionReturnNullValuesNotNull - opts.ReturnNullValues = &returnNullValues - nullInputBehavior := FunctionNullInputBehaviorCalledOnNullInput - opts.NullInputBehavior = &nullInputBehavior - returnResultsBehavior := FunctionReturnResultsBehaviorImmutable - opts.ReturnResultsBehavior = &returnResultsBehavior + opts.Returns = FunctionReturns{ + ResultDataType: &FunctionReturnsResultDataType{ + ResultDataType: DataTypeFloat, + }, + } + opts.ReturnNullValues = ReturnNullValuesPointer(ReturnNullValuesNotNull) + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorCalledOnNullInput) + opts.ReturnResultsBehavior = ReturnResultsBehaviorPointer(ReturnResultsBehaviorImmutable) opts.Comment = String("comment") - opts.FunctionDefinition = "return 1;" - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (d FLOAT) COPY GRANTS RETURNS FLOAT NOT NULL LANGUAGE JAVASCRIPT CALLED ON NULL INPUT IMMUTABLE COMMENT = 'comment' AS 'return 1;'`, id.FullyQualifiedName()) + opts.FunctionDefinition = String("return 1;") + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (d FLOAT DEFAULT 1.0) COPY GRANTS RETURNS FLOAT NOT NULL LANGUAGE JAVASCRIPT CALLED ON NULL INPUT IMMUTABLE COMMENT = 'comment' AS 'return 1;'`, id.FullyQualifiedName()) }) } -func TestFunctions_CreateFunctionForPython(t *testing.T) { +func TestFunctions_CreateForPython(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateFunctionForPythonFunctionOptions { - return &CreateFunctionForPythonFunctionOptions{ + defaultOpts := func() *CreateForPythonFunctionOptions { + return &CreateForPythonFunctionOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - opts := (*CreateFunctionForPythonFunctionOptions)(nil) + opts := (*CreateForPythonFunctionOptions)(nil) assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -163,29 +173,37 @@ func TestFunctions_CreateFunctionForPython(t *testing.T) { assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) + t.Run("validation: function definition", func(t *testing.T) { + opts := defaultOpts() + opts.Packages = []FunctionPackages{ + { + Package: "com.snowflake:snowpark:1.2.0", + }, + } + assertOptsInvalidJoinedErrors(t, opts, errors.New("IMPORTS must not be empty when AS is nil")) + }) + t.Run("all options", func(t *testing.T) { opts := defaultOpts() opts.OrReplace = Bool(true) opts.Temporary = Bool(true) opts.Secure = Bool(true) - opts.IfNotExists = Bool(true) opts.Arguments = []FunctionArgument{ { - ArgName: "i", - ArgDataType: DataTypeNumber, + ArgName: "i", + ArgDataType: DataTypeNumber, + DefaultValue: String("1"), }, } opts.CopyGrants = Bool(true) - varint := DataTypeVariant - opts.Returns = &FunctionReturns{ - ResultDataType: &varint, - } - returnNullValues := FunctionReturnNullValuesNotNull - opts.ReturnNullValues = &returnNullValues - nullInputBehavior := FunctionNullInputBehaviorCalledOnNullInput - opts.NullInputBehavior = &nullInputBehavior - returnResultsBehavior := FunctionReturnResultsBehaviorImmutable - opts.ReturnResultsBehavior = &returnResultsBehavior + opts.Returns = FunctionReturns{ + ResultDataType: &FunctionReturnsResultDataType{ + ResultDataType: DataTypeVariant, + }, + } + opts.ReturnNullValues = ReturnNullValuesPointer(ReturnNullValuesNotNull) + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorCalledOnNullInput) + opts.ReturnResultsBehavior = ReturnResultsBehaviorPointer(ReturnResultsBehaviorImmutable) opts.RuntimeVersion = "3.8" opts.Comment = String("comment") opts.Imports = []FunctionImports{ @@ -208,32 +226,32 @@ func TestFunctions_CreateFunctionForPython(t *testing.T) { opts.ExternalAccessIntegrations = []AccountObjectIdentifier{ NewAccountObjectIdentifier("ext_integration"), } - opts.Secrets = []FunctionSecret{ + opts.Secrets = []Secret{ { - SecretVariableName: "variable1", - SecretName: "name1", + VariableName: "variable1", + Name: "name1", }, { - SecretVariableName: "variable2", - SecretName: "name2", + VariableName: "variable2", + Name: "name2", }, } - opts.FunctionDefinition = "import numpy as np" - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION IF NOT EXISTS %s (i NUMBER) COPY GRANTS RETURNS VARIANT NOT NULL LANGUAGE PYTHON CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '3.8' COMMENT = 'comment' IMPORTS = ('numpy', 'pandas') PACKAGES = ('numpy', 'pandas') HANDLER = 'udf' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) AS 'import numpy as np'`, id.FullyQualifiedName()) + opts.FunctionDefinition = String("import numpy as np") + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (i NUMBER DEFAULT 1) COPY GRANTS RETURNS VARIANT NOT NULL LANGUAGE PYTHON CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '3.8' COMMENT = 'comment' IMPORTS = ('numpy', 'pandas') PACKAGES = ('numpy', 'pandas') HANDLER = 'udf' EXTERNAL_ACCESS_INTEGRATIONS = ("ext_integration") SECRETS = ('variable1' = name1, 'variable2' = name2) AS 'import numpy as np'`, id.FullyQualifiedName()) }) } -func TestFunctions_CreateFunctionForScala(t *testing.T) { +func TestFunctions_CreateForScala(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateFunctionForScalaFunctionOptions { - return &CreateFunctionForScalaFunctionOptions{ + defaultOpts := func() *CreateForScalaFunctionOptions { + return &CreateForScalaFunctionOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - opts := (*CreateFunctionForScalaFunctionOptions)(nil) + opts := (*CreateForScalaFunctionOptions)(nil) assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -243,29 +261,36 @@ func TestFunctions_CreateFunctionForScala(t *testing.T) { assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) + t.Run("validation: function definition", func(t *testing.T) { + opts := defaultOpts() + opts.TargetPath = String("@~/testfunc.jar") + opts.Packages = []FunctionPackages{ + { + Package: "com.snowflake:snowpark:1.2.0", + }, + } + assertOptsInvalidJoinedErrors(t, opts, errors.New("TARGET_PATH must be nil when AS is nil")) + assertOptsInvalidJoinedErrors(t, opts, errors.New("PACKAGES must be empty when AS is nil")) + assertOptsInvalidJoinedErrors(t, opts, errors.New("IMPORTS must not be empty when AS is nil")) + }) + t.Run("all options", func(t *testing.T) { opts := defaultOpts() opts.OrReplace = Bool(true) opts.Temporary = Bool(true) opts.Secure = Bool(true) - opts.IfNotExists = Bool(true) opts.Arguments = []FunctionArgument{ { - ArgName: "x", - ArgDataType: DataTypeVARCHAR, + ArgName: "x", + ArgDataType: DataTypeVARCHAR, + DefaultValue: String("'test'"), }, } opts.CopyGrants = Bool(true) - varchar := DataTypeVARCHAR - opts.Returns = &FunctionReturns{ - ResultDataType: &varchar, - } - returnNullValues := FunctionReturnNullValuesNotNull - opts.ReturnNullValues = &returnNullValues - nullInputBehavior := FunctionNullInputBehaviorCalledOnNullInput - opts.NullInputBehavior = &nullInputBehavior - returnResultsBehavior := FunctionReturnResultsBehaviorImmutable - opts.ReturnResultsBehavior = &returnResultsBehavior + opts.ResultDataType = DataTypeVARCHAR + opts.ReturnNullValues = ReturnNullValuesPointer(ReturnNullValuesNotNull) + opts.NullInputBehavior = NullInputBehaviorPointer(NullInputBehaviorCalledOnNullInput) + opts.ReturnResultsBehavior = ReturnResultsBehaviorPointer(ReturnResultsBehaviorImmutable) opts.RuntimeVersion = String("2.0") opts.Comment = String("comment") opts.Imports = []FunctionImports{ @@ -273,23 +298,23 @@ func TestFunctions_CreateFunctionForScala(t *testing.T) { Import: "@udf_libs/echohandler.jar", }, } - opts.Handler ="Echo.echoVarchar" - opts.FunctionDefinition = "return x" - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION IF NOT EXISTS %s (x VARCHAR) COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SCALA CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '2.0' COMMENT = 'comment' IMPORTS = ('@udf_libs/echohandler.jar') HANDLER = 'Echo.echoVarchar' AS 'return x'`, id.FullyQualifiedName()) + opts.Handler = "Echo.echoVarchar" + opts.FunctionDefinition = String("return x") + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (x VARCHAR DEFAULT 'test') COPY GRANTS RETURNS VARCHAR NOT NULL LANGUAGE SCALA CALLED ON NULL INPUT IMMUTABLE RUNTIME_VERSION = '2.0' COMMENT = 'comment' IMPORTS = ('@udf_libs/echohandler.jar') HANDLER = 'Echo.echoVarchar' AS 'return x'`, id.FullyQualifiedName()) }) } -func TestFunctions_CreateFunctionForSQL(t *testing.T) { +func TestFunctions_CreateForSQL(t *testing.T) { id := RandomSchemaObjectIdentifier() - defaultOpts := func() *CreateFunctionForSQLFunctionOptions { - return &CreateFunctionForSQLFunctionOptions{ + defaultOpts := func() *CreateForSQLFunctionOptions { + return &CreateForSQLFunctionOptions{ name: id, } } t.Run("validation: nil options", func(t *testing.T) { - opts := (*CreateFunctionForSQLFunctionOptions)(nil) + opts := (*CreateForSQLFunctionOptions)(nil) assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) }) @@ -304,20 +329,25 @@ func TestFunctions_CreateFunctionForSQL(t *testing.T) { opts.OrReplace = Bool(true) opts.Temporary = Bool(true) opts.Secure = Bool(true) - opts.IfNotExists = Bool(true) + opts.Arguments = []FunctionArgument{ + { + ArgName: "message", + ArgDataType: "VARCHAR", + DefaultValue: String("'test'"), + }, + } opts.CopyGrants = Bool(true) - dt := DataTypeFloat - opts.Returns = &FunctionReturns{ - ResultDataType: &dt, - } - returnNullValues := FunctionReturnNullValuesNotNull - opts.ReturnNullValues = &returnNullValues - returnResultsBehavior := FunctionReturnResultsBehaviorImmutable - opts.ReturnResultsBehavior = &returnResultsBehavior + opts.Returns = FunctionReturns{ + ResultDataType: &FunctionReturnsResultDataType{ + ResultDataType: DataTypeFloat, + }, + } + opts.ReturnNullValues = ReturnNullValuesPointer(ReturnNullValuesNotNull) + opts.ReturnResultsBehavior = ReturnResultsBehaviorPointer(ReturnResultsBehaviorImmutable) opts.Memoizable = Bool(true) opts.Comment = String("comment") - opts.FunctionDefinition = "3.141592654::FLOAT" - assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION IF NOT EXISTS %s COPY GRANTS RETURNS FLOAT NOT NULL IMMUTABLE MEMOIZABLE COMMENT = 'comment' AS '3.141592654::FLOAT'`, id.FullyQualifiedName()) + opts.FunctionDefinition = String("3.141592654::FLOAT") + assertOptsValidAndSQLEquals(t, opts, `CREATE OR REPLACE TEMPORARY SECURE FUNCTION %s (message VARCHAR DEFAULT 'test') COPY GRANTS RETURNS FLOAT NOT NULL IMMUTABLE MEMOIZABLE COMMENT = 'comment' AS '3.141592654::FLOAT'`, id.FullyQualifiedName()) }) } @@ -346,14 +376,7 @@ func TestFunctions_Drop(t *testing.T) { name: id, } opts.IfExists = Bool(true) - opts.ArgumentTypes = []FunctionArgumentType{ - { - ArgDataType: DataTypeVARCHAR, - }, - { - ArgDataType: DataTypeNumber, - }, - } + opts.ArgumentDataTypes = []DataType{DataTypeVARCHAR, DataTypeNumber} assertOptsValidAndSQLEquals(t, opts, `DROP FUNCTION IF EXISTS %s (VARCHAR, NUMBER)`, id.FullyQualifiedName()) }) } @@ -363,16 +386,9 @@ func TestFunctions_Alter(t *testing.T) { defaultOpts := func() *AlterFunctionOptions { return &AlterFunctionOptions{ - name: id, - IfExists: Bool(true), - ArgumentTypes: []FunctionArgumentType{ - { - ArgDataType: DataTypeVARCHAR, - }, - { - ArgDataType: DataTypeNumber, - }, - }, + name: id, + IfExists: Bool(true), + ArgumentDataTypes: []DataType{DataTypeVARCHAR, DataTypeNumber}, } } @@ -387,6 +403,18 @@ func TestFunctions_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("AlterFunctionOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "SetSecure", "UnsetLogLevel", "UnsetTraceLevel", "UnsetSecure", "UnsetComment", "SetTags", "UnsetTags")) + }) + + 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("AlterFunctionOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "SetSecure", "UnsetLogLevel", "UnsetTraceLevel", "UnsetSecure", "UnsetComment", "SetTags", "UnsetTags")) + }) + t.Run("alter: rename to", func(t *testing.T) { opts := defaultOpts() target := NewSchemaObjectIdentifier(id.DatabaseName(), id.SchemaName(), random.StringN(12)) @@ -396,49 +424,49 @@ func TestFunctions_Alter(t *testing.T) { t.Run("alter: set log level", func(t *testing.T) { opts := defaultOpts() - opts.Set = &FunctionSet{ - LogLevel: String("DEBUG"), - } + opts.SetLogLevel = String("DEBUG") assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION 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 = &FunctionSet{ - TraceLevel: String("DEBUG"), - } + opts.SetTraceLevel = String("DEBUG") assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) SET TRACE_LEVEL = 'DEBUG'`, id.FullyQualifiedName()) }) t.Run("alter: set comment", func(t *testing.T) { opts := defaultOpts() - opts.Set = &FunctionSet{ - Comment: String("comment"), - } + opts.SetComment = String("comment") assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) SET COMMENT = 'comment'`, id.FullyQualifiedName()) }) t.Run("alter: set secure", func(t *testing.T) { opts := defaultOpts() - opts.Set = &FunctionSet{ - Secure: Bool(true), - } + opts.SetSecure = Bool(true) assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) SET SECURE`, id.FullyQualifiedName()) }) + t.Run("alter: unset log level", func(t *testing.T) { + opts := defaultOpts() + opts.UnsetLogLevel = Bool(true) + assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) UNSET LOG_LEVEL`, id.FullyQualifiedName()) + }) + + t.Run("alter: unset trace level", func(t *testing.T) { + opts := defaultOpts() + opts.UnsetTraceLevel = Bool(true) + assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) UNSET TRACE_LEVEL`, id.FullyQualifiedName()) + }) + t.Run("alter: unset secure", func(t *testing.T) { opts := defaultOpts() - opts.Unset = &FunctionUnset{ - Secure: Bool(true), - } + opts.UnsetSecure = Bool(true) assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) UNSET SECURE`, id.FullyQualifiedName()) }) t.Run("alter: unset comment", func(t *testing.T) { opts := defaultOpts() - opts.Unset = &FunctionUnset{ - Comment: Bool(true), - } + opts.UnsetComment = Bool(true) assertOptsValidAndSQLEquals(t, opts, `ALTER FUNCTION IF EXISTS %s (VARCHAR, NUMBER) UNSET COMMENT`, id.FullyQualifiedName()) }) @@ -473,12 +501,6 @@ func TestFunctions_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 USER FUNCTIONS`) diff --git a/pkg/sdk/functions_impl_gen.go b/pkg/sdk/functions_impl_gen.go index f1be1337a9..70426de5ae 100644 --- a/pkg/sdk/functions_impl_gen.go +++ b/pkg/sdk/functions_impl_gen.go @@ -12,27 +12,27 @@ type functions struct { client *Client } -func (v *functions) CreateFunctionForJava(ctx context.Context, request *CreateFunctionForJavaFunctionRequest) error { +func (v *functions) CreateForJava(ctx context.Context, request *CreateForJavaFunctionRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *functions) CreateFunctionForJavascript(ctx context.Context, request *CreateFunctionForJavascriptFunctionRequest) error { +func (v *functions) CreateForJavascript(ctx context.Context, request *CreateForJavascriptFunctionRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *functions) CreateFunctionForPython(ctx context.Context, request *CreateFunctionForPythonFunctionRequest) error { +func (v *functions) CreateForPython(ctx context.Context, request *CreateForPythonFunctionRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *functions) CreateFunctionForScala(ctx context.Context, request *CreateFunctionForScalaFunctionRequest) error { +func (v *functions) CreateForScala(ctx context.Context, request *CreateForScalaFunctionRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } -func (v *functions) CreateFunctionForSQL(ctx context.Context, request *CreateFunctionForSQLFunctionRequest) error { +func (v *functions) CreateForSQL(ctx context.Context, request *CreateForSQLFunctionRequest) error { opts := request.toOpts() return validateAndExec(v.client, ctx, opts) } @@ -58,7 +58,7 @@ func (v *functions) Show(ctx context.Context, request *ShowFunctionRequest) ([]F } func (v *functions) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*Function, error) { - request := NewShowFunctionRequest().WithLike(id.Name()) + request := NewShowFunctionRequest().WithIn(&In{Database: NewAccountObjectIdentifier(id.DatabaseName())}).WithLike(&Like{String(id.Name())}) functions, err := v.Show(ctx, request) if err != nil { return nil, err @@ -75,8 +75,8 @@ func (v *functions) Describe(ctx context.Context, request *DescribeFunctionReque return convertRows[functionDetailRow, FunctionDetail](rows), nil } -func (r *CreateFunctionForJavaFunctionRequest) toOpts() *CreateFunctionForJavaFunctionOptions { - opts := &CreateFunctionForJavaFunctionOptions{ +func (r *CreateForJavaFunctionRequest) toOpts() *CreateForJavaFunctionOptions { + opts := &CreateForJavaFunctionOptions{ OrReplace: r.OrReplace, Temporary: r.Temporary, Secure: r.Secure, @@ -85,52 +85,48 @@ func (r *CreateFunctionForJavaFunctionRequest) toOpts() *CreateFunctionForJavaFu CopyGrants: r.CopyGrants, - RuntimeVersion: r.RuntimeVersion, - Comment: r.Comment, + ReturnNullValues: r.ReturnNullValues, + NullInputBehavior: r.NullInputBehavior, + ReturnResultsBehavior: r.ReturnResultsBehavior, + RuntimeVersion: r.RuntimeVersion, + Comment: r.Comment, Handler: r.Handler, ExternalAccessIntegrations: r.ExternalAccessIntegrations, - - TargetPath: r.TargetPath, + Secrets: r.Secrets, + TargetPath: r.TargetPath, + FunctionDefinition: r.FunctionDefinition, } if r.Arguments != nil { s := make([]FunctionArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = FunctionArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, - Default: v.Default, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &FunctionReturns{ - ResultDataType: r.Returns.ResultDataType, + opts.Returns = FunctionReturns{} + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &FunctionReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, } - if r.Returns.Table != nil { - opts.Returns.Table = &FunctionReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]FunctionColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = FunctionColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &FunctionReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]FunctionColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = FunctionColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } - if r.ReturnNullValues != nil { - opts.ReturnNullValues = r.ReturnNullValues - } - if r.NullInputBehavior != nil { - opts.NullInputBehavior = r.NullInputBehavior - } - if r.ReturnResultsBehavior != nil { - opts.ReturnResultsBehavior = r.ReturnResultsBehavior - } if r.Imports != nil { s := make([]FunctionImports, len(r.Imports)) for i, v := range r.Imports { @@ -149,77 +145,59 @@ func (r *CreateFunctionForJavaFunctionRequest) toOpts() *CreateFunctionForJavaFu } opts.Packages = s } - if r.Secrets != nil { - s := make([]FunctionSecret, len(r.Secrets)) - for i, v := range r.Secrets { - s[i] = FunctionSecret{ - SecretVariableName: v.SecretVariableName, - SecretName: v.SecretName, - } - } - opts.Secrets = s - } - opts.FunctionDefinition = r.FunctionDefinition return opts } -func (r *CreateFunctionForJavascriptFunctionRequest) toOpts() *CreateFunctionForJavascriptFunctionOptions { - opts := &CreateFunctionForJavascriptFunctionOptions{ - OrReplace: r.OrReplace, - Temporary: r.Temporary, - Secure: r.Secure, - IfNotExists: r.IfNotExists, - name: r.name, +func (r *CreateForJavascriptFunctionRequest) toOpts() *CreateForJavascriptFunctionOptions { + opts := &CreateForJavascriptFunctionOptions{ + OrReplace: r.OrReplace, + Temporary: r.Temporary, + Secure: r.Secure, + name: r.name, CopyGrants: r.CopyGrants, - Comment: r.Comment, + ReturnNullValues: r.ReturnNullValues, + NullInputBehavior: r.NullInputBehavior, + ReturnResultsBehavior: r.ReturnResultsBehavior, + Comment: r.Comment, + FunctionDefinition: r.FunctionDefinition, } if r.Arguments != nil { s := make([]FunctionArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = FunctionArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, - Default: v.Default, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &FunctionReturns{ - ResultDataType: r.Returns.ResultDataType, + opts.Returns = FunctionReturns{} + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &FunctionReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, } - if r.Returns.Table != nil { - opts.Returns.Table = &FunctionReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]FunctionColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = FunctionColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &FunctionReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]FunctionColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = FunctionColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } - if r.ReturnNullValues != nil { - opts.ReturnNullValues = r.ReturnNullValues - } - if r.NullInputBehavior != nil { - opts.NullInputBehavior = r.NullInputBehavior - } - if r.ReturnResultsBehavior != nil { - opts.ReturnResultsBehavior = r.ReturnResultsBehavior - } - - opts.FunctionDefinition = r.FunctionDefinition return opts } -func (r *CreateFunctionForPythonFunctionRequest) toOpts() *CreateFunctionForPythonFunctionOptions { - opts := &CreateFunctionForPythonFunctionOptions{ +func (r *CreateForPythonFunctionRequest) toOpts() *CreateForPythonFunctionOptions { + opts := &CreateForPythonFunctionOptions{ OrReplace: r.OrReplace, Temporary: r.Temporary, Secure: r.Secure, @@ -228,50 +206,47 @@ func (r *CreateFunctionForPythonFunctionRequest) toOpts() *CreateFunctionForPyth CopyGrants: r.CopyGrants, - RuntimeVersion: r.RuntimeVersion, - Comment: r.Comment, + ReturnNullValues: r.ReturnNullValues, + NullInputBehavior: r.NullInputBehavior, + ReturnResultsBehavior: r.ReturnResultsBehavior, + RuntimeVersion: r.RuntimeVersion, + Comment: r.Comment, Handler: r.Handler, ExternalAccessIntegrations: r.ExternalAccessIntegrations, + Secrets: r.Secrets, + FunctionDefinition: r.FunctionDefinition, } if r.Arguments != nil { s := make([]FunctionArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = FunctionArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, - Default: v.Default, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &FunctionReturns{ - ResultDataType: r.Returns.ResultDataType, + opts.Returns = FunctionReturns{} + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &FunctionReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, } - if r.Returns.Table != nil { - opts.Returns.Table = &FunctionReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]FunctionColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = FunctionColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &FunctionReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]FunctionColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = FunctionColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } - if r.ReturnNullValues != nil { - opts.ReturnNullValues = r.ReturnNullValues - } - if r.NullInputBehavior != nil { - opts.NullInputBehavior = r.NullInputBehavior - } - if r.ReturnResultsBehavior != nil { - opts.ReturnResultsBehavior = r.ReturnResultsBehavior - } if r.Imports != nil { s := make([]FunctionImports, len(r.Imports)) for i, v := range r.Imports { @@ -290,74 +265,40 @@ func (r *CreateFunctionForPythonFunctionRequest) toOpts() *CreateFunctionForPyth } opts.Packages = s } - if r.Secrets != nil { - s := make([]FunctionSecret, len(r.Secrets)) - for i, v := range r.Secrets { - s[i] = FunctionSecret{ - SecretVariableName: v.SecretVariableName, - SecretName: v.SecretName, - } - } - opts.Secrets = s - } - opts.FunctionDefinition = r.FunctionDefinition return opts } -func (r *CreateFunctionForScalaFunctionRequest) toOpts() *CreateFunctionForScalaFunctionOptions { - opts := &CreateFunctionForScalaFunctionOptions{ +func (r *CreateForScalaFunctionRequest) toOpts() *CreateForScalaFunctionOptions { + opts := &CreateForScalaFunctionOptions{ OrReplace: r.OrReplace, Temporary: r.Temporary, Secure: r.Secure, IfNotExists: r.IfNotExists, name: r.name, - CopyGrants: r.CopyGrants, - - RuntimeVersion: r.RuntimeVersion, - Comment: r.Comment, + CopyGrants: r.CopyGrants, + ResultDataType: r.ResultDataType, + ReturnNullValues: r.ReturnNullValues, + NullInputBehavior: r.NullInputBehavior, + ReturnResultsBehavior: r.ReturnResultsBehavior, + RuntimeVersion: r.RuntimeVersion, + Comment: r.Comment, - Handler: r.Handler, - TargetPath: r.TargetPath, + Handler: r.Handler, + TargetPath: r.TargetPath, + FunctionDefinition: r.FunctionDefinition, } if r.Arguments != nil { s := make([]FunctionArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = FunctionArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, - Default: v.Default, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &FunctionReturns{ - ResultDataType: r.Returns.ResultDataType, - } - if r.Returns.Table != nil { - opts.Returns.Table = &FunctionReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]FunctionColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = FunctionColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } - } - opts.Returns.Table.Columns = s - } - } - } - if r.ReturnNullValues != nil { - opts.ReturnNullValues = r.ReturnNullValues - } - if r.NullInputBehavior != nil { - opts.NullInputBehavior = r.NullInputBehavior - } - if r.ReturnResultsBehavior != nil { - opts.ReturnResultsBehavior = r.ReturnResultsBehavior - } if r.Imports != nil { s := make([]FunctionImports, len(r.Imports)) for i, v := range r.Imports { @@ -376,112 +317,82 @@ func (r *CreateFunctionForScalaFunctionRequest) toOpts() *CreateFunctionForScala } opts.Packages = s } - opts.FunctionDefinition = r.FunctionDefinition return opts } -func (r *CreateFunctionForSQLFunctionRequest) toOpts() *CreateFunctionForSQLFunctionOptions { - opts := &CreateFunctionForSQLFunctionOptions{ - OrReplace: r.OrReplace, - Temporary: r.Temporary, - Secure: r.Secure, - IfNotExists: r.IfNotExists, - name: r.name, +func (r *CreateForSQLFunctionRequest) toOpts() *CreateForSQLFunctionOptions { + opts := &CreateForSQLFunctionOptions{ + OrReplace: r.OrReplace, + Temporary: r.Temporary, + Secure: r.Secure, + name: r.name, CopyGrants: r.CopyGrants, - Memoizable: r.Memoizable, - Comment: r.Comment, + ReturnNullValues: r.ReturnNullValues, + ReturnResultsBehavior: r.ReturnResultsBehavior, + Memoizable: r.Memoizable, + Comment: r.Comment, + FunctionDefinition: r.FunctionDefinition, } if r.Arguments != nil { s := make([]FunctionArgument, len(r.Arguments)) for i, v := range r.Arguments { s[i] = FunctionArgument{ - ArgName: v.ArgName, - ArgDataType: v.ArgDataType, - Default: v.Default, + ArgName: v.ArgName, + ArgDataType: v.ArgDataType, + DefaultValue: v.DefaultValue, } } opts.Arguments = s } - if r.Returns != nil { - opts.Returns = &FunctionReturns{ - ResultDataType: r.Returns.ResultDataType, + opts.Returns = FunctionReturns{} + if r.Returns.ResultDataType != nil { + opts.Returns.ResultDataType = &FunctionReturnsResultDataType{ + ResultDataType: r.Returns.ResultDataType.ResultDataType, } - if r.Returns.Table != nil { - opts.Returns.Table = &FunctionReturnsTable{} - if r.Returns.Table.Columns != nil { - s := make([]FunctionColumn, len(r.Returns.Table.Columns)) - for i, v := range r.Returns.Table.Columns { - s[i] = FunctionColumn{ - ColumnName: v.ColumnName, - ColumnDataType: v.ColumnDataType, - } + } + if r.Returns.Table != nil { + opts.Returns.Table = &FunctionReturnsTable{} + if r.Returns.Table.Columns != nil { + s := make([]FunctionColumn, len(r.Returns.Table.Columns)) + for i, v := range r.Returns.Table.Columns { + s[i] = FunctionColumn{ + ColumnName: v.ColumnName, + ColumnDataType: v.ColumnDataType, } - opts.Returns.Table.Columns = s } + opts.Returns.Table.Columns = s } } - if r.ReturnNullValues != nil { - opts.ReturnNullValues = r.ReturnNullValues - } - if r.ReturnResultsBehavior != nil { - opts.ReturnResultsBehavior = r.ReturnResultsBehavior - } - opts.FunctionDefinition = r.FunctionDefinition return opts } func (r *AlterFunctionRequest) toOpts() *AlterFunctionOptions { opts := &AlterFunctionOptions{ - IfExists: r.IfExists, - name: r.name, - - RenameTo: r.RenameTo, - SetTags: r.SetTags, - UnsetTags: r.UnsetTags, - } - if r.ArgumentTypes != nil { - s := make([]FunctionArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = FunctionArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s - } - if r.Set != nil { - opts.Set = &FunctionSet{ - LogLevel: r.Set.LogLevel, - TraceLevel: r.Set.TraceLevel, - Comment: r.Set.Comment, - Secure: r.Set.Secure, - } - } - if r.Unset != nil { - opts.Unset = &FunctionUnset{ - Secure: r.Unset.Secure, - Comment: r.Unset.Comment, - LogLevel: r.Unset.LogLevel, - TraceLevel: r.Unset.TraceLevel, - } + IfExists: r.IfExists, + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, + RenameTo: r.RenameTo, + SetComment: r.SetComment, + SetLogLevel: r.SetLogLevel, + SetTraceLevel: r.SetTraceLevel, + SetSecure: r.SetSecure, + UnsetSecure: r.UnsetSecure, + UnsetLogLevel: r.UnsetLogLevel, + UnsetTraceLevel: r.UnsetTraceLevel, + UnsetComment: r.UnsetComment, + SetTags: r.SetTags, + UnsetTags: r.UnsetTags, } return opts } func (r *DropFunctionRequest) toOpts() *DropFunctionOptions { opts := &DropFunctionOptions{ - IfExists: r.IfExists, - name: r.name, - } - if r.ArgumentTypes != nil { - s := make([]FunctionArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = FunctionArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s + IfExists: r.IfExists, + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, } return opts } @@ -495,11 +406,11 @@ func (r *ShowFunctionRequest) toOpts() *ShowFunctionOptions { } func (r functionRow) convert() *Function { - return &Function{ + e := &Function{ CreatedOn: r.CreatedOn, Name: r.Name, SchemaName: r.SchemaName, - IsBuiltIn: r.IsBuiltIn == "Y", + IsBuiltin: r.IsBuiltin == "Y", IsAggregate: r.IsAggregate == "Y", IsAnsi: r.IsAnsi == "Y", MinNumArguments: r.MinNumArguments, @@ -509,25 +420,22 @@ func (r functionRow) convert() *Function { CatalogName: r.CatalogName, IsTableFunction: r.IsTableFunction == "Y", ValidForClustering: r.ValidForClustering == "Y", - IsSecure: r.IsSecure == "Y", IsExternalFunction: r.IsExternalFunction == "Y", Language: r.Language, - IsMemoizable: r.IsMemoizable == "Y", } + if r.IsSecure.Valid { + e.IsSecure = r.IsSecure.String == "Y" + } + if r.IsMemoizable.Valid { + e.IsMemoizable = r.IsMemoizable.String == "Y" + } + return e } func (r *DescribeFunctionRequest) toOpts() *DescribeFunctionOptions { opts := &DescribeFunctionOptions{ - name: r.name, - } - if r.ArgumentTypes != nil { - s := make([]FunctionArgumentType, len(r.ArgumentTypes)) - for i, v := range r.ArgumentTypes { - s[i] = FunctionArgumentType{ - ArgDataType: v.ArgDataType, - } - } - opts.ArgumentTypes = s + name: r.name, + ArgumentDataTypes: r.ArgumentDataTypes, } return opts } diff --git a/pkg/sdk/functions_validations_gen.go b/pkg/sdk/functions_validations_gen.go index 0ec3c77252..c92298b1b0 100644 --- a/pkg/sdk/functions_validations_gen.go +++ b/pkg/sdk/functions_validations_gen.go @@ -1,29 +1,20 @@ package sdk +import "errors" + var ( - _ validatable = new(CreateFunctionForJavaFunctionOptions) - _ validatable = new(CreateFunctionForJavascriptFunctionOptions) - _ validatable = new(CreateFunctionForPythonFunctionOptions) - _ validatable = new(CreateFunctionForScalaFunctionOptions) - _ validatable = new(CreateFunctionForSQLFunctionOptions) + _ validatable = new(CreateForJavaFunctionOptions) + _ validatable = new(CreateForJavascriptFunctionOptions) + _ validatable = new(CreateForPythonFunctionOptions) + _ validatable = new(CreateForScalaFunctionOptions) + _ validatable = new(CreateForSQLFunctionOptions) _ validatable = new(AlterFunctionOptions) _ validatable = new(DropFunctionOptions) _ validatable = new(ShowFunctionOptions) _ validatable = new(DescribeFunctionOptions) ) -func (v *FunctionReturns) 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 *CreateFunctionForJavaFunctionOptions) validate() error { +func (opts *CreateForJavaFunctionOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -31,13 +22,29 @@ func (opts *CreateFunctionForJavaFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if everyValueSet(opts.OrReplace, opts.IfNotExists) { + errs = append(errs, errOneOf("CreateForJavaFunctionOptions", "OrReplace", "IfNotExists")) + } + if valueSet(opts.Returns) { + if !exactlyOneValueSet(opts.Returns.ResultDataType, opts.Returns.Table) { + errs = append(errs, errExactlyOneOf("CreateForJavaFunctionOptions.Returns", "ResultDataType", "Table")) + } + } + if opts.FunctionDefinition == nil { + if opts.TargetPath != nil { + errs = append(errs, errors.New("TARGET_PATH must be nil when AS is nil")) + } + if len(opts.Packages) > 0 { + errs = append(errs, errors.New("PACKAGES must be empty when AS is nil")) + } + if len(opts.Imports) == 0 { + errs = append(errs, errors.New("IMPORTS must not be empty when AS is nil")) + } } return JoinErrors(errs...) } -func (opts *CreateFunctionForJavascriptFunctionOptions) validate() error { +func (opts *CreateForJavascriptFunctionOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -45,13 +52,15 @@ func (opts *CreateFunctionForJavascriptFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if valueSet(opts.Returns) { + if !exactlyOneValueSet(opts.Returns.ResultDataType, opts.Returns.Table) { + errs = append(errs, errExactlyOneOf("CreateForJavascriptFunctionOptions.Returns", "ResultDataType", "Table")) + } } return JoinErrors(errs...) } -func (opts *CreateFunctionForPythonFunctionOptions) validate() error { +func (opts *CreateForPythonFunctionOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -59,13 +68,23 @@ func (opts *CreateFunctionForPythonFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if everyValueSet(opts.OrReplace, opts.IfNotExists) { + errs = append(errs, errOneOf("CreateForPythonFunctionOptions", "OrReplace", "IfNotExists")) + } + if valueSet(opts.Returns) { + if !exactlyOneValueSet(opts.Returns.ResultDataType, opts.Returns.Table) { + errs = append(errs, errExactlyOneOf("CreateForPythonFunctionOptions.Returns", "ResultDataType", "Table")) + } + } + if opts.FunctionDefinition == nil { + if len(opts.Imports) == 0 { + errs = append(errs, errors.New("IMPORTS must not be empty when AS is nil")) + } } return JoinErrors(errs...) } -func (opts *CreateFunctionForScalaFunctionOptions) validate() error { +func (opts *CreateForScalaFunctionOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -73,13 +92,24 @@ func (opts *CreateFunctionForScalaFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if everyValueSet(opts.OrReplace, opts.IfNotExists) { + errs = append(errs, errOneOf("CreateForScalaFunctionOptions", "OrReplace", "IfNotExists")) + } + if opts.FunctionDefinition == nil { + if opts.TargetPath != nil { + errs = append(errs, errors.New("TARGET_PATH must be nil when AS is nil")) + } + if len(opts.Packages) > 0 { + errs = append(errs, errors.New("PACKAGES must be empty when AS is nil")) + } + if len(opts.Imports) == 0 { + errs = append(errs, errors.New("IMPORTS must not be empty when AS is nil")) + } } return JoinErrors(errs...) } -func (opts *CreateFunctionForSQLFunctionOptions) validate() error { +func (opts *CreateForSQLFunctionOptions) validate() error { if opts == nil { return ErrNilOptions } @@ -87,8 +117,10 @@ func (opts *CreateFunctionForSQLFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if err := opts.Returns.validate(); err != nil { - errs = append(errs, err) + if valueSet(opts.Returns) { + if !exactlyOneValueSet(opts.Returns.ResultDataType, opts.Returns.Table) { + errs = append(errs, errExactlyOneOf("CreateForSQLFunctionOptions.Returns", "ResultDataType", "Table")) + } } return JoinErrors(errs...) } @@ -101,8 +133,11 @@ func (opts *AlterFunctionOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if !exactlyOneValueSet(opts.Set, opts.Unset, opts.SetTags, opts.UnsetTags, opts.RenameTo) { - errs = append(errs, errExactlyOneOf("Set", "Unset", "SetTags", "UnsetTags", "RenameTo")) + if opts.RenameTo != nil && !ValidObjectIdentifier(opts.RenameTo) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + if !exactlyOneValueSet(opts.RenameTo, opts.SetComment, opts.SetLogLevel, opts.SetTraceLevel, opts.SetSecure, opts.UnsetLogLevel, opts.UnsetTraceLevel, opts.UnsetSecure, opts.UnsetComment, opts.SetTags, opts.UnsetTags) { + errs = append(errs, errExactlyOneOf("AlterFunctionOptions", "RenameTo", "SetComment", "SetLogLevel", "SetTraceLevel", "SetSecure", "UnsetLogLevel", "UnsetTraceLevel", "UnsetSecure", "UnsetComment", "SetTags", "UnsetTags")) } return JoinErrors(errs...) } @@ -123,9 +158,6 @@ func (opts *ShowFunctionOptions) validate() error { return ErrNilOptions } var errs []error - if valueSet(opts.Like) && !valueSet(opts.Like.Pattern) { - errs = append(errs, ErrPatternRequiredForLikeKeyword) - } return JoinErrors(errs...) } 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/testint/functions_integration_test.go b/pkg/sdk/testint/functions_integration_test.go index 6c7a210b39..bd021a6dc7 100644 --- a/pkg/sdk/testint/functions_integration_test.go +++ b/pkg/sdk/testint/functions_integration_test.go @@ -18,13 +18,11 @@ func TestInt_CreateFunctions(t *testing.T) { client := testClient(t) ctx := context.Background() - cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, argumentTypes []sdk.DataType) func() { + databaseTest, schemaTest := testDb(t), testSchema(t) + + cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, dts []sdk.DataType) func() { return func() { - es := []sdk.FunctionArgumentTypeRequest{} - for _, item := range argumentTypes { - es = append(es, *sdk.NewFunctionArgumentTypeRequest().WithArgDataType(item)) - } - err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id).WithArgumentTypes(es)) + err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id, dts)) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } @@ -34,123 +32,133 @@ func TestInt_CreateFunctions(t *testing.T) { t.Run("create function for Java", func(t *testing.T) { name := "echo_varchar" - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) definition := ` - class TestFunc { - public static String echoVarchar(String x) { - return x; - } - }` +class TestFunc { + public static String echoVarchar(String x) { + return x; + } +}` target := fmt.Sprintf("@~/tf-%d.jar", time.Now().Unix()) - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeVARCHAR) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("x").WithArgDataType(sdk.DataTypeVARCHAR).WithDefault(sdk.String("abc")) - request := sdk.NewCreateFunctionForJavaFunctionRequest(id, returnsRequest, "TestFunc.echoVarchar", definition). + dt := sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeVARCHAR) + returns := sdk.NewFunctionReturnsRequest().WithResultDataType(dt) + argument := sdk.NewFunctionArgumentRequest("x", sdk.DataTypeVARCHAR).WithDefaultValue(sdk.String("'abc'")) + request := sdk.NewCreateForJavaFunctionRequest(id, *returns, "TestFunc.echoVarchar"). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}). - WithNullInputBehavior(sdk.FunctionNullInputBehaviorCalledOnNullInput). - WithTargetPath(&target) - err := client.Functions.CreateFunctionForJava(ctx, request) + WithArguments([]sdk.FunctionArgumentRequest{*argument}). + WithNullInputBehavior(sdk.NullInputBehaviorPointer(sdk.NullInputBehaviorCalledOnNullInput)). + WithTargetPath(&target). + WithFunctionDefinition(&definition) + err := client.Functions.CreateForJava(ctx, request) require.NoError(t, err) t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{"VARCHAR"})) - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest()) + function, err := client.Functions.ShowByID(ctx, id) require.NoError(t, err) - require.Equal(t, 1, len(functions)) + require.Equal(t, id.Name(), function.Name) + require.Equal(t, "JAVA", function.Language) }) t.Run("create function for Javascript", func(t *testing.T) { name := "js_factorial" - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) definition := ` - if (D <= 0) { - return 1; - } else { - var result = 1; - for (var i = 2; i <= D; i++) { - result = result * i; - } - return result; - } - ` - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeFloat) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("d").WithArgDataType(sdk.DataTypeFloat) - request := sdk.NewCreateFunctionForJavascriptFunctionRequest(id, returnsRequest, definition). +if (D <= 0) { + return 1; +} else { + var result = 1; + for (var i = 2; i <= D; i++) { + result = result * i; + } + return result; +}` + + dt := sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeFloat) + returns := sdk.NewFunctionReturnsRequest().WithResultDataType(dt) + argument := sdk.NewFunctionArgumentRequest("d", sdk.DataTypeFloat) + request := sdk.NewCreateForJavascriptFunctionRequest(id, *returns, &definition). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}). - WithNullInputBehavior(sdk.FunctionNullInputBehaviorCalledOnNullInput) - err := client.Functions.CreateFunctionForJavascript(ctx, request) + WithArguments([]sdk.FunctionArgumentRequest{*argument}). + WithNullInputBehavior(sdk.NullInputBehaviorPointer(sdk.NullInputBehaviorCalledOnNullInput)) + err := client.Functions.CreateForJavascript(ctx, request) require.NoError(t, err) t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeFloat})) - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest()) + function, err := client.Functions.ShowByID(ctx, id) require.NoError(t, err) - require.Equal(t, 1, len(functions)) + require.Equal(t, id.Name(), function.Name) + require.Equal(t, "JAVASCRIPT", function.Language) }) t.Run("create function for Python", func(t *testing.T) { name := random.StringN(8) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) definition := ` def dump(i): - print("Hello World!") - ` - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeVariant) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("i").WithArgDataType(sdk.DataTypeNumber) - request := sdk.NewCreateFunctionForPythonFunctionRequest(id, returnsRequest, "3.8", "dump", definition). + print("Hello World!")` + dt := sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeVariant) + returns := sdk.NewFunctionReturnsRequest().WithResultDataType(dt) + argument := sdk.NewFunctionArgumentRequest("i", sdk.DataTypeNumber) + request := sdk.NewCreateForPythonFunctionRequest(id, *returns, "3.8", "dump"). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}) - err := client.Functions.CreateFunctionForPython(ctx, request) + WithArguments([]sdk.FunctionArgumentRequest{*argument}). + WithFunctionDefinition(&definition) + err := client.Functions.CreateForPython(ctx, request) require.NoError(t, err) t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{"int"})) - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest()) + function, err := client.Functions.ShowByID(ctx, id) require.NoError(t, err) - require.Equal(t, 1, len(functions)) + require.Equal(t, id.Name(), function.Name) + require.Equal(t, "PYTHON", function.Language) }) t.Run("create function for Scala", func(t *testing.T) { name := "echo_varchar" - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) definition := ` - class Echo { - def echoVarchar(x : String): String = { - return x - } - } - ` - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeVARCHAR) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("x").WithArgDataType(sdk.DataTypeVARCHAR) - request := sdk.NewCreateFunctionForScalaFunctionRequest(id, returnsRequest, "Echo.echoVarchar", definition). +class Echo { + def echoVarchar(x : String): String = { + return x + } +}` + + argument := sdk.NewFunctionArgumentRequest("x", sdk.DataTypeVARCHAR) + request := sdk.NewCreateForScalaFunctionRequest(id, sdk.DataTypeVARCHAR, "Echo.echoVarchar"). WithOrReplace(sdk.Bool(true)). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}). - WithRuntimeVersion(sdk.String("2.12")) - err := client.Functions.CreateFunctionForScala(ctx, request) + WithArguments([]sdk.FunctionArgumentRequest{*argument}). + WithRuntimeVersion(sdk.String("2.12")). + WithFunctionDefinition(&definition) + err := client.Functions.CreateForScala(ctx, request) require.NoError(t, err) - t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{"VARCHAR"})) + t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeVARCHAR})) - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest()) + function, err := client.Functions.ShowByID(ctx, id) require.NoError(t, err) - require.Equal(t, 1, len(functions)) + require.Equal(t, id.Name(), function.Name) + require.Equal(t, "SCALA", function.Language) }) t.Run("create function for SQL", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) definition := "3.141592654::FLOAT" - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeFloat) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("x").WithArgDataType(sdk.DataTypeFloat) - request := sdk.NewCreateFunctionForSQLFunctionRequest(id, returnsRequest, definition). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}). + + dt := sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeFloat) + returns := sdk.NewFunctionReturnsRequest().WithResultDataType(dt) + argument := sdk.NewFunctionArgumentRequest("x", sdk.DataTypeFloat) + request := sdk.NewCreateForSQLFunctionRequest(id, *returns, &definition). + WithArguments([]sdk.FunctionArgumentRequest{*argument}). WithOrReplace(sdk.Bool(true)). WithComment(sdk.String("comment")) - err := client.Functions.CreateFunctionForSQL(ctx, request) + err := client.Functions.CreateForSQL(ctx, request) require.NoError(t, err) - t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{"FLOAT"})) + t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeFloat})) function, err := client.Functions.ShowByID(ctx, id) require.NoError(t, err) @@ -159,20 +167,41 @@ def dump(i): }) } -func TestInt_AlterAndShowFunctions(t *testing.T) { +func TestInt_OtherFunctions(t *testing.T) { client := testClient(t) - ctx := context.Background() + ctx := testContext(t) - tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + databaseTest, schemaTest := testDb(t), testSchema(t) + tagTest, tagCleanup := createTag(t, client, databaseTest, schemaTest) t.Cleanup(tagCleanup) - cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, argumentTypes []sdk.DataType) func() { + assertFunction := func(t *testing.T, id sdk.SchemaObjectIdentifier, secure bool) { + t.Helper() + + function, err := client.Functions.ShowByID(ctx, id) + require.NoError(t, err) + + assert.NotEmpty(t, function.CreatedOn) + assert.Equal(t, id.Name(), function.Name) + assert.Equal(t, false, function.IsBuiltin) + assert.Equal(t, false, function.IsAggregate) + assert.Equal(t, false, function.IsAnsi) + assert.Equal(t, 1, function.MinNumArguments) + assert.Equal(t, 1, function.MaxNumArguments) + assert.NotEmpty(t, function.Arguments) + assert.NotEmpty(t, function.Description) + assert.NotEmpty(t, function.CatalogName) + assert.Equal(t, false, function.IsTableFunction) + assert.Equal(t, false, function.ValidForClustering) + assert.Equal(t, secure, function.IsSecure) + assert.Equal(t, false, function.IsExternalFunction) + assert.Equal(t, "SQL", function.Language) + assert.Equal(t, false, function.IsMemoizable) + } + + cleanupFunctionHandle := func(id sdk.SchemaObjectIdentifier, dts []sdk.DataType) func() { return func() { - es := []sdk.FunctionArgumentTypeRequest{} - for _, item := range argumentTypes { - es = append(es, *sdk.NewFunctionArgumentTypeRequest().WithArgDataType(item)) - } - err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id).WithArgumentTypes(es)) + err := client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id, dts)) if errors.Is(err, sdk.ErrObjectNotExistOrAuthorized) { return } @@ -182,15 +211,17 @@ func TestInt_AlterAndShowFunctions(t *testing.T) { createFunctionForSQLHandle := func(t *testing.T, cleanup bool) *sdk.Function { t.Helper() + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(4)) definition := "3.141592654::FLOAT" - returnsRequest := sdk.NewFunctionReturnsRequest().WithResultDataType(sdk.DataTypeFloat) - argumentRequest := sdk.NewFunctionArgumentRequest().WithArgName("x").WithArgDataType(sdk.DataTypeFloat) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) - request := sdk.NewCreateFunctionForSQLFunctionRequest(id, returnsRequest, definition). - WithArguments([]sdk.FunctionArgumentRequest{*argumentRequest}). + + dt := sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeFloat) + returns := sdk.NewFunctionReturnsRequest().WithResultDataType(dt) + argument := sdk.NewFunctionArgumentRequest("x", sdk.DataTypeFloat) + request := sdk.NewCreateForSQLFunctionRequest(id, *returns, &definition). + WithArguments([]sdk.FunctionArgumentRequest{*argument}). WithOrReplace(sdk.Bool(true)) - err := client.Functions.CreateFunctionForSQL(ctx, request) + err := client.Functions.CreateForSQL(ctx, request) require.NoError(t, err) if cleanup { t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeFloat})) @@ -200,21 +231,20 @@ func TestInt_AlterAndShowFunctions(t *testing.T) { return function } - defaultArgumentTypes := []sdk.FunctionArgumentTypeRequest{ - *sdk.NewFunctionArgumentTypeRequest().WithArgDataType(sdk.DataTypeFloat), + defaultAlterRequest := func(id sdk.SchemaObjectIdentifier) *sdk.AlterFunctionRequest { + return sdk.NewAlterFunctionRequest(id, []sdk.DataType{sdk.DataTypeFloat}) } t.Run("alter function: rename", func(t *testing.T) { f := createFunctionForSQLHandle(t, false) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - nid := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) - request := sdk.NewAlterFunctionRequest(id).WithRenameTo(&nid).WithArgumentTypes(defaultArgumentTypes) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + nid := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, random.StringN(3)) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithRenameTo(&nid)) if err != nil { - t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{"FLOAT"})) + t.Cleanup(cleanupFunctionHandle(id, []sdk.DataType{sdk.DataTypeFloat})) } else { - t.Cleanup(cleanupFunctionHandle(nid, []sdk.DataType{"FLOAT"})) + t.Cleanup(cleanupFunctionHandle(nid, []sdk.DataType{sdk.DataTypeFloat})) } require.NoError(t, err) @@ -229,111 +259,95 @@ func TestInt_AlterAndShowFunctions(t *testing.T) { t.Run("alter function: set log level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - set := sdk.NewFunctionSetRequest().WithLogLevel(sdk.String("DEBUG")) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetLogLevel(sdk.String("DEBUG"))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: unset log level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - unset := sdk.NewFunctionUnsetRequest().WithLogLevel(sdk.Bool(true)) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnset(unset) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetLogLevel(sdk.Bool(true))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: set trace level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - set := sdk.NewFunctionSetRequest().WithTraceLevel(sdk.String("ALWAYS")) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetTraceLevel(sdk.String("ALWAYS"))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: unset trace level", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - unset := sdk.NewFunctionUnsetRequest().WithTraceLevel(sdk.Bool(true)) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnset(unset) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetTraceLevel(sdk.Bool(true))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: set comment", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - set := sdk.NewFunctionSetRequest().WithComment(sdk.String("comment")) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetComment(sdk.String("test comment"))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: unset comment", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - unset := sdk.NewFunctionUnsetRequest().WithComment(sdk.Bool(true)) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnset(unset) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetComment(sdk.Bool(true))) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("alter function: set secure", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - set := sdk.NewFunctionSetRequest().WithSecure(sdk.Bool(true)) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSet(set) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetSecure(sdk.Bool(true))) require.NoError(t, err) - - e, err := client.Functions.ShowByID(ctx, id) - require.NoError(t, err) - require.Equal(t, true, e.IsSecure) + assertFunction(t, id, true) }) t.Run("alter function: unset secure", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) - unset := sdk.NewFunctionUnsetRequest().WithSecure(sdk.Bool(true)) - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnset(unset) - err := client.Functions.Alter(ctx, request) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetSecure(sdk.Bool(true))) require.NoError(t, err) - - e, err := client.Functions.ShowByID(ctx, id) - require.NoError(t, err) - require.Equal(t, false, e.IsSecure) + assertFunction(t, id, false) }) t.Run("alter function: set and unset tags", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) setTags := []sdk.TagAssociation{ { Name: tagTest.ID(), - Value: "abc", + Value: "v1", }, } - request := sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithSetTags(setTags) - err := client.Functions.Alter(ctx, request) + err := client.Functions.Alter(ctx, defaultAlterRequest(id).WithSetTags(setTags)) require.NoError(t, err) + assertFunction(t, id, false) unsetTags := []sdk.ObjectIdentifier{ tagTest.ID(), } - request = sdk.NewAlterFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes).WithUnsetTags(unsetTags) - err = client.Functions.Alter(ctx, request) + err = client.Functions.Alter(ctx, defaultAlterRequest(id).WithUnsetTags(unsetTags)) require.NoError(t, err) + assertFunction(t, id, false) }) t.Run("show function for SQL: without like", func(t *testing.T) { @@ -352,7 +366,7 @@ func TestInt_AlterAndShowFunctions(t *testing.T) { f1 := createFunctionForSQLHandle(t, true) f2 := createFunctionForSQLHandle(t, true) - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(f1.Name)) + functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(&sdk.Like{Pattern: &f1.Name})) require.NoError(t, err) require.Equal(t, 1, len(functions)) @@ -361,18 +375,25 @@ func TestInt_AlterAndShowFunctions(t *testing.T) { }) t.Run("show function for SQL: no matches", func(t *testing.T) { - functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(random.String())) + functions, err := client.Functions.Show(ctx, sdk.NewShowFunctionRequest().WithLike(&sdk.Like{Pattern: sdk.String(random.String())})) require.NoError(t, err) require.Equal(t, 0, len(functions)) }) t.Run("describe function for SQL", func(t *testing.T) { f := createFunctionForSQLHandle(t, true) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, f.Name) + id := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, f.Name) - request := sdk.NewDescribeFunctionRequest(id).WithArgumentTypes(defaultArgumentTypes) + request := sdk.NewDescribeFunctionRequest(id, []sdk.DataType{sdk.DataTypeFloat}) details, err := client.Functions.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, "FLOAT", pairs["returns"]) + require.Equal(t, "3.141592654::FLOAT", pairs["body"]) + require.Equal(t, "(X FLOAT)", pairs["signature"]) }) }