From 9f7cec43f166ff74a4678aaf27d1700c18d761f6 Mon Sep 17 00:00:00 2001 From: Tomasz Wazny Date: Tue, 4 Jun 2024 13:51:26 +0200 Subject: [PATCH 1/3] add OR REPLACE to queries where it was missing in the setup.sql of example connector --- .../app/setup.sql | 4 ++-- .../build.gradle | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/connectors-native-sdk-example-java-github-connector/app/setup.sql b/examples/connectors-native-sdk-example-java-github-connector/app/setup.sql index 7cb7ef6..ee23a71 100644 --- a/examples/connectors-native-sdk-example-java-github-connector/app/setup.sql +++ b/examples/connectors-native-sdk-example-java-github-connector/app/setup.sql @@ -14,7 +14,7 @@ CREATE OR REPLACE STREAMLIT STREAMLIT.EXAMPLE_JAVA_GITHUB_CONNECTOR_ST GRANT USAGE ON STREAMLIT STREAMLIT.EXAMPLE_JAVA_GITHUB_CONNECTOR_ST TO APPLICATION ROLE ADMIN; -- SNOWFLAKE REFERENCE MECHANISM -CREATE PROCEDURE PUBLIC.REGISTER_REFERENCE(ref_name STRING, operation STRING, ref_or_alias STRING) +CREATE OR REPLACE PROCEDURE PUBLIC.REGISTER_REFERENCE(ref_name STRING, operation STRING, ref_or_alias STRING) RETURNS STRING LANGUAGE SQL AS @@ -105,7 +105,7 @@ CALL TASK_REACTOR.CREATE_INSTANCE_OBJECTS( NULL ); -CREATE VIEW EXAMPLE_CONNECTOR_TASK_REACTOR.WORK_SELECTOR_VIEW AS SELECT * FROM EXAMPLE_CONNECTOR_TASK_REACTOR.QUEUE ORDER BY RESOURCE_ID; +CREATE OR REPLACE VIEW EXAMPLE_CONNECTOR_TASK_REACTOR.WORK_SELECTOR_VIEW AS SELECT * FROM EXAMPLE_CONNECTOR_TASK_REACTOR.QUEUE ORDER BY RESOURCE_ID; CREATE OR REPLACE PROCEDURE PUBLIC.RUN_SCHEDULER_ITERATION() RETURNS VARIANT diff --git a/examples/connectors-native-sdk-example-java-github-connector/build.gradle b/examples/connectors-native-sdk-example-java-github-connector/build.gradle index ca9c430..f0dbf17 100644 --- a/examples/connectors-native-sdk-example-java-github-connector/build.gradle +++ b/examples/connectors-native-sdk-example-java-github-connector/build.gradle @@ -201,6 +201,7 @@ private void createNewVersion() { String query = """ALTER APPLICATION PACKAGE ${appPackage} ADD VERSION "${appVersion}" USING '${versionDirPath}';""" + println(query) Process command = new ProcessBuilder(["snowsql", "-c", connection, "-q", query]).redirectErrorStream(true).start() Utils.executeStandardSnowsqlCommand(command) TaskLogger.success("Version [${appVersion}] cretead successfully.") @@ -216,6 +217,7 @@ private void createAppInstance() { def instanceName = getCommandArgument("instanceName", {appPackage+(instanceNameSuffix.isBlank() ? "_INSTANCE" : "_${instanceNameSuffix}")}) String query = createFromAppVersionOrVersionDir(instanceName, appPackage, versionDirPath, appVersion) + println(query) Process command = new ProcessBuilder("snowsql", "-c", connection, "-q", query).redirectErrorStream(true).start() Utils.executeStandardSnowsqlCommand(command) TaskLogger.success("Application instance [${instanceName}] created successfully.") @@ -231,6 +233,7 @@ private String createFromAppVersionOrVersionDir(String instanceName, String appP String createFromAppPackageQuery = """CREATE APPLICATION ${instanceName} FROM APPLICATION PACKAGE ${appPackage} USING ${versionDirPath.orElse("")};""" + println createFromAppPackageQuery String createFromAppVersionQuery = """CREATE APPLICATION ${instanceName} FROM APPLICATION PACKAGE ${appPackage} USING VERSION "${appVersion.orElse("")}";""" From 99305784c69b597cba1ef6683929a493b5a5db8a Mon Sep 17 00:00:00 2001 From: Tomasz Wazny Date: Tue, 4 Jun 2024 13:52:59 +0200 Subject: [PATCH 2/3] add OR REPLACE to queries where it was missing in the setup.sql of template --- templates/connectors-native-sdk-template/app/setup.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/connectors-native-sdk-template/app/setup.sql b/templates/connectors-native-sdk-template/app/setup.sql index cd33f8c..dfbf33a 100644 --- a/templates/connectors-native-sdk-template/app/setup.sql +++ b/templates/connectors-native-sdk-template/app/setup.sql @@ -14,7 +14,7 @@ CREATE OR REPLACE STREAMLIT STREAMLIT.NATIVE_SDK_TEMPLATE_ST GRANT USAGE ON STREAMLIT STREAMLIT.NATIVE_SDK_TEMPLATE_ST TO APPLICATION ROLE ADMIN; -- SNOWFLAKE REFERENCE MECHANISM -CREATE PROCEDURE PUBLIC.REGISTER_REFERENCE(ref_name STRING, operation STRING, ref_or_alias STRING) +CREATE OR REPLACE PROCEDURE PUBLIC.REGISTER_REFERENCE(ref_name STRING, operation STRING, ref_or_alias STRING) RETURNS STRING LANGUAGE SQL AS @@ -100,7 +100,7 @@ CALL TASK_REACTOR.CREATE_INSTANCE_OBJECTS( NULL ); -CREATE VIEW EXAMPLE_CONNECTOR_TASK_REACTOR.WORK_SELECTOR_VIEW AS SELECT * FROM EXAMPLE_CONNECTOR_TASK_REACTOR.QUEUE ORDER BY RESOURCE_ID; +CREATE OR REPLACE VIEW EXAMPLE_CONNECTOR_TASK_REACTOR.WORK_SELECTOR_VIEW AS SELECT * FROM EXAMPLE_CONNECTOR_TASK_REACTOR.QUEUE ORDER BY RESOURCE_ID; CREATE OR REPLACE PROCEDURE PUBLIC.RUN_SCHEDULER_ITERATION() RETURNS VARIANT From 865a3902011226a77cfa78f8bc8cf66d7ecd074a Mon Sep 17 00:00:00 2001 From: Tomasz Wazny Date: Tue, 4 Jun 2024 13:58:12 +0200 Subject: [PATCH 3/3] remove debugging leftovers --- .../build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/connectors-native-sdk-example-java-github-connector/build.gradle b/examples/connectors-native-sdk-example-java-github-connector/build.gradle index f0dbf17..ca9c430 100644 --- a/examples/connectors-native-sdk-example-java-github-connector/build.gradle +++ b/examples/connectors-native-sdk-example-java-github-connector/build.gradle @@ -201,7 +201,6 @@ private void createNewVersion() { String query = """ALTER APPLICATION PACKAGE ${appPackage} ADD VERSION "${appVersion}" USING '${versionDirPath}';""" - println(query) Process command = new ProcessBuilder(["snowsql", "-c", connection, "-q", query]).redirectErrorStream(true).start() Utils.executeStandardSnowsqlCommand(command) TaskLogger.success("Version [${appVersion}] cretead successfully.") @@ -217,7 +216,6 @@ private void createAppInstance() { def instanceName = getCommandArgument("instanceName", {appPackage+(instanceNameSuffix.isBlank() ? "_INSTANCE" : "_${instanceNameSuffix}")}) String query = createFromAppVersionOrVersionDir(instanceName, appPackage, versionDirPath, appVersion) - println(query) Process command = new ProcessBuilder("snowsql", "-c", connection, "-q", query).redirectErrorStream(true).start() Utils.executeStandardSnowsqlCommand(command) TaskLogger.success("Application instance [${instanceName}] created successfully.") @@ -233,7 +231,6 @@ private String createFromAppVersionOrVersionDir(String instanceName, String appP String createFromAppPackageQuery = """CREATE APPLICATION ${instanceName} FROM APPLICATION PACKAGE ${appPackage} USING ${versionDirPath.orElse("")};""" - println createFromAppPackageQuery String createFromAppVersionQuery = """CREATE APPLICATION ${instanceName} FROM APPLICATION PACKAGE ${appPackage} USING VERSION "${appVersion.orElse("")}";"""