Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Dec 10, 2024
1 parent 37b723b commit bfa01db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pkg/resources/function_commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func setUpFunctionSchema(definition functionSchemaDef) map[string]*schema.Schema
}
if v, ok := currentSchema["runtime_version"]; ok && v != nil {
if definition.runtimeVersionRequired {
v.Optional = false
v.Required = true
} else {
v.Optional = true
Expand Down Expand Up @@ -156,7 +155,7 @@ var (
)

// TODO [SNOW-1348103]: add null/not null
// TODO [SNOW-1348103]: currently all database.schema.name are ForceNew but based on the docs it is possible to rename with moving to different db/schema
// TODO [SNOW-1348103]: currently database and schema are ForceNew but based on the docs it is possible to rename with moving to different db/schema
// TODO [SNOW-1348103]: copyGrants and orReplace logic omitted for now, will be added to the limitations docs
// TODO [SNOW-1348103]: temporary is not supported because it creates a per-session object; add to limitations/design decisions
var functionBaseSchema = map[string]schema.Schema{
Expand All @@ -177,7 +176,6 @@ var functionBaseSchema = map[string]schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: blocklistedCharactersFieldDescription("The name of the function; the identifier does not need to be unique for the schema in which the function is created because UDFs are identified and resolved by the combination of the name and argument types. Check the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#all-languages)."),
DiffSuppressFunc: suppressIdentifierQuoting,
},
Expand Down Expand Up @@ -207,11 +205,13 @@ var functionBaseSchema = map[string]schema.Schema{
// TODO [SNOW-1348103]: adjust diff suppression accordingly.
Description: "The argument name.",
},
// TODO [SNOW-1348103]: after testing weird names add limitations to the docs and add validation here
"arg_data_type": {
Type: schema.TypeString,
Required: true,
// TODO [SNOW-1348103]: adjust diff suppression accordingly.
Description: "The argument type.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: IsDataTypeValid,
DiffSuppressFunc: DiffSuppressDataTypes,
Description: "The argument type.",
},
},
},
Expand All @@ -221,10 +221,12 @@ var functionBaseSchema = map[string]schema.Schema{
},
// TODO [SNOW-1348103]: for now, the proposal is to leave return type as string, add TABLE to data types, and here always parse (easier handling and diff suppression)
"return_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Specifies the results returned by the UDF, which determines the UDF type. Use `<result_data_type>` to create a scalar UDF that returns a single value with the specified data type. Use `TABLE (col_name col_data_type, ...)` to creates a table UDF that returns tabular results with the specified table column(s) and column type(s). For the details, consult the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#all-languages).",
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: IsDataTypeValid,
DiffSuppressFunc: DiffSuppressDataTypes,
Description: "Specifies the results returned by the UDF, which determines the UDF type. Use `<result_data_type>` to create a scalar UDF that returns a single value with the specified data type. Use `TABLE (col_name col_data_type, ...)` to creates a table UDF that returns tabular results with the specified table column(s) and column type(s). For the details, consult the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#all-languages).",
// TODO [SNOW-1348103]: adjust DiffSuppressFunc
},
"null_input_behavior": {
Expand All @@ -245,7 +247,6 @@ var functionBaseSchema = map[string]schema.Schema{
},
"runtime_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
// TODO [SNOW-1348103]: may be optional for java without consequence because if it is not set, the describe is not returning any version.
},
Expand Down Expand Up @@ -275,6 +276,7 @@ var functionBaseSchema = map[string]schema.Schema{
Required: true,
ForceNew: true,
},
// TODO [SNOW-1348103]: use suppress from network policies when adding logic
"external_access_integrations": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Expand Down Expand Up @@ -305,6 +307,7 @@ var functionBaseSchema = map[string]schema.Schema{
},
Description: "Assigns the names of secrets to variables so that you can use the variables to reference the secrets when retrieving information from secrets in handler code. Secrets you specify here must be allowed by the [external access integration](https://docs.snowflake.com/en/sql-reference/sql/create-external-access-integration) specified as a value of this CREATE FUNCTION command’s EXTERNAL_ACCESS_INTEGRATIONS parameter.",
},
// TODO [SNOW-1348103]: because of https://docs.snowflake.com/en/sql-reference/sql/create-function#id6, maybe it will be better to split into stage + path
"target_path": {
Type: schema.TypeString,
Optional: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/testint/functions_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// TODO [SNOW-1348103]: python aggregate func (100357 (P0000): Could not find accumulate method in function CVVEMHIT_06547800_08D6_DBCA_1AC7_5E422AFF8B39 with handler dump)
// TODO [SNOW-1348103]: add a test documenting that we can't set parameters in create (and revert adding these parameters directly in object...)
// TODO [SNOW-1850370]: active warehouse vs validations
// TODO [SNOW-1348103]: add a test documenting STRICT behavior
func TestInt_Functions(t *testing.T) {
client := testClient(t)
ctx := context.Background()
Expand Down

0 comments on commit bfa01db

Please sign in to comment.