Skip to content

Commit

Permalink
Oracle integration (#258)
Browse files Browse the repository at this point in the history
* add: oracle integration

* fix: docker compose and datasource type

---------

Co-authored-by: subhankarb <subhankar@waterdip.ai>
  • Loading branch information
Ryuk-me and subhankarb authored Oct 7, 2024
1 parent 3a5e1ec commit 80c8097
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 207 deletions.
3 changes: 3 additions & 0 deletions dcs_core/core/common/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DataSourceType(str, Enum):
SNOWFLAKE = "snowflake"
DATABRICKS = "databricks"
SPARK_DF = "spark_df"
ORACLE = "oracle"


class DataSourceLanguageSupport(str, Enum):
Expand Down Expand Up @@ -74,6 +75,8 @@ class DataSourceConnectionConfiguration:

spark_session: Optional[Any] = None # Spark specific configuration

service_name: Optional[str] = None # Oracle specific configuration


@dataclass
class DataSourceConfiguration:
Expand Down
1 change: 1 addition & 0 deletions dcs_core/core/configuration/configuration_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _data_source_connection_config_parser(
account=config["connection"].get("account"),
warehouse=config["connection"].get("warehouse"),
role=config["connection"].get("role"),
service_name=config["connection"].get("service_name"),
)
return connection_config

Expand Down
1 change: 1 addition & 0 deletions dcs_core/core/datasource/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DataSourceManager:
"redshift": "RedShiftDataSource",
"snowflake": "SnowFlakeDataSource",
"mssql": "MssqlDataSource",
"oracle": "OracleDataSource",
}

def __init__(self, config: Configuration):
Expand Down
49 changes: 49 additions & 0 deletions dcs_core/integrations/databases/oracle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2022-present, the Waterdip Labs Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Dict

from sqlalchemy import create_engine
from sqlalchemy.engine import URL

from dcs_core.core.common.errors import DataChecksDataSourcesConnectionError
from dcs_core.core.datasource.sql_datasource import SQLDataSource


class OracleDataSource(SQLDataSource):
def __init__(self, data_source_name: str, data_connection: Dict):
super().__init__(data_source_name, data_connection)

def connect(self) -> Any:
"""
Connect to the data source
"""
try:
engine = create_engine(
f"oracle+oracledb://:@",
thick_mode=False,
connect_args={
"user": self.data_connection.get("username"),
"password": self.data_connection.get("password"),
"host": self.data_connection.get("host"),
"port": self.data_connection.get("port"),
"service_name": self.data_connection.get("service_name"),
},
)
self.connection = engine.connect()
return self.connection
except Exception as e:
raise DataChecksDataSourcesConnectionError(
message=f"Failed to connect to Oracle data source: [{str(e)}]"
)
20 changes: 20 additions & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ services:
- test-postgres
restart: unless-stopped

test-dc-oracle:
image: gvenzl/oracle-xe
container_name: test-oracle-db
environment:
- ORACLE_PASSWORD=password
- ORACLE_DISABLE_ASYNCH_IO=true
ports:
- "1521:1521"
- "5500:5500"
volumes:
- test-oracle-data:/opt/oracle/oradata
restart: always
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5500/em"]
interval: 1m30s
timeout: 30s
retries: 5

networks:
test-opensearch-net:
test-postgres:
Expand All @@ -51,4 +69,6 @@ volumes:
test-opensearch-data:
test-dc-mysql:
test-postgres:
driver: local
test-oracle-data:
driver: local
Loading

0 comments on commit 80c8097

Please sign in to comment.