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

Added Oracle profiler #21

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion odd_collector_profiler/datasource/database/repository.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import sys
from contextlib import contextmanager

import oracledb
from sqlalchemy import create_engine, inspect
from sqlalchemy.engine import Connection, Engine, Inspector

from odd_collector_profiler.datasource.database.table import Table
from odd_collector_profiler.domain.config import DatabaseConfig
from odd_collector_profiler.domain.config import DatabaseConfig, OracleConfig
from odd_collector_profiler.logger import logger


Expand Down Expand Up @@ -83,3 +85,12 @@ def get_tables(self) -> list[Table]:
for table_name in self._get_tables_by(self.config.database):
if not self.config.filters or table_name in self.config.filters:
yield Table(database=self.config.database, schema=None, name=table_name)


class OracleRepository(RDBRepository):
def __init__(self, config: OracleConfig, skip_schemas: set[str] = None) -> None:
super().__init__(config, skip_schemas)
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb
if config.thick_mode:
oracledb.init_oracle_client()
17 changes: 17 additions & 0 deletions odd_collector_profiler/domain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,20 @@ class ClickHouseConfig(DatabaseConfig):
def connection_str(self) -> str:
conn_str = f"clickhouse://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
return conn_str


class OracleConfig(DatabaseConfig):
type = "oracle"
host: str
port: str
user: str
database: str
password: SecretStr
thick_mode: Optional[bool] = False

def connection_str(self) -> str:
conn_str = (
f"oracle+cx_oracle://{self.user}:{self.password.get_secret_value()}@{self.host}:{self.port}"
f"/?service_name={self.database}"
)
return conn_str
Empty file.
43 changes: 43 additions & 0 deletions odd_collector_profiler/profilers/oracle/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Any

from oddrn_generator import OracleGenerator

from odd_collector_profiler.datasource.database.profiler import RDBProfiler
from odd_collector_profiler.datasource.database.repository import OracleRepository
from odd_collector_profiler.domain.config import OracleConfig
from odd_collector_profiler.domain.profiler import Profiler
from odd_collector_profiler.profilers import DATA_PROFILER

SYS_SCHEMAS = {
"xdb",
"xs$null",
"anonymous",
"apex_040000",
"apex_public_user",
"ctxsys",
"flows_files",
"hr",
"mdsys",
"outln",
"sys",
"system",
}


class OracleProfiler(RDBProfiler):
config_model = OracleConfig
"""Profiler for Oracle datasource"""


def register_profiler(config: dict[str, Any]) -> Profiler:
config = OracleConfig.parse_obj(config)
repository = OracleRepository(config=config, skip_schemas=SYS_SCHEMAS)
generator = OracleGenerator(
host_settings=config.host, databases=config.database, schemas=config.user
)
return OracleProfiler(
config=config,
generator=generator,
repository=repository,
profiler=DATA_PROFILER,
)
Loading