fix(sqlalchemy): do not emit CREATE SCHEMA on Oracle (#3939)#4001
Open
DRACULA1729 wants to merge 1 commit into
Open
fix(sqlalchemy): do not emit CREATE SCHEMA on Oracle (#3939)#4001DRACULA1729 wants to merge 1 commit into
DRACULA1729 wants to merge 1 commit into
Conversation
Oracle schemas are owned by database users and cannot be created with a bare `CREATE SCHEMA` statement, so the sqlalchemy destination failed with `ORA-02420: missing schema authorization clause` when initializing storage. Add dataset-lifecycle extension points (`dataset_exists`, `create_dataset`, `drop_dataset`) to `DialectCapabilities` and delegate to them from the SQL client. The base implementations preserve the previous behavior for all other dialects. `OracleDialectCapabilities` overrides them to: - match schema existence case-insensitively (Oracle folds identifiers to upper case), so loading into an existing schema is detected and no creation is attempted - skip `CREATE SCHEMA`; raise a clear terminal error when the target schema (or `<dataset>_staging`) does not exist, instead of the cryptic ORA-02420 - drop the tables within the schema instead of `DROP SCHEMA` (which would require `DROP USER`, a DBA privilege) Add unit tests for the new hooks and document Oracle's existing-schema requirement in the destination docs.
ef3ee3a to
31bcc80
Compare
Author
|
This is ready for review. The fork-gated workflows (the ones that need repo secrets) are stuck in the "requires reviewer approval" state, so they need a maintainer to approve the run before they execute. @ivasio you dug into this exact Oracle case in #3141, so it's probably familiar territory. @rudolfix it extends the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Loading to Oracle through the
sqlalchemydestination fails on the first run withORA-02420: missing schema authorization clause. dlt runsCREATE SCHEMA "<dataset>"when it cannot find the target dataset, and Oracle rejects that. In Oracle a schema is a database user, so there is no bareCREATE SCHEMA(it needsCREATE SCHEMA AUTHORIZATION <user> ...).This adds dataset-lifecycle extension points to
DialectCapabilitiesand routes the SQL client through them. The base implementations keep the old behavior for every other dialect, so nothing changes for Postgres/MySQL/etc.OracleDialectCapabilitiesoverrides them:dataset_existsmatches case-insensitively, since Oracle folds unquoted identifiers to upper case. Loading into an existing schema is now detected and no creation is attempted.create_datasetno longer emitsCREATE SCHEMA. If the schema is missing it raises a terminal error explaining that the schema (and the<dataset>_stagingschema, for merge/replace) has to be created up front as a user with grants, instead of surfacing the cryptic ORA-02420.drop_datasetdrops the tables inside the schema instead ofDROP SCHEMA, which on Oracle would requireDROP USER(a DBA privilege).Related Issues
Additional Context
<dataset>_stagingschema, merge/replace still work.tests/load/sqlalchemy/test_sqlalchemy_dialect.pyand run without a live Oracle.sqlalchemy.md.