Skip to content

Commit 7f5f67e

Browse files
authored
Merge pull request #58 from eifrach/get_all_partitions
NO-ISSUE: fix issue where tool gets only the first partition
2 parents e5bf9fd + a592e57 commit 7f5f67e

File tree

3 files changed

+443
-284
lines changed

3 files changed

+443
-284
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "A Model Context Protocol (MCP) server that provides access to JIR
55
readme = "README.md"
66
requires-python = ">=3.10"
77
dependencies = [
8-
"httpx==0.28.1",
8+
"httpx[http2]==0.28.1",
99
"mcp==1.11.0",
1010
"prometheus_client==0.20.0",
1111
]
@@ -23,4 +23,5 @@ packages = ["src"]
2323
[tool.uv]
2424
dev-dependencies = [
2525
"flake8>=7.3.0",
26+
"requests>=2.32.4",
2627
]

src/database.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def make_snowflake_request(
4949
url = f"{SNOWFLAKE_BASE_URL}/{endpoint}"
5050

5151
try:
52-
async with httpx.AsyncClient(timeout=30.0) as client:
52+
async with httpx.AsyncClient(timeout=60.0, http2=True) as client:
5353
if method.upper() == "GET":
5454
response = await client.request(method, url, headers=headers, params=data)
5555
else:
@@ -102,8 +102,41 @@ async def execute_snowflake_query(sql: str, snowflake_token: Optional[str] = Non
102102
# Parse the response to extract data
103103
if response and "data" in response:
104104
logger.info(f"Successfully got {len(response['data'])} rows from Snowflake")
105+
106+
all_data = response["data"]
107+
108+
# Check for pagination/partitions
109+
metadata = response.get('resultSetMetaData', {})
110+
partition_info = metadata.get('partitionInfo', [])
111+
112+
if len(partition_info) > 1:
113+
logger.info(f"Found {len(partition_info)} partitions, fetching remaining data...")
114+
115+
# Get the statement handle for pagination
116+
statement_handle = response.get('statementHandle')
117+
if statement_handle:
118+
# Fetch remaining partitions
119+
for partition_index in range(1, len(partition_info)):
120+
try:
121+
partition_endpoint = f"statements/{statement_handle}?partition={partition_index}"
122+
partition_response = await make_snowflake_request(
123+
partition_endpoint, "GET", None, snowflake_token
124+
)
125+
126+
if partition_response and "data" in partition_response:
127+
partition_data = partition_response["data"]
128+
logger.info(f"Fetched partition {partition_index}: {len(partition_data)} rows")
129+
all_data.extend(partition_data)
130+
else:
131+
logger.warning(f"Failed to fetch partition {partition_index}")
132+
133+
except Exception as e:
134+
logger.error(f"Error fetching partition {partition_index}: {e}")
135+
136+
logger.info(f"Total rows after fetching all partitions: {len(all_data)}")
137+
105138
success = True
106-
return response["data"]
139+
return all_data
107140
elif response and "resultSet" in response:
108141
# Handle different response formats
109142
result_set = response["resultSet"]
@@ -155,7 +188,7 @@ async def get_issue_labels(issue_ids: List[str], snowflake_token: Optional[str]
155188

156189
sql = f"""
157190
SELECT ISSUE, LABEL
158-
FROM JIRA_LABEL_RHAI
191+
FROM {SNOWFLAKE_DATABASE}.{SNOWFLAKE_SCHEMA}.JIRA_LABEL_RHAI
159192
WHERE ISSUE IN ({ids_str}) AND LABEL IS NOT NULL
160193
"""
161194

@@ -201,7 +234,7 @@ async def get_issue_comments(issue_ids: List[str], snowflake_token: Optional[str
201234

202235
sql = f"""
203236
SELECT ID, ISSUEID, ROLELEVEL, BODY, CREATED, UPDATED
204-
FROM JIRA_COMMENT_NON_PII
237+
FROM {SNOWFLAKE_DATABASE}.{SNOWFLAKE_SCHEMA}.JIRA_COMMENT_NON_PII
205238
WHERE ISSUEID IN ({ids_str}) AND BODY IS NOT NULL
206239
ORDER BY ISSUEID, CREATED ASC
207240
"""

0 commit comments

Comments
 (0)