-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add default_value under arguments #8209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d895b9e
Add default_value under arguments
luna-bianca efc1e74
Update udfs.md
luna-bianca 4e0c0f6
Merge branch 'current' into default_value
luna-bianca d0cb2a7
Merge branch 'current' into default_value
mirnawong1 998279d
Merge branch 'current' into default_value
luna-bianca 53d0b57
Add more value types
luna-bianca 0c14cf2
Update website/docs/docs/build/udfs.md
luna-bianca ace9190
Update website/docs/docs/build/udfs.md
luna-bianca 21149e6
Fix spacing
luna-bianca 9e735d1
Fix example and add more info
luna-bianca a05d78d
Merge branch 'current' into default_value
luna-bianca 09ec47b
Merge branch 'current' into default_value
mirnawong1 c9c247c
Update website/docs/reference/resource-properties/function-arguments.md
luna-bianca ceeccda
Update website/docs/reference/resource-properties/function-arguments.md
luna-bianca d07ab57
Apply suggestion from @luna-bianca
luna-bianca fdcd254
Apply suggestion from @luna-bianca
luna-bianca e000846
Add samples of calling the function
luna-bianca b17ac0c
Update function-arguments.md
luna-bianca 9ca79f4
Update function-arguments.md
luna-bianca 6e807a3
Merge branch 'current' into default_value
luna-bianca 21483ae
Merge branch 'current' into default_value
luna-bianca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,13 @@ import ArgumentsShared from '/snippets/_arguments-shared.md'; | |
|
|
||
| ```yml | ||
|
|
||
|
|
||
| functions: | ||
| - name: <function name> | ||
| arguments: | ||
| - name: <arg name> | ||
| data_type: <string> # warehouse-specific | ||
| description: <markdown_string> | ||
| default_value: <string | boolean | integer> # optional, available in Snowflake and Postgres | ||
luna-bianca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
|
|
||
|
|
@@ -55,6 +55,63 @@ Refer to your warehouse documentation for the complete list of supported data ty | |
|
|
||
| An optional markdown string describing the argument. This is helpful for documentation purposes. | ||
|
|
||
| ### default_value | ||
|
|
||
| Use the `default_value` property to make a function argument optional. | ||
| - When an argument isn't defined with a `default_value`, it becomes a required argument, and you must pass a value for them when you use the function. If a required argument isn’t passed, the function call fails. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revised lines 61 and 62 |
||
| - Arguments with a `default_value` are optional — if you don't pass a value for the argument, the warehouse uses the value you set in `default_value`. | ||
|
|
||
| This property is supported in [Snowflake](https://docs.snowflake.com/en/developer-guide/udf-stored-procedure-arguments#designating-an-argument-as-optional) and [Postgres](https://www.postgresql.org/docs/current/sql-createfunction.html). | ||
|
|
||
| When you use `default_value`, the order of your arguments matter. Any required arguments (those without default values) have to come before optional ones. Here's an example with the correct order: | ||
|
|
||
| <File name='functions/schema.yml'> | ||
|
|
||
| ```yml | ||
| functions: | ||
| - name: sum_2_values | ||
| description: Add two values together | ||
| arguments: | ||
| - name: val1 # this argument comes first because it has no default value | ||
| data_type: integer | ||
| description: The first value | ||
| - name: val2 | ||
| data_type: integer | ||
| description: The second value | ||
| default_value: 0 | ||
| returns: | ||
| data_type: integer | ||
| ``` | ||
| </File> | ||
|
|
||
| In this example: | ||
luna-bianca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - `val1` has no `default_value`, so it’s required. | ||
| - `val2` has a `default_value` of `0`, so it’s optional. If you don’t provide a value for `val2`, the function uses `0` instead. | ||
|
|
||
| See the following examples of calling the `sum_2_values` function in SQL and Python: | ||
|
||
|
|
||
| <Tabs> | ||
|
|
||
| <TabItem value="SQL"> | ||
|
|
||
| ```sql | ||
| select sum_2_values(5); -- val1 = 5, val2 = 0 (default used since user didn't specify val2) | ||
| select sum_2_values(5, 10); -- val1 = 5, val2 = 10 | ||
| select sum_2_values(); -- ❌ error: val1 is required and must be passed | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="Python"> | ||
|
|
||
| ```py | ||
| sum_2_values(5) # val1 = 5, val2 = 0 (default used since user didn't specify val2) | ||
| sum_2_values(5, 10) # val1 = 5, val2 = 10 | ||
| sum_2_values() # ❌ error: val1 is required and must be passed | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
luna-bianca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Examples | ||
|
|
||
| ### Simple function arguments | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| The `arguments` property is used to define the parameters that a resource can accept. Each argument can have a `name`, a type field, and an optional `description`. | ||
| The `arguments` property is used to define the parameters that a resource can accept. Each argument can have a `name`, a type field, and optional properties such as `description` and `default_value`. | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also updated the
CREATEstatement for Python