Skip to content
Open
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
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ venv/
.venv
ENV/
env.bak/
venv.bak/
venv.bak/

etl_data.db

# Ignore Python cache files
__pycache__/
*.pyc
*.pyo
*.pyd
Binary file removed app/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed app/etl/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed app/etl/__pycache__/extract.cpython-310.pyc
Binary file not shown.
Binary file removed app/etl/__pycache__/extract.cpython-313.pyc
Binary file not shown.
Binary file removed app/etl/__pycache__/load.cpython-313.pyc
Binary file not shown.
Binary file removed app/etl/__pycache__/transform.cpython-313.pyc
Binary file not shown.
15 changes: 4 additions & 11 deletions app/etl/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ def load(df: pd.DataFrame, db_path: str = "etl_data.db", table_name: str = "proc
# Ensure directory exists
db_dir = os.path.dirname(db_path)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir)

os.makedirs(db_dir)
conn = None
try:
# Connect to database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# TODO (Find & Fix): Table creation and schema logic missing

# Idempotency check (should avoid duplicate inserts)
cursor.execute(f"""
CREATE TABLE IF NOT EXISTS {table_name} (
employee_id INTEGER PRIMARY KEY,
employee_id TEXT PRIMARY KEY,
name TEXT,
email TEXT,
age INTEGER,
Expand All @@ -50,15 +47,11 @@ def load(df: pd.DataFrame, db_path: str = "etl_data.db", table_name: str = "proc
)
""")

data_to_insert = [tuple(row) for row in df.itertuples(index=False, name=None)]
placeholders = ", ".join(["?"] * len(df.columns))
column_names = ", ".join(df.columns)
sql_query = f"INSERT OR IGNORE INTO {table_name} ({column_names}) VALUES ({placeholders})"
cursor.executemany(sql_query, data_to_insert)
sql_query = f"INSERT OR REPLACE INTO {table_name} ({column_names}) VALUES ({placeholders})"
cursor.executemany(sql_query, df.itertuples(index=False, name=None))
conn.commit()
# TODO (Find & Fix): Bulk insert without checking for duplicates


except sqlite3.Error as e:
if conn:
conn.rollback()
Expand Down
7 changes: 6 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os

from app.etl.extract import extract
from app.etl.transform import transform
from app.etl.load import load

def run_pipeline(csv_path: str = "data.csv", db_path: str = "etl_data.db"):
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
data_path = os.path.join(BASE_DIR, "data.csv")

def run_pipeline(csv_path: str =data_path, db_path: str = "etl_data.db"):
"""
Run the complete ETL pipeline.

Expand Down
Loading