Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<fix>[oracle ingestion]: get database name when using service #10158

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/source/sql/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ def __init__(self, inspector_instance: Inspector):
# tables that we don't want to ingest into the DataHub
self.exclude_tablespaces: Tuple[str, str] = ("SYSTEM", "SYSAUX")

def get_db_name(self) -> str:
try:
# Try to retrieve current DB name by executing query
db_name = self._inspector_instance.bind.execute(
sql.text("select sys_context('USERENV','DB_NAME') from dual")
).scalar()
return str(db_name)
except sqlalchemy.exc.DatabaseError as e:
logger.error("Error fetching DB name: " + str(e))
return ""

def get_schema_names(self) -> List[str]:
cursor = self._inspector_instance.bind.execute(
sql.text("SELECT username FROM dba_users ORDER BY username")
Expand Down Expand Up @@ -582,6 +593,22 @@ def create(cls, config_dict, ctx):
config = OracleConfig.parse_obj(config_dict)
return cls(config, ctx)

def get_db_name(self, inspector: Inspector) -> str:
"""
This overwrites the default implementation, which only tries to read
database name from Connection URL, which does not work when using
service instead of database.
In that case, it tries to retrieve the database name by sending a query to the DB.
"""

# call default implementation first
db_name = super().get_db_name(inspector)

if db_name == "" and isinstance(inspector, OracleInspectorObjectWrapper):
db_name = inspector.get_db_name()

return db_name

def get_inspectors(self) -> Iterable[Inspector]:
for inspector in super().get_inspectors():
event.listen(
Expand Down
Loading