From 932e1ad5d906b3431ccd888bcb6b5ab9c4087113 Mon Sep 17 00:00:00 2001 From: Vincent de Saboulin Date: Fri, 25 Oct 2024 11:42:50 +0200 Subject: [PATCH] fix --- .../jdbc-snowflake-source.sh | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/connect/connect-jdbc-snowflake-source/jdbc-snowflake-source.sh b/connect/connect-jdbc-snowflake-source/jdbc-snowflake-source.sh index b3ef40761..d7a0163f4 100755 --- a/connect/connect-jdbc-snowflake-source/jdbc-snowflake-source.sh +++ b/connect/connect-jdbc-snowflake-source/jdbc-snowflake-source.sh @@ -83,6 +83,7 @@ log "Create a Snowflake DB" docker run --quiet --rm -i -e SNOWSQL_PWD="$SNOWFLAKE_PASSWORD" -e RSA_PUBLIC_KEY="$RSA_PUBLIC_KEY" kurron/snowsql --username $SNOWFLAKE_USERNAME -a $SNOWFLAKE_ACCOUNT_NAME << EOF DROP DATABASE IF EXISTS $PLAYGROUND_DB; CREATE OR REPLACE DATABASE $PLAYGROUND_DB COMMENT = 'Database for Docker Playground'; +CREATE SCHEMA MYSCHEMA; EOF log "Create a Snowflake ROLE" @@ -92,12 +93,14 @@ DROP ROLE IF EXISTS $PLAYGROUND_CONNECTOR_ROLE; CREATE ROLE $PLAYGROUND_CONNECTOR_ROLE; GRANT USAGE ON DATABASE $PLAYGROUND_DB TO ROLE $PLAYGROUND_CONNECTOR_ROLE; GRANT USAGE ON DATABASE $PLAYGROUND_DB TO ACCOUNTADMIN; -GRANT USAGE ON SCHEMA $PLAYGROUND_DB.PUBLIC TO ROLE $PLAYGROUND_CONNECTOR_ROLE; -GRANT ALL ON FUTURE TABLES IN SCHEMA $PLAYGROUND_DB.PUBLIC TO $PLAYGROUND_CONNECTOR_ROLE; -GRANT USAGE ON SCHEMA $PLAYGROUND_DB.PUBLIC TO ROLE ACCOUNTADMIN; -GRANT CREATE TABLE ON SCHEMA $PLAYGROUND_DB.PUBLIC TO ROLE $PLAYGROUND_CONNECTOR_ROLE; -GRANT CREATE STAGE ON SCHEMA $PLAYGROUND_DB.PUBLIC TO ROLE $PLAYGROUND_CONNECTOR_ROLE; -GRANT CREATE PIPE ON SCHEMA $PLAYGROUND_DB.PUBLIC TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT USAGE ON SCHEMA $PLAYGROUND_DB.MYSCHEMA TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT ALL ON FUTURE TABLES IN SCHEMA $PLAYGROUND_DB.MYSCHEMA TO $PLAYGROUND_CONNECTOR_ROLE; +GRANT USAGE ON SCHEMA $PLAYGROUND_DB.MYSCHEMA TO ROLE ACCOUNTADMIN; +GRANT CREATE TABLE ON SCHEMA $PLAYGROUND_DB.MYSCHEMA TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT CREATE STAGE ON SCHEMA $PLAYGROUND_DB.MYSCHEMA TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT CREATE PIPE ON SCHEMA $PLAYGROUND_DB.MYSCHEMA TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT ALL ON ALL SCHEMAS IN DATABASE $PLAYGROUND_DB TO ROLE $PLAYGROUND_CONNECTOR_ROLE; +GRANT ALL ON FUTURE SCHEMAS IN DATABASE $PLAYGROUND_DB TO ROLE $PLAYGROUND_CONNECTOR_ROLE; GRANT ROLE $PLAYGROUND_CONNECTOR_ROLE TO ROLE ACCOUNTADMIN; EOF @@ -140,7 +143,7 @@ log "Create table foo" docker run --quiet --rm -i -e SNOWSQL_PWD="$SNOWFLAKE_PASSWORD" -e RSA_PUBLIC_KEY="$RSA_PUBLIC_KEY" kurron/snowsql --username $SNOWFLAKE_USERNAME -a $SNOWFLAKE_ACCOUNT_NAME << EOF USE ROLE $PLAYGROUND_CONNECTOR_ROLE; USE DATABASE $PLAYGROUND_DB; -USE SCHEMA PUBLIC; +USE SCHEMA MYSCHEMA; USE WAREHOUSE $PLAYGROUND_WAREHOUSE; create or replace sequence seq1; create or replace table FOO (id number default seq1.nextval, f1 string, update_ts timestamp default current_timestamp()); @@ -153,19 +156,19 @@ log "Create a view MYVIEWFORFOO" docker run --quiet --rm -i -e SNOWSQL_PWD="$SNOWFLAKE_PASSWORD" -e RSA_PUBLIC_KEY="$RSA_PUBLIC_KEY" kurron/snowsql --username $SNOWFLAKE_USERNAME -a $SNOWFLAKE_ACCOUNT_NAME << EOF USE ROLE $PLAYGROUND_CONNECTOR_ROLE; USE DATABASE $PLAYGROUND_DB; -USE SCHEMA PUBLIC; +USE SCHEMA MYSCHEMA; USE WAREHOUSE $PLAYGROUND_WAREHOUSE; create or replace view MYVIEWFORFOO as select id,f1, convert_timezone('UTC', update_ts) as update_ts from FOO; EOF docker run --quiet --rm -i -e SNOWSQL_PWD="$SNOWFLAKE_PASSWORD" -e RSA_PUBLIC_KEY="$RSA_PUBLIC_KEY" kurron/snowsql --username $SNOWFLAKE_USERNAME -a $SNOWFLAKE_ACCOUNT_NAME << EOF USE ROLE SECURITYADMIN; -grant select on view $PLAYGROUND_DB.PUBLIC.MYVIEWFORFOO to role $PLAYGROUND_CONNECTOR_ROLE; +grant select on view $PLAYGROUND_DB.MYSCHEMA.MYVIEWFORFOO to role $PLAYGROUND_CONNECTOR_ROLE; EOF # https://docs.snowflake.com/en/user-guide/jdbc-configure.html#jdbc-driver-connection-string -CONNECTION_URL="jdbc:snowflake://$SNOWFLAKE_ACCOUNT_NAME.snowflakecomputing.com/?warehouse=$PLAYGROUND_WAREHOUSE&db=$PLAYGROUND_DB&role=$PLAYGROUND_CONNECTOR_ROLE&schema=PUBLIC&user=$PLAYGROUND_USER&private_key_file=/tmp/snowflake_key.p8&private_key_file_pwd=confluent&tracing=ALL" -VIEW="$PLAYGROUND_DB.PUBLIC.MYVIEWFORFOO" +CONNECTION_URL="jdbc:snowflake://$SNOWFLAKE_ACCOUNT_NAME.snowflakecomputing.com/?warehouse=$PLAYGROUND_WAREHOUSE&db=$PLAYGROUND_DB&role=$PLAYGROUND_CONNECTOR_ROLE&schema=MYSCHEMA&user=$PLAYGROUND_USER&private_key_file=/tmp/snowflake_key.p8&private_key_file_pwd=confluent&tracing=ALL" +VIEW="$PLAYGROUND_DB.MYSCHEMA.MYVIEWFORFOO" log "Creating JDBC Snowflake Source connector" playground connector create-or-update --connector jdbc-snowflake-source << EOF