Skip to content

Commit

Permalink
added requested changes: fixed example input_param fields, minor fixe…
Browse files Browse the repository at this point in the history
…s at the resource level
  • Loading branch information
dgomez04 committed Dec 23, 2024
1 parent 7672d40 commit bb51da2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 54 deletions.
45 changes: 24 additions & 21 deletions docs/resources/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ resource "databricks_function" "calculate_bmi" {
name = "calculate_bmi"
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.functions.name
input_params = [
{
name = "weight"
type = "DOUBLE"
},
{
name = "height"
type = "DOUBLE"
}
]
input_params = {
parameters = [
{
name = "weight"
type_name = "DOUBLE"
},
{
name = "height"
type_name = "DOUBLE"
}
]
}
data_type = "DOUBLE"
routine_body = "SQL"
routine_definition = "weight / (height * height)"
language = "SQL"
is_deterministic = true
sql_data_access = "CONTAINS_SQL"
security_type = "DEFINER"
Expand All @@ -54,16 +55,18 @@ resource "databricks_function" "calculate_bmi_py" {
name = "calculate_bmi_py"
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.functions.name
input_params = [
{
name = "weight_kg"
type = "DOUBLE"
},
{
name = "height_m"
type = "DOUBLE"
}
]
input_params = {
parameters = [
{
name = "weight_kg"
type = "DOUBLE"
},
{
name = "height_m"
type = "DOUBLE"
}
]
}
data_type = "DOUBLE"
routine_body = "EXTERNAL"
routine_definition = "return weight_kg / (height_m ** 2)"
Expand Down
3 changes: 1 addition & 2 deletions internal/providers/pluginfw/pluginfw_rollout_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ var migratedDataSources = []func() datasource.DataSource{
// Keep this list sorted.
var pluginFwOnlyResources = []func() resource.Resource{
// TODO Add resources here
sharing.ResourceShare, // Using the staging name (with pluginframework suffix)
catalog.ResourceFunction,
app.ResourceApp,
catalog.ResourceFunction,
sharing.ResourceShare,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func (r *FunctionResource) Metadata(ctx context.Context, req resource.MetadataRe
}

func (r *FunctionResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
attrs, blocks := tfschema.ResourceStructToSchemaMap(catalog_tf.FunctionInfo{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
c.ToNestedBlockObject()

attrs, blocks := tfschema.ResourceStructToSchemaMap(ctx, catalog_tf.FunctionInfo{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
c.SetRequired("name")
c.SetRequired("catalog_name")
c.SetRequired("schema_name")
Expand Down Expand Up @@ -163,7 +161,7 @@ func (r *FunctionResource) Read(ctx context.Context, req resource.ReadRequest, r
return
}

funcName := stateFunc.Name.ValueString()
funcName := stateFunc.FullName.ValueString()

funcInfo, err := w.Functions.GetByName(ctx, funcName)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ func TestFunctionResource(t *testing.T) {
}
resource "databricks_schema" "functions" {
catalog_name = databricks_catalog.sandbox.id
catalog_name = databricks_catalog.sandbox.name
name = "functions-${var.STICKY_RANDOM}"
}
resource "databricks_function" "function" {
name = "function-${var.STICKY_RANDOM}"
catalog_name = databricks_catalog.sandbox.id
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.functions.name
input_params = [
{
name = "weight"
type = "DOUBLE"
},
{
name = "height"
type = "DOUBLE"
}
]
input_params = {
parameters = [
{
name = "weight"
type = "DOUBLE"
},
{
name = "height"
type = "DOUBLE"
}
]
}
data_type = "DOUBLE"
routine_body = "SQL"
routine_defintion = "weight / (height * height)"
Expand All @@ -76,22 +78,24 @@ func TestFunctionResource(t *testing.T) {
resource "databricks_function" "function" {
name = "function-${var.STICKY_RANDOM}"
catalog_name = databricks_catalog.sandbox.id
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.functions.name
input_params = [
{
name = "weight"
type = "DOUBLE"
},
{
name = "height"
type = "DOUBLE"
},
{
name = "age"
type = "INT"
}
]
input_params = {
parameters = [
{
name = "weight"
type = "DOUBLE"
},
{
name = "height"
type = "DOUBLE"
},
{
name = "age"
type = "INT"
}
]
}
data_type = "DOUBLE"
routine_body = "SQL"
routine_defintion = "weight / (height * height) + age / 100"
Expand Down

0 comments on commit bb51da2

Please sign in to comment.