diff --git a/app/ide-desktop/lib/dashboard/src/data/dataLinkSchema.json b/app/ide-desktop/lib/dashboard/src/data/dataLinkSchema.json index c263a823579..1a4727e2577 100644 --- a/app/ide-desktop/lib/dashboard/src/data/dataLinkSchema.json +++ b/app/ide-desktop/lib/dashboard/src/data/dataLinkSchema.json @@ -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", diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Credentials.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Credentials.enso index 2b0f81ac04f..9579a912624 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Credentials.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Credentials.enso @@ -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 diff --git a/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Connection.enso b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Connection.enso index 76b531fc881..0898c9e8b24 100644 --- a/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Connection.enso +++ b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Connection.enso @@ -1,3 +1,5 @@ +private + from Standard.Base import all import Standard.Base.Metadata.Display from Standard.Base.Metadata.Choice import Option diff --git a/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Dialect.enso b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Dialect.enso index ce5aee424ca..ec2c444201b 100644 --- a/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Dialect.enso +++ b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Internal/Snowflake_Dialect.enso @@ -1,3 +1,5 @@ +private + from Standard.Base import all from Standard.Database.Internal.Postgres.Postgres_Dialect import make_internal_generator_dialect, Postgres_Dialect diff --git a/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Snowflake_Data_Link.enso b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Snowflake_Data_Link.enso new file mode 100644 index 00000000000..50633624acc --- /dev/null +++ b/distribution/lib/Standard/Snowflake/0.0.0-dev/src/Snowflake_Data_Link.enso @@ -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 diff --git a/std-bits/snowflake/src/main/java/org/enso/snowflake/SnowflakeDataLinkSPI.java b/std-bits/snowflake/src/main/java/org/enso/snowflake/SnowflakeDataLinkSPI.java new file mode 100644 index 00000000000..629857bf3aa --- /dev/null +++ b/std-bits/snowflake/src/main/java/org/enso/snowflake/SnowflakeDataLinkSPI.java @@ -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"; + } +}