Files
mars-elt/airflow/TestDags/archive/dmarsdb1_data_replicator_test.py
Grzegorz Michalski 2c225d68ac init
2026-03-02 09:47:35 +01:00

66 lines
1.9 KiB
Python

from airflow import DAG
from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
from airflow.operators.python import PythonOperator
from datetime import datetime, timedelta
import logging
logger = logging.getLogger(__name__)
## OLD ( Package repliction)
def test_oracle_connection(**context):
"""Test Oracle connection and log the result"""
conn_id = "marsdb_loader"
from airflow.providers.oracle.hooks.oracle import OracleHook
try:
logger.debug("Attempting to connect to Oracle database...")
hook = OracleHook(oracle_conn_id=conn_id)
conn = hook.get_conn()
cursor = conn.cursor()
cursor.execute("SELECT 1 FROM dual")
result = cursor.fetchone()
logger.info(f"Connection test successful. Result: {result}")
cursor.close()
conn.close()
except Exception as e:
logger.error(f"Connection test failed: {str(e)}")
raise
default_args = {
'depends_on_past': False,
'start_date': datetime(2025, 6, 25),
'retries': 1,
'retry_delay': timedelta(seconds=15),
}
with DAG(
'oracle_plsql_test_dag',
default_args=default_args,
schedule_interval=None,
catchup=False,
) as dag:
test_connection = PythonOperator(
task_id='test_oracle_connection',
python_callable=test_oracle_connection,
)
# With named parameter
run_plsql = SQLExecuteQueryOperator(
task_id='run_plsql_procedure',
conn_id="marsdb_loader",
sql="""
BEGIN
DATA_REPLICATOR.export_table(
p_table_owner => 'c2d',
p_table_name => 't_all_assets_servicer',
p_objectstore_uri => 'https://oci-test-sani.bucket.vpce-0b3a5f000733397b0-kxlyoh5z.s3.eu-central-1.vpce.amazonaws.com/',
p_date_column => 'SNAPSHOT_DATE'
);
END;
""",
)
test_connection >> run_plsql