mirror of
https://github.com/enso-org/enso.git
synced 2025-01-03 14:04:44 +03:00
Data link for Snowflake. (#9514)
Adding in Snowflake into the Datalink APIs. ![image](https://github.com/enso-org/enso/assets/4699705/32bd347c-0b2b-47b5-bec2-5c939ecd0594)
This commit is contained in:
parent
aff7fb86e8
commit
283c0b61d9
@ -6,7 +6,8 @@
|
||||
"anyOf": [
|
||||
{ "$ref": "#/$defs/S3DataLink" },
|
||||
{ "$ref": "#/$defs/HttpFetchDataLink" },
|
||||
{ "$ref": "#/$defs/PostgresDataLink" }
|
||||
{ "$ref": "#/$defs/PostgresDataLink" },
|
||||
{ "$ref": "#/$defs/SnowflakeDataLink" }
|
||||
],
|
||||
"$comment": "The fields `type` and `libraryName` are required for all data link types, but we currently don't add a top-level `required` setting to the schema, because it was confusing the code that is generating the modal."
|
||||
},
|
||||
@ -175,6 +176,57 @@
|
||||
},
|
||||
"required": ["type", "libraryName", "host", "port", "database_name"]
|
||||
},
|
||||
"SnowflakeDataLink": {
|
||||
"title": "Snowflake Database Connection",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"title": "Type",
|
||||
"const": "Snowflake_Connection",
|
||||
"type": "string"
|
||||
},
|
||||
"libraryName": { "const": "Standard.Snowflake" },
|
||||
"account": {
|
||||
"title": "Account",
|
||||
"type": "string"
|
||||
},
|
||||
"database_name": {
|
||||
"title": "Database Name",
|
||||
"type": "string"
|
||||
},
|
||||
"schema": {
|
||||
"title": "Schema",
|
||||
"type": "string"
|
||||
},
|
||||
"warehouse": {
|
||||
"title": "Warehouse",
|
||||
"type": "string"
|
||||
},
|
||||
"credentials": {
|
||||
"title": "Credentials",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {
|
||||
"title": "Username",
|
||||
"$ref": "#/$defs/SecureValue"
|
||||
},
|
||||
"password": {
|
||||
"title": "Password",
|
||||
"$ref": "#/$defs/SecureValue"
|
||||
}
|
||||
},
|
||||
"required": ["username", "password"]
|
||||
},
|
||||
"table": { "title": "Table to access", "type": "string" }
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"libraryName",
|
||||
"account",
|
||||
"database_name",
|
||||
"credentials"
|
||||
]
|
||||
},
|
||||
|
||||
"Format": {
|
||||
"title": "Format",
|
||||
|
@ -1,7 +1,10 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Widget_Helpers import make_text_secret_selector
|
||||
|
||||
type Credentials
|
||||
## Simple username and password type.
|
||||
@username make_text_secret_selector
|
||||
@password make_text_secret_selector
|
||||
Username_And_Password username:(Text|Enso_Secret) password:(Text|Enso_Secret)
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1,3 +1,5 @@
|
||||
private
|
||||
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Metadata.Display
|
||||
from Standard.Base.Metadata.Choice import Option
|
||||
|
@ -1,3 +1,5 @@
|
||||
private
|
||||
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Database.Internal.Postgres.Postgres_Dialect import make_internal_generator_dialect, Postgres_Dialect
|
||||
|
@ -0,0 +1,47 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Enso_Cloud.Data_Link import parse_secure_value
|
||||
from Standard.Base.Enso_Cloud.Public_Utils import get_optional_field, get_required_field
|
||||
|
||||
import Standard.Database.Connection.Connection_Options.Connection_Options
|
||||
import Standard.Database.Connection.Credentials.Credentials
|
||||
|
||||
import project.Snowflake_Details.Snowflake_Details
|
||||
|
||||
## PRIVATE
|
||||
type Snowflake_Data_Link
|
||||
## PRIVATE
|
||||
A data-link returning a connection to the specified database.
|
||||
Connection details:Snowflake_Details
|
||||
|
||||
## PRIVATE
|
||||
A data-link returning a query to a specific table within a database.
|
||||
Table name:Text details:Snowflake_Details
|
||||
|
||||
## PRIVATE
|
||||
parse json -> Snowflake_Data_Link =
|
||||
account = get_required_field "account" json expected_type=Text
|
||||
db_name = get_required_field "database_name" json expected_type=Text
|
||||
schema = get_optional_field "schema" json if_missing="SNOWFLAKE" expected_type=Text
|
||||
warehouse = get_optional_field "warehouse" json if_missing="" expected_type=Text
|
||||
|
||||
credentials_json = get_required_field "credentials" json
|
||||
username = get_required_field "username" credentials_json |> parse_secure_value
|
||||
password = get_required_field "password" credentials_json |> parse_secure_value
|
||||
credentials = Credentials.Username_And_Password username password
|
||||
|
||||
details = Snowflake_Details.Snowflake account=account database=db_name schema=schema warehouse=warehouse credentials=credentials
|
||||
case get_optional_field "table" json expected_type=Text of
|
||||
Nothing ->
|
||||
Snowflake_Data_Link.Connection details
|
||||
table_name : Text ->
|
||||
Snowflake_Data_Link.Table table_name details
|
||||
|
||||
## PRIVATE
|
||||
read self (on_problems : Problem_Behavior) =
|
||||
_ = on_problems
|
||||
default_options = Connection_Options.Value
|
||||
connection = self.details.connect default_options
|
||||
case self of
|
||||
Snowflake_Data_Link.Connection _ -> connection
|
||||
Snowflake_Data_Link.Table table_name _ ->
|
||||
connection.query table_name
|
@ -0,0 +1,21 @@
|
||||
package org.enso.snowflake;
|
||||
|
||||
import org.enso.base.enso_cloud.DataLinkSPI;
|
||||
|
||||
@org.openide.util.lookup.ServiceProvider(service = DataLinkSPI.class)
|
||||
public class SnowflakeDataLinkSPI extends DataLinkSPI {
|
||||
@Override
|
||||
protected String getModuleName() {
|
||||
return "Standard.Snowflake.Snowflake_Data_Link";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTypeName() {
|
||||
return "Snowflake_Data_Link";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLinkTypeName() {
|
||||
return "Snowflake_Connection";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user