Skip to content

Commit 73fca4d

Browse files
committed
v0.2.10: JSON TABLE: support alias in order by clause
Signed-off-by: shanhaikang.shk <shanhaikang.shk@oceanbase.com>
1 parent 427e1bc commit 73fca4d

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ poetry install
1515
- install with pip:
1616

1717
```shell
18-
pip install pyobvector==0.2.9
18+
pip install pyobvector==0.2.10
1919
```
2020

2121
## Build Doc

pyobvector/client/ob_vec_json_table_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ def _handle_jtable_dml_select(
846846
new_select_exprs.append(data_id_col_expr)
847847
need_replace_select_exprs = True
848848

849+
alias_names = set()
849850
for select_expr in ast.args['expressions']:
850851
if isinstance(select_expr, exp.Star):
851852
need_replace_select_exprs = True
@@ -857,6 +858,8 @@ def _handle_jtable_dml_select(
857858
col_expr.args['this'] = identifier
858859
new_select_exprs.append(col_expr)
859860
else:
861+
if isinstance(select_expr, exp.Alias):
862+
alias_names.add(select_expr.args['alias'].args['this'])
860863
new_select_exprs.append(select_expr)
861864
if need_replace_select_exprs:
862865
ast.args['expressions'] = new_select_exprs
@@ -865,6 +868,9 @@ def _handle_jtable_dml_select(
865868
json_table_str = f"json_table({JSON_TABLE_DATA_TABLE_NAME}.jdata, '$' COLUMNS ({', '.join(json_table_meta_str)})) {tmp_table_name}"
866869

867870
for col in ast.find_all(exp.Column):
871+
col_name = col.args["this"].args["this"]
872+
if col_name in alias_names:
873+
continue
868874
if 'table' in col.args.keys():
869875
if col.args['table'].args['this'] != JSON_TABLE_DATA_TABLE_NAME:
870876
col.args['table'].args['this'] = tmp_table_name
@@ -894,6 +900,6 @@ def _handle_jtable_dml_select(
894900
where_clause.args['this'] = parse_one(extra_filter_str)
895901
ast.args['where'] = where_clause
896902

897-
select_sql = str(ast)
903+
select_sql = ast.sql(dialect="mysql", identify=True)
898904
logger.debug(f"===================== do select: {select_sql}")
899905
return self.perform_raw_text_sql(select_sql)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyobvector"
3-
version = "0.2.9"
3+
version = "0.2.10"
44
description = "A python SDK for OceanBase Vector Store, based on SQLAlchemy, compatible with Milvus API."
55
authors = ["shanhaikang.shk <shanhaikang.shk@oceanbase.com>"]
66
readme = "README.md"

tests/test_json_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def test_online_cases(self):
426426
)
427427

428428
res = self.client.perform_json_table_sql(
429-
"SELECT field0, field1, field2 FROM `table_unit_test` WHERE DATE(field3)='2025-03-09' ORDER BY field2 DESC LIMIT 2"
429+
"SELECT field0 AS 消费内容, `table_unit_test`.field1 AS 消费类型, field2 AS 消费金额 FROM `table_unit_test` WHERE DATE(`table_unit_test`.field3)='2025-03-09' ORDER BY 消费金额 DESC LIMIT 2"
430430
)
431431
# logger.info(get_all_rows(res))
432432
self.assertEqual(

0 commit comments

Comments
 (0)