-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Python support for functions (#1069)
* adding python language support and runtime_version attribute * adding packages attribute for python / java * updated function_acceptance_test * testing by adding warehouse attribute * testing by adding warehouse attribute * updating null input and return behaviour * updating test functions * running go fmt * changing runtime_version type from float64 to string * updating function acceptance test * updating function acceptance test * adding sql in the list and updating the description of attributes * updating function acceptance test * minor changes * testing * testing * adding warehouse attribute to the provider config * updating docs and adding examples * fixing conflicts * fixing docs * updating description of warehouse attribute Co-authored-by: Scott Winkler <[email protected]>
- Loading branch information
1 parent
88f4d44
commit bab729a
Showing
13 changed files
with
165 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -19,4 +19,5 @@ provider "snowflake" { | |
// optional | ||
role = "..." | ||
host = "..." | ||
warehouse = "..." | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# format is database name | schema name | function name | <list of arg types, separated with '-'> | ||
terraform import snowflake_function.example 'dbName|schemaName|functionName|varchar-varchar-varchar' |
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Provider configuration | ||
provider "snowflake" { | ||
region = "REGION" // Default is "us-west-2" | ||
username = "USERNAME" | ||
account = "ACCOUNT" | ||
password = "PASSWORD" | ||
role = "MY_ROLE" | ||
warehouse = "MY_WH" // Optional attribute, some resources (e.g. Python UDFs)' require a warehouse to create and can also be set optionally from the `SNOWFLAKE_WAREHOUSE` environment variable | ||
} | ||
|
||
// Create database | ||
resource "snowflake_database" "db" { | ||
name = "MY_DB" | ||
data_retention_days = 1 | ||
} | ||
|
||
// Create schema | ||
resource "snowflake_schema" "schema" { | ||
database = snowflake_database.db.name | ||
name = "MY_SCHEMA" | ||
data_retention_days = 1 | ||
} | ||
|
||
// Example for Java language | ||
resource "snowflake_function" "test_funct_java" { | ||
name = "my_java_func" | ||
database = "MY_DB" | ||
schema = "MY_SCHEMA" | ||
arguments { | ||
name = "arg1" | ||
type = "number" | ||
} | ||
comment = "Example for java language" | ||
return_type = "varchar" | ||
language = "java" | ||
handler = "CoolFunc.test" | ||
statement = "class CoolFunc {public static String test(int n) {return \"hello!\";}}" | ||
} | ||
|
||
// Example for Python language | ||
resource "snowflake_function" "python_test" { | ||
name = "MY_PYTHON_FUNC" | ||
database = "MY_DB" | ||
schema = "MY_SCHEMA" | ||
arguments { | ||
name = "arg1" | ||
type = "number" | ||
} | ||
comment = "Example for Python language" | ||
return_type = "NUMBER(38,0)" | ||
null_input_behavior = "CALLED ON NULL INPUT" | ||
return_behavior = "VOLATILE" | ||
language = "python" | ||
runtime_version = "3.8" | ||
handler = "add_py" | ||
statement = "def add_py(i): return i+1" | ||
} |
This file contains 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,4 +1,4 @@ | ||
resource "snowflake_schema" "db" { | ||
resource "snowflake_database" "db" { | ||
name = "MYDB" | ||
data_retention_days = 1 | ||
} | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -34,26 +34,27 @@ func TestDSN(t *testing.T) { | |
browserAuth bool | ||
region, | ||
role, | ||
host string | ||
host, | ||
warehouse string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{"simple", args{"acct", "user", "pass", false, "region", "role", ""}, | ||
{"simple", args{"acct", "user", "pass", false, "region", "role", "", ""}, | ||
"user:[email protected]:443?ocspFailOpen=true®ion=region&role=role&validateDefaultParameters=true", false}, | ||
{"us-west-2 special case", args{"acct2", "user2", "pass2", false, "us-west-2", "role2", ""}, | ||
{"us-west-2 special case", args{"acct2", "user2", "pass2", false, "us-west-2", "role2", "", ""}, | ||
"user2:[email protected]:443?ocspFailOpen=true&role=role2&validateDefaultParameters=true", false}, | ||
{"customhostwregion", args{"acct3", "user3", "pass3", false, "", "role3", "zha123.us-east-1.privatelink.snowflakecomputing.com"}, | ||
{"customhostwregion", args{"acct3", "user3", "pass3", false, "", "role3", "zha123.us-east-1.privatelink.snowflakecomputing.com", ""}, | ||
"user3:[email protected]:443?account=acct3&ocspFailOpen=true&role=role3&validateDefaultParameters=true", false}, | ||
{"customhostignoreregion", args{"acct4", "user4", "pass4", false, "fakeregion", "role4", "zha1234.us-east-1.privatelink.snowflakecomputing.com"}, | ||
{"customhostignoreregion", args{"acct4", "user4", "pass4", false, "fakeregion", "role4", "zha1234.us-east-1.privatelink.snowflakecomputing.com", ""}, | ||
"user4:[email protected]:443?account=acct4&ocspFailOpen=true&role=role4&validateDefaultParameters=true", false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := provider.DSN(tt.args.account, tt.args.user, tt.args.password, tt.args.browserAuth, "", "", "", "", tt.args.region, tt.args.role, tt.args.host) | ||
got, err := provider.DSN(tt.args.account, tt.args.user, tt.args.password, tt.args.browserAuth, "", "", "", "", tt.args.region, tt.args.role, tt.args.host, tt.args.warehouse) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("DSN() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
|
@@ -89,7 +90,7 @@ func TestOAuthDSN(t *testing.T) { | |
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := provider.DSN(tt.args.account, tt.args.user, "", false, "", "", "", tt.args.oauthAccessToken, tt.args.region, tt.args.role, "") | ||
got, err := provider.DSN(tt.args.account, tt.args.user, "", false, "", "", "", tt.args.oauthAccessToken, tt.args.region, tt.args.role, "", "") | ||
|
||
if (err != nil) != tt.wantErr { | ||
t.Errorf("DSN() error = %v, dsn = %v, wantErr %v", err, got, tt.wantErr) | ||
|
This file contains 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
Oops, something went wrong.