Skip to content

🐛 Snowflake destination: do not create schema if it exists - #9311

Merged
oneshcheret (sashaNeshcheret) merged 7 commits into
masterfrom
omneshcheret/6005-snowflake-do-not-create-schema-if-exists
Jan 10, 2022
Merged

oneshcheret (sashaNeshcheret) merged 7 commits into
masterfrom
omneshcheret/6005-snowflake-do-not-create-schema-if-exists

Conversation

@sashaNeshcheret

@sashaNeshcheret oneshcheret (sashaNeshcheret) commented Jan 5, 2022 •

Copy link
Copy Markdown
Contributor

What

Allow Airbyte to write to the existing Snowflake Schema without database ownership

How

We need to check whether schema already exist before trying to create it. Fix is applicable for all snowflake insert methods

Recommended reading order

  1. x.java

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@github-actions github-actions Bot added the area/connectors Connector related issues label Jan 5, 2022
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 5, 2022 •

Copy link
Copy Markdown
Contributor Author

/test connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1658312071
✅ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1658312071
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                              Stmts   Miss  Cover
	 -------------------------------------------------------------------------------------
	 main_dev_transform_catalog.py                                         3      3     0%
	 main_dev_transform_config.py                                          3      3     0%
	 normalization/__init__.py                                             4      0   100%
	 normalization/destination_type.py                                    13      0   100%
	 normalization/transform_catalog/__init__.py                           2      0   100%
	 normalization/transform_catalog/catalog_processor.py                143     77    46%
	 normalization/transform_catalog/destination_name_transformer.py     124      6    95%
	 normalization/transform_catalog/reserved_keywords.py                 13      0   100%
	 normalization/transform_catalog/stream_processor.py                 494    313    37%
	 normalization/transform_catalog/table_name_registry.py              174     34    80%
	 normalization/transform_catalog/transform.py                         45     26    42%
	 normalization/transform_catalog/utils.py                             33      7    79%
	 normalization/transform_config/__init__.py                            2      0   100%
	 normalization/transform_config/transform.py                         146     32    78%
	 -------------------------------------------------------------------------------------
	 TOTAL                                                              1199    501    58%

@etsybaev Eugene (etsybaev) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please do not forget to update the changelog, bump versions and release new images
  2. Pass all PR's checklists
  3. Is there any way to create a test for it?
    Thanks

@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 5, 2022 12:25 Inactive
@sashaNeshcheret

Copy link
Copy Markdown
Contributor Author
  1. Please do not forget to update the changelog, bump versions and release new images
  2. Pass all PR's checklists
  3. Is there any way to create a test for it?
    Thanks

Unfortunately we cannot add test for this case, i found two case: first is create user with usage permissions on database level, but we cannot do it with integration test user, do not have enough privileges for it. Second way is to revoke 'create schema' privileges from integration test user, run check and than grant it again, we can do revoking, but for grant we need ownership privileges, but it can be granted only to one role.

@alexandr-shegeda

Copy link
Copy Markdown
Contributor

we can proceed with publish and merge without airbyte review

@github-actions github-actions Bot added the area/documentation Improvements or additions to documentation label Jan 6, 2022
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 6, 2022 •

Copy link
Copy Markdown
Contributor Author

/test connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1663183676
✅ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1663183676
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                              Stmts   Miss  Cover
	 -------------------------------------------------------------------------------------
	 main_dev_transform_catalog.py                                         3      3     0%
	 main_dev_transform_config.py                                          3      3     0%
	 normalization/__init__.py                                             4      0   100%
	 normalization/destination_type.py                                    13      0   100%
	 normalization/transform_catalog/__init__.py                           2      0   100%
	 normalization/transform_catalog/catalog_processor.py                143     77    46%
	 normalization/transform_catalog/destination_name_transformer.py     124      6    95%
	 normalization/transform_catalog/reserved_keywords.py                 13      0   100%
	 normalization/transform_catalog/stream_processor.py                 502    321    36%
	 normalization/transform_catalog/table_name_registry.py              174     34    80%
	 normalization/transform_catalog/transform.py                         45     26    42%
	 normalization/transform_catalog/utils.py                             33      7    79%
	 normalization/transform_config/__init__.py                            2      0   100%
	 normalization/transform_config/transform.py                         146     32    78%
	 -------------------------------------------------------------------------------------
	 TOTAL                                                              1207    509    58%

@sashaNeshcheret
oneshcheret (sashaNeshcheret) temporarily deployed to more-secrets January 6, 2022 13:28 Inactive
@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 6, 2022 13:29 Inactive
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 6, 2022 •

Copy link
Copy Markdown
Contributor Author

/publish connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1663630977
❌ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1663630977

@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 6, 2022 15:28 Inactive
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 6, 2022 •

Copy link
Copy Markdown
Contributor Author

/publish connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664002931
✅ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664002931

@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 6, 2022 17:05 Inactive
…nowflake-do-not-create-schema-if-exists

# Conflicts:
#	airbyte-config/init/src/main/resources/seed/destination_definitions.yaml
#	airbyte-integrations/connectors/destination-snowflake/Dockerfile
#	docs/integrations/destinations/snowflake.md
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 6, 2022 •

Copy link
Copy Markdown
Contributor Author

/test connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664487869
❌ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664487869
🐛

@sashaNeshcheret
oneshcheret (sashaNeshcheret) temporarily deployed to more-secrets January 6, 2022 19:11 Inactive
@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 6, 2022 19:12 Inactive
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 6, 2022 •

Copy link
Copy Markdown
Contributor Author

/test connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664653570
❌ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1664653570
🐛

@jrhizor
Jared Rhizor (jrhizor) temporarily deployed to more-secrets January 6, 2022 20:02 Inactive
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 10, 2022 •

Copy link
Copy Markdown
Contributor Author

/test connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1676572545
✅ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1676572545
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                              Stmts   Miss  Cover
	 -------------------------------------------------------------------------------------
	 main_dev_transform_catalog.py                                         3      3     0%
	 main_dev_transform_config.py                                          3      3     0%
	 normalization/__init__.py                                             4      0   100%
	 normalization/destination_type.py                                    13      0   100%
	 normalization/transform_catalog/__init__.py                           2      0   100%
	 normalization/transform_catalog/catalog_processor.py                143     77    46%
	 normalization/transform_catalog/destination_name_transformer.py     155      8    95%
	 normalization/transform_catalog/reserved_keywords.py                 13      0   100%
	 normalization/transform_catalog/stream_processor.py                 520    333    36%
	 normalization/transform_catalog/table_name_registry.py              174     34    80%
	 normalization/transform_catalog/transform.py                         45     26    42%
	 normalization/transform_catalog/utils.py                             33      7    79%
	 normalization/transform_config/__init__.py                            2      0   100%
	 normalization/transform_config/transform.py                         148     34    77%
	 -------------------------------------------------------------------------------------
	 TOTAL                                                              1258    525    58%

@sashaNeshcheret
oneshcheret (sashaNeshcheret) temporarily deployed to more-secrets January 10, 2022 09:02 Inactive
@octavia-squidington-iii
Octavia Squidington III (octavia-squidington-iii) temporarily deployed to more-secrets January 10, 2022 09:04 Inactive
@sashaNeshcheret

oneshcheret (sashaNeshcheret) commented Jan 10, 2022 •

Copy link
Copy Markdown
Contributor Author

/publish connector=connectors/destination-snowflake

🕑 connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1676973694
✅ connectors/destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/1676973694

*
* @return true if the schema exists in destination database, false if it doesn't
*/
default boolean isSchemaExists(final JdbcDatabase database, final String schemaName) throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does snowflake not have a SQL statement IF NOT EXISTS? e.g: CREATE SCHEMA IF NOT EXISTS %s;? why is the iface method needed?

Ifyes, can you leave a comment clarifying why this method is needed?

Also, why do we need an extra method? Shouldn't it be covered by the createSchemaIfNotExists method? Having a default implementation which returns true can also be misleading for the developer. Either it is required or we should embed this inside createSchemaIfNotExists

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sherif A. Nada (@sherifnada) snowflake has a SQL statement IF NOT EXISTS and it was replaced by the changes. The cause for it is the 'create schema' statement needs 'CREATE SCHEMA', 'OWNERSHIP' or 'ALL' permissions on database level, and users with existing schema and 'Using' permissions on database level faced with issue Could not connect with provided configuration. SQL access control error: Insufficient privileges to operate on database 'DATABASE.
So instead of simply call CREATE SCHEMA IF NOT EXISTS %s; we firstly need to check it and try to create only if schema is absent.
Regarding right place, i did it common interface because theoretically we can faced with same permissions behavior in other db, for now i will move it from interface to snowflake operations impls.

This branch was previously deployed

1 inactive deployment
more-secrets — 26bb2066 Deployed Jan 10, 2022 by octavia-squidington-iii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Airbyte to write to a Snowflake Schema without database ownership

8 participants