question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Oracle] Oracle Hook - make it possible to define a schema in the connection parameters

See original GitHub issue

Description

Currently the oracle hook it not setting a CURRENT_SCHEMA after connecting with the Database. In a lot of use cases we have production and test databases with seperate connections and database schemas e.g. TEST.Table1, PROD.Table1 “Hard-coding” the database schema in SQL Scripts is not elegant due to having different Airflow Instances for developing and Production.

An Option would be to store the database schema in a airflow Variable and getting it into the sql script with JINJA. In Large SQL files with several tables it is not elegant either, because for every table a query to the metadatabase is made.

Why not using the Schema parameter in the Airflow Connections and executing ALTER SESSION SET CURRENT_SCHEMA='SCHEMA' right after successfully connecting to the database?

An alternative would be to use option Connection.current_schema of Library cx_Oracle. https://cx-oracle.readthedocs.io/en/6.4.1/connection.html#Connection.current_schema

Use case/motivation

It makes Query development much easier by storing environment attributes directly in the Airflow Connection. You have full flexibility without touching your SQL Script. It makes separation of Test and Production environments and connections possible.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eladkalcommented, Oct 6, 2021

We probably also need to customize the connection fields in the UI and set Service Name with explanation to avoid confusion. Similar to what was done for Salesforce https://github.com/apache/airflow/pull/17162

@mehmax do you want to work on this?

0reactions
mehmaxcommented, Oct 19, 2021

@eladkal @uranusjr @nikochiko I created PR #19084. Could you please have a look at this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SET SCHEMA statement
The SET SCHEMA statement sets the default schema for a connection's session to the designated schema. The default schema is used as the...
Read more >
4 Creating the Master and Work Repository Schemas
Use the Database Connection Details screen to specify a product database schema with a custom prefix. Specifying Schema Passwords On the Schema Passwords...
Read more >
2 Developing Oracle REST Data Services Applications
This section describes how to use query strings in the URI to specify parameters for REST requests like the GET method, which does...
Read more >
Connecting to Oracle Database
Connection String Attributes. Connection String Builder. Specifying the Data Source Attribute. Schema Discovery. Connection Pooling. Connection Pool Management.
Read more >
Making Database Connections - Oracle Blogs
Connect to Oracle and third-party databases from Oracle SQL Developer. ; Now create a basic connection for this user from the New/Select Database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found