Skip to content

Commit b3ba438

Browse files
authored
Merge pull request #5 from databendlabs/pyarrow-pandas
remove pandas dep
2 parents f546346 + 973e556 commit b3ba438

File tree

3 files changed

+14
-143
lines changed

3 files changed

+14
-143
lines changed

mcp_databend/server.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from mcp.server.fastmcp import FastMCP
77
import concurrent.futures
88
from dotenv import load_dotenv
9+
import pyarrow as pa
910
import atexit
1011
from typing import Optional
1112
from .env import get_config
@@ -107,8 +108,8 @@ def execute_databend_query(sql: str) -> list[dict] | dict:
107108
if config.local_mode:
108109
# Handle local in-memory Databend
109110
result = client.sql(sql)
110-
df = result.to_pandas()
111-
return df.to_dict("records")
111+
df = result.to_py_arrow()
112+
return recordbatches_to_dicts(df)
112113
else:
113114
# Handle remote Databend server
114115
conn = client.get_conn()
@@ -128,6 +129,15 @@ def execute_databend_query(sql: str) -> list[dict] | dict:
128129
logger.error(error_msg)
129130
return {"error": error_msg}
130131

132+
def recordbatches_to_dicts(batches: list[pa.RecordBatch]) -> list[dict]:
133+
results = []
134+
for batch in batches:
135+
columns = batch.schema.names
136+
columns_data = [batch.column(i).to_pylist() for i in range(batch.num_columns)]
137+
for row in zip(*columns_data):
138+
results.append(dict(zip(columns, row)))
139+
return results
140+
131141

132142
def _execute_sql(sql: str) -> dict:
133143
logger.info(f"Executing SQL query: {sql}")

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-databend"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "An MCP server for Databend."
55
readme = "README.md"
66
requires-python = ">=3.12"
@@ -24,7 +24,6 @@ dependencies = [
2424
"databend>=1.2.810",
2525
"databend-driver>=0.27.3",
2626
"mcp>=1.9.0",
27-
"pandas>=2.3.2",
2827
"pyarrow>=21.0.0",
2928
"python-dotenv>=1.1.0",
3029
]

0 commit comments

Comments
 (0)