-
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
base: current
Are you sure you want to change the base?
Changes from all commits
d895b9e
efc1e74
4e0c0f6
d0cb2a7
998279d
53d0b57
0c14cf2
ace9190
21149e6
9e735d1
a05d78d
09ec47b
c9c247c
ceeccda
d07ab57
fdcd254
e000846
b17ac0c
9ca79f4
6e807a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,49 @@ 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: | ||
|
|
||
| ```text | ||
| sum_2_values(5) # val1 = 5, val2 = 0 (default value used since user did not specify val2) | ||
| sum_2_values(5, 10) # val1 = 5, val2 = 10 | ||
| sum_2_values() # ❌ error: val1 is required and must be passed | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
|
Contributor
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. i wonder if we should include an example of what 'calling a function' looks like for sql/python:
Contributor
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. The calling of a function should look the same whether the function is using Python or SQL 🙂
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.
Contributor
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. Looks good to me 🙂 |
||
| ## Examples | ||
|
|
||
| ### Simple function arguments | ||
|
|
||
| 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`. | ||
|
|
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