Skip to content

Commit efb82ed

Browse files
committed
feat: new tips for data limit
1 parent 3c896c9 commit efb82ed

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

app/src/dataSource/index.ts app/src/dataSource/index.tsx

+32-5
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,47 @@ function initBatchGetDatas(action: string) {
122122

123123
const batchGetDatasBySql = initBatchGetDatas("batch_get_datas_by_sql");
124124
const batchGetDatasByPayload = initBatchGetDatas("batch_get_datas_by_payload");
125+
const DEFAULT_LIMIT = 50_000;
126+
127+
function notifyDataLimit() {
128+
commonStore.setNotification({
129+
type: "warning",
130+
title: "Data Limit Reached",
131+
message: (<>
132+
The current computation has returned more than 50,000 rows of data.
133+
To ensure optimal performance, we are currently rendering only the first 50,000 rows.
134+
If you need to render the entire all datas, please use the 'limit' tool
135+
(<svg className="inline bg-black" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
136+
<path
137+
d="M9.94969 7.49989C9.94969 8.85288 8.85288 9.94969 7.49989 9.94969C6.14691 9.94969 5.0501 8.85288 5.0501 7.49989C5.0501 6.14691 6.14691 5.0501 7.49989 5.0501C8.85288 5.0501 9.94969 6.14691 9.94969 7.49989ZM10.8632 8C10.6213 9.64055 9.20764 10.8997 7.49989 10.8997C5.79214 10.8997 4.37847 9.64055 4.13662 8H0.5C0.223858 8 0 7.77614 0 7.5C0 7.22386 0.223858 7 0.5 7H4.13659C4.37835 5.35935 5.79206 4.1001 7.49989 4.1001C9.20772 4.1001 10.6214 5.35935 10.8632 7H14.5C14.7761 7 15 7.22386 15 7.5C15 7.77614 14.7761 8 14.5 8H10.8632Z"
138+
fill="currentColor"
139+
fillRule="evenodd"
140+
clipRule="evenodd"
141+
></path>
142+
</svg>) to manually set the maximum number of rows to be returned.
143+
</>)
144+
}, 60_000);
145+
}
125146

126147
export function getDatasFromKernelBySql(fieldMetas: any) {
127148
return async (payload: IDataQueryPayload) => {
128149
const sql = parser_dsl_with_meta(
129150
"pygwalker_mid_table",
130-
JSON.stringify(payload),
151+
JSON.stringify({...payload, limit: payload.limit ?? DEFAULT_LIMIT}),
131152
JSON.stringify({"pygwalker_mid_table": fieldMetas})
132153
);
133-
const result = await batchGetDatasBySql.getDatas(sql);
134-
return (result ?? []) as IRow[];
154+
const result = await batchGetDatasBySql.getDatas(sql) ?? [];
155+
if (!payload.limit && result.length === DEFAULT_LIMIT) {
156+
notifyDataLimit();
157+
}
158+
return result as IRow[];
135159
}
136160
}
137161

138162
export async function getDatasFromKernelByPayload(payload: IDataQueryPayload) {
139-
const result = await batchGetDatasByPayload.getDatas(payload);
140-
return (result ?? []) as IRow[];
163+
const result = await batchGetDatasByPayload.getDatas({...payload, limit: payload.limit ?? DEFAULT_LIMIT}) ?? [];
164+
if (!payload.limit && result.length === DEFAULT_LIMIT) {
165+
notifyDataLimit();
166+
}
167+
return result as IRow[];
141168
}

pygwalker/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pygwalker.services.global_var import GlobalVarManager
1111
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle
1212

13-
__version__ = "0.4.9.2"
13+
__version__ = "0.4.9.3"
1414
__hash__ = __rand_str()
1515

1616
from pygwalker.api.jupyter import walk, render, table

pygwalker/api/pygwalker.py

-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from pygwalker.utils.randoms import generate_hash_code
3939
from pygwalker.communications.hacker_comm import HackerCommunication, BaseCommunication
4040
from pygwalker._constants import JUPYTER_BYTE_LIMIT, JUPYTER_WIDGETS_BYTE_LIMIT
41-
from pygwalker.errors import DataCountLimitError
4241
from pygwalker import __version__
4342

4443

@@ -404,34 +403,24 @@ def upload_spec_to_cloud(data: Dict[str, Any]):
404403
def _get_datas(data: Dict[str, Any]):
405404
sql = data["sql"]
406405
datas = self.data_parser.get_datas_by_sql(sql)
407-
if len(datas) > GlobalVarManager.max_data_length:
408-
raise DataCountLimitError()
409406
return {
410407
"datas": datas
411408
}
412409

413410
def _get_datas_by_payload(data: Dict[str, Any]):
414411
datas = self.data_parser.get_datas_by_payload(data["payload"])
415-
if len(datas) > GlobalVarManager.max_data_length:
416-
raise DataCountLimitError()
417412
return {
418413
"datas": datas
419414
}
420415

421416
def _batch_get_datas_by_sql(data: Dict[str, Any]):
422417
result = self.data_parser.batch_get_datas_by_sql(data["queryList"])
423-
for datas in result:
424-
if len(datas) > GlobalVarManager.max_data_length:
425-
raise DataCountLimitError()
426418
return {
427419
"datas": result
428420
}
429421

430422
def _batch_get_datas_by_payload(data: Dict[str, Any]):
431423
result = self.data_parser.batch_get_datas_by_payload(data["queryList"])
432-
for datas in result:
433-
if len(datas) > GlobalVarManager.max_data_length:
434-
raise DataCountLimitError()
435424
return {
436425
"datas": result
437426
}

pygwalker/errors.py

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ class ViewSqlSameColumnError(BaseError):
4343
pass
4444

4545

46-
class DataCountLimitError(BaseError):
47-
"""Raised when the data count is too large."""
48-
def __init__(self) -> None:
49-
super().__init__(
50-
"The query returned too many data entries, making it difficult for the frontend to render. Please adjust your chart configuration and try again.",
51-
code=ErrorCode.UNKNOWN_ERROR
52-
)
53-
54-
5546
class StreamlitPygwalkerApiError(BaseError):
5647
"""Raised when the config is invalid."""
5748
def __init__(self) -> None:

pygwalker/services/global_var.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
from pandas import DataFrame
4-
from typing_extensions import Literal
4+
from typing_extensions import Literal, deprecated
55

66
from .config import get_config
77

@@ -46,6 +46,7 @@ def set_last_exported_dataframe(cls, df: DataFrame):
4646
cls.last_exported_dataframe = df
4747

4848
@classmethod
49+
@deprecated("use ui config instead.")
4950
def set_max_data_length(cls, length: int):
5051
cls.max_data_length = length
5152

0 commit comments

Comments
 (0)