Skip to content

Commit f9492b1

Browse files
committed
Merge branch 'master' into feature/80-add-connectors-and-metadata
2 parents 37b9c5e + 717bfb1 commit f9492b1

28 files changed

+1350
-448
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ test_lhm/
1010
.cursorignore
1111
.vscode
1212
table_info_db
13-
ko_reranker_local
13+
ko_reranker_local

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Python 3.10 slim 이미지 기반
2+
FROM python:3.12-slim
3+
4+
# 시스템 라이브러리 설치
5+
RUN apt-get update && apt-get install -y \
6+
build-essential \
7+
curl \
8+
software-properties-common \
9+
git \
10+
libpq-dev \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# 작업 디렉토리 설정
14+
WORKDIR /app
15+
16+
# 의존성 파일 복사 및 설치
17+
COPY requirements.txt .
18+
RUN pip install --no-cache-dir -r requirements.txt
19+
20+
# 전체 서비스 코드 복사
21+
COPY . .
22+
23+
# Python 환경 설정
24+
ENV PYTHONPATH=/app
25+
ENV PYTHONUNBUFFERED=1
26+
27+
# Streamlit 포트 노출
28+
EXPOSE 8501
29+
30+
# Streamlit 실행 명령
31+
CMD ["python", "-c", "from llm_utils.tools import set_gms_server; import os; set_gms_server(os.getenv('DATAHUB_SERVER', 'http://localhost:8080'))"]
32+
CMD ["streamlit", "run", "./interface/streamlit_app.py", "--server.port=8501"]

README.md

Lines changed: 201 additions & 139 deletions
Large diffs are not rendered by default.

cli/__init__.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
"""
2-
Datahub GMS 서버 URL을 설정하고, 필요 시 Streamlit 인터페이스를 실행하는 CLI 프로그램입니다.
2+
Lang2SQL CLI 프로그램입니다.
3+
이 프로그램은 Datahub GMS 서버 URL을 설정하고, 필요 시 Streamlit 인터페이스를 실행합니다.
4+
5+
명령어 예시: lang2sql --datahub_server http://localhost:8080 --run-streamlit
36
"""
47

8+
import logging
59
import subprocess
610

711
import click
812

13+
from llm_utils.check_server import CheckServer
914
from llm_utils.tools import set_gms_server
15+
from version import __version__
16+
17+
logging.basicConfig(
18+
level=logging.INFO,
19+
format="%(asctime)s [%(levelname)s] %(message)s",
20+
datefmt="%Y-%m-%d %H:%M:%S",
21+
)
22+
logger = logging.getLogger(__name__)
1023

1124

1225
@click.group()
13-
@click.version_option(version="0.1.4")
26+
@click.version_option(version=__version__)
1427
@click.pass_context
1528
@click.option(
1629
"--datahub_server",
@@ -64,11 +77,20 @@ def cli(
6477
'set_gms_server' 함수에서 ValueError가 발생할 경우, 프로그램은 비정상 종료(exit code 1)합니다.
6578
"""
6679

67-
try:
80+
logger.info(
81+
"Initialization started: GMS server = %s, run_streamlit = %s, port = %d",
82+
datahub_server,
83+
run_streamlit,
84+
port,
85+
)
86+
87+
if CheckServer.is_gms_server_healthy(url=datahub_server):
6888
set_gms_server(datahub_server)
69-
except ValueError as e:
70-
click.secho(f"GMS 서버 URL 설정 실패: {str(e)}", fg="red")
89+
logger.info("GMS server URL successfully set: %s", datahub_server)
90+
else:
91+
logger.error("GMS server health check failed. URL: %s", datahub_server)
7192
ctx.exit(1)
93+
7294
if run_streamlit:
7395
run_streamlit_command(port)
7496

@@ -89,6 +111,8 @@ def run_streamlit_command(port: int) -> None:
89111
- subprocess 호출 실패 시 예외가 발생할 수 있습니다.
90112
"""
91113

114+
logger.info("Starting Streamlit application on port %d...", port)
115+
92116
try:
93117
subprocess.run(
94118
[
@@ -100,8 +124,9 @@ def run_streamlit_command(port: int) -> None:
100124
],
101125
check=True,
102126
)
127+
logger.info("Streamlit application started successfully.")
103128
except subprocess.CalledProcessError as e:
104-
click.echo(f"Streamlit 실행 실패: {e}")
129+
logger.error("Failed to start Streamlit application: %s", e)
105130
raise
106131

107132

@@ -132,4 +157,5 @@ def run_streamlit_cli_command(port: int) -> None:
132157
- Streamlit 실행에 실패할 경우 subprocess 호출에서 예외가 발생할 수 있습니다.
133158
"""
134159

160+
logger.info("Executing 'run-streamlit' command on port %d...", port)
135161
run_streamlit_command(port)

data_utils/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
# data_utils 패키지 초기화 파일

db_utils/__init__.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
else:
2525
print(f"⚠️ 환경변수 파일(.env)이 {os.getcwd()}에 없습니다!")
2626

27+
2728
def get_db_connector(db_type: Optional[str] = None, config: Optional[DBConfig] = None):
2829
"""
2930
Return the appropriate DB connector instance.
@@ -43,23 +44,25 @@ def get_db_connector(db_type: Optional[str] = None, config: Optional[DBConfig] =
4344
if db_type is None:
4445
db_type = os.getenv("DB_TYPE")
4546
if not db_type:
46-
raise ValueError("DB type must be provided or set in environment as DB_TYPE.")
47+
raise ValueError(
48+
"DB type must be provided or set in environment as DB_TYPE."
49+
)
4750

4851
db_type = db_type.lower()
4952

5053
if config is None:
5154
config = load_config_from_env(db_type.upper())
5255

5356
connector_map = {
54-
"clickhouse": ClickHouseConnector,
55-
"postgresql": PostgresConnector,
56-
"mysql": MySQLConnector,
57-
"mariadb": MariaDBConnector,
58-
"oracle": OracleConnector,
59-
"duckdb": DuckDBConnector,
60-
"databricks": DatabricksConnector,
61-
"snowflake": SnowflakeConnector,
62-
}
57+
"clickhouse": ClickHouseConnector,
58+
"postgresql": PostgresConnector,
59+
"mysql": MySQLConnector,
60+
"mariadb": MariaDBConnector,
61+
"oracle": OracleConnector,
62+
"duckdb": DuckDBConnector,
63+
"databricks": DatabricksConnector,
64+
"snowflake": SnowflakeConnector,
65+
}
6366

6467
if db_type not in connector_map:
6568
logger.error(f"Unsupported DB type: {db_type}")
@@ -87,7 +90,6 @@ def get_db_connector(db_type: Optional[str] = None, config: Optional[DBConfig] =
8790
return connector_map[db_type](config)
8891

8992

90-
9193
def load_config_from_env(prefix: str) -> DBConfig:
9294
"""
9395
Load DBConfig from environment variables with a given prefix.
@@ -107,7 +109,9 @@ def load_config_from_env(prefix: str) -> DBConfig:
107109
# Extract standard values
108110
config = {
109111
"host": os.getenv(f"{prefix}_HOST"),
110-
"port": int(os.getenv(f"{prefix}_PORT")) if os.getenv(f"{prefix}_PORT") else None,
112+
"port": (
113+
int(os.getenv(f"{prefix}_PORT")) if os.getenv(f"{prefix}_PORT") else None
114+
),
111115
"user": os.getenv(f"{prefix}_USER"),
112116
"password": os.getenv(f"{prefix}_PASSWORD"),
113117
"database": os.getenv(f"{prefix}_DATABASE"),
@@ -117,11 +121,11 @@ def load_config_from_env(prefix: str) -> DBConfig:
117121
extra = {}
118122
for key, value in os.environ.items():
119123
if key.startswith(f"{prefix}_"):
120-
suffix = key[len(f"{prefix}_"):]
124+
suffix = key[len(f"{prefix}_") :]
121125
if suffix.upper() not in base_keys:
122126
extra[suffix.lower()] = value
123127

124128
if extra:
125129
config["extra"] = extra
126130

127-
return DBConfig(**config)
131+
return DBConfig(**config)

db_utils/clickhouse_connector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import pandas as pd
44
from db_utils import DBConfig, logger
55

6+
67
class ClickHouseConnector(BaseConnector):
78
"""
89
Connect to ClickHouse and execute SQL queries.
910
"""
11+
1012
client = None
1113

1214
def __init__(self, config: DBConfig):
@@ -54,8 +56,8 @@ def run_sql(self, sql: str) -> pd.DataFrame:
5456
self.connect()
5557

5658
try:
57-
result = self.client.query(sql).result()
58-
return pd.DataFrame(result)
59+
result = self.client.query_dataframe(sql)
60+
return result
5961
except Exception as e:
6062
logger.error(f"Failed to execute SQL query: {e}")
6163
raise

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
streamlit:
3+
build: .
4+
ports:
5+
- "8501:8501"
6+
volumes:
7+
- .:/app
8+
env_file:
9+
- .env
10+
environment:
11+
- DATABASE_URL=postgresql://postgres:password@db:5432/streamlit_db
12+
depends_on:
13+
- db
14+
15+
db:
16+
image: pgvector/pgvector:pg17
17+
container_name: pgvector-db
18+
environment:
19+
POSTGRES_USER: postgres
20+
POSTGRES_PASSWORD: password
21+
POSTGRES_DB: streamlit_db
22+
ports:
23+
- "5432:5432"
24+
volumes:
25+
- pgdata:/var/lib/postgresql/data
26+
- ./postgres/schema.sql:/docker-entrypoint-initdb.d/schema.sql
27+
volumes:
28+
pgdata:

docs/README.md

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)