mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat/fix(charts): Normalize qualified SQL column names for display
- Add DataFormat.normalize_qualified_sql_column_keys* so driver keys like "_u2.table_name" also expose "table_name", matching chart columns[].value. - Apply after SQL execution (LLM save path), format_json_list_data (API/history), and get_chart_data_ds (live refresh). Hive prompts: Document explicit table aliases for duplicate column names in JOINs. Frontend: Add datasource form i18n key "file_path" (en/zh-CN/zh-TW/ko-KR). Update Hive/SQLite datasource icons. Remove hive from haveSchema list.
This commit is contained in:
@@ -211,7 +211,7 @@ def format_json_list_data(origin_data: list[dict]):
|
||||
if len(decimal_str) > 15:
|
||||
value = str(value)
|
||||
_row[key] = value
|
||||
data.append(_row)
|
||||
data.append(DataFormat.normalize_qualified_sql_column_keys(_row))
|
||||
|
||||
return data
|
||||
|
||||
@@ -253,6 +253,7 @@ def get_chart_data_ds(session: SessionDep,ds_id,sql):
|
||||
else:
|
||||
result = exec_sql(ds=datasource,sql=sql, origin_column=False)
|
||||
_data = DataFormat.convert_large_numbers_in_object_array(result.get('data'))
|
||||
_data = DataFormat.normalize_qualified_sql_column_keys_in_object_array(_data)
|
||||
json_result['data'] = _data
|
||||
return json_result
|
||||
except Exception as e:
|
||||
|
||||
@@ -1318,6 +1318,7 @@ class LLMService:
|
||||
'count': len(result.get('data'))})
|
||||
|
||||
_data = DataFormat.convert_large_numbers_in_object_array(result.get('data'))
|
||||
_data = DataFormat.normalize_qualified_sql_column_keys_in_object_array(_data)
|
||||
result["data"] = _data
|
||||
|
||||
self.save_sql_data(session=_session, data_obj=result)
|
||||
|
||||
@@ -17,6 +17,34 @@ class DataFormat:
|
||||
|
||||
return df_copy
|
||||
|
||||
@staticmethod
|
||||
def normalize_qualified_sql_column_keys(row: dict) -> dict:
|
||||
"""Add unqualified keys for names like ``alias.column`` (Hive/MySQL return shape).
|
||||
|
||||
Chart bindings use the bare column name (``table_name``) while drivers may return
|
||||
``_u2.table_name``. Only adds ``short`` when absent to avoid clobbering real duplicates.
|
||||
"""
|
||||
if not row:
|
||||
return row
|
||||
out = dict(row)
|
||||
for k, v in row.items():
|
||||
ks = str(k)
|
||||
if "." not in ks:
|
||||
continue
|
||||
short = ks.rsplit(".", 1)[-1]
|
||||
if short not in out:
|
||||
out[short] = v
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def normalize_qualified_sql_column_keys_in_object_array(obj_array: list) -> list:
|
||||
if not obj_array:
|
||||
return obj_array
|
||||
return [
|
||||
DataFormat.normalize_qualified_sql_column_keys(obj) if isinstance(obj, dict) else obj
|
||||
for obj in obj_array
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def convert_large_numbers_in_object_array(obj_array, int_threshold=1e15, float_threshold=1e10):
|
||||
"""处理对象数组,将每个对象中的大数字转换为字符串"""
|
||||
|
||||
@@ -5,6 +5,7 @@ template:
|
||||
<note>
|
||||
1. 点号(.)不能包含在引号内,必须写成 `database`.`table`
|
||||
2. 即使标识符不含特殊字符或非关键字,也需强制加反引号
|
||||
3. 在多表关联(JOIN)/ 多子查询的 SQL 中,只要多个表 / 子查询存在 同名字段,所有引用该字段的位置,必须显式指定 表别名
|
||||
</note>
|
||||
</rule>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user