Skip to content

Commit 80a1b75

Browse files
Fixed pysdk_api_reference.md, add some function test cases. (#676)
### What problem does this PR solve? Fixed pysdk_api_reference.md, add some function test cases. Issue link:#672 #673 #675 ### Type of change - [x] Documentation Update - [x] Test cases
1 parent 6b977b9 commit 80a1b75

File tree

5 files changed

+86
-48
lines changed

5 files changed

+86
-48
lines changed

docs/pysdk_api_reference.md

+32-40
Original file line numberDiff line numberDiff line change
@@ -446,36 +446,28 @@ This method searches for rows that satisfy the search condition and updates them
446446
- response `success` is `True`
447447
- failure: `Exception`
448448

449-
# table_obj.query_builder
450449

451-
Gets a query_builder by self.
452-
453-
```python
454-
query_builder=table_obj.query_builder
455-
```
456-
457-
## Details
458-
459-
This method retrieves a query_builder by self table.
460-
461-
## Returns
462-
463-
- success:
464-
- A `query_builder` object.
465-
- failure: `Exception`
466-
467-
---
468-
469-
# query_builder.output
450+
# table_obj.output
470451

471452
Specifies the columns to display in the search output.
472453

473454
```python
474-
query_builder.output(["num", "body"])
455+
table_obj.output(["num", "body"])
475456
# To display all columns
476-
query_builder.output(["*"])
457+
table_obj.output(["*"])
477458
# To display row ID
478-
query_builder.output(["_row_id"])
459+
table_obj.output(["_row_id"])
460+
```
461+
Convert output to different display types.
462+
```python
463+
# Returns a data result
464+
table_obj.output(["*"]).to_result()
465+
# Returns a pandas result
466+
table_obj.output(["*"]).to_df()
467+
# Returns a polars result
468+
table_obj.output(["*"]).to_pl()
469+
# Returns a pyarrow result
470+
table_obj.output(["*"]).to_arrow()
479471
```
480472

481473
## Details
@@ -493,12 +485,12 @@ This method specifies the columns to display in the search output. You must inpu
493485

494486
- self : `InfinityThriftQueryBuilder`
495487

496-
# query_builder.filter
488+
# table_obj.filter
497489

498490
Builds a filtering condition expression.
499491

500492
```python
501-
query_builder.filter("(-7 < c1 or 9 >= c1) and (c2 = 3)")
493+
table_obj.filter("(-7 < c1 or 9 >= c1) and (c2 = 3)")
502494
```
503495

504496
## Details
@@ -515,13 +507,13 @@ This method builds a filtering expression.
515507

516508
- self : `InfinityThriftQueryBuilder`
517509

518-
# query_builder.knn
510+
# table_obj.knn
519511

520512
Builds a KNN search expression.
521513

522514
```python
523-
query_builder.knn('col1', [0.1,0.2,0.3], 'float', 'l2', 100)
524-
query_builder.knn('vec', [3.0] * 5, 'float', 'ip', 2)
515+
table_obj.knn('col1', [0.1,0.2,0.3], 'float', 'l2', 100)
516+
table_obj.knn('vec', [3.0] * 5, 'float', 'ip', 2)
525517
```
526518

527519
## Details
@@ -548,12 +540,12 @@ VEC supports list or np.ndarray.
548540

549541
- self : `InfinityThriftQueryBuilder`
550542

551-
# query_builder.match
543+
# table_obj.match
552544

553545
Builds a full-text search expression.
554546

555547
```python
556-
query_builder.match('body', 'harmful', 'topn=2')
548+
table_obj.match('body', 'harmful', 'topn=2')
557549
```
558550

559551
## Details
@@ -570,12 +562,12 @@ This method builds a full-text search expression.
570562

571563
- self : `InfinityThriftQueryBuilder`
572564

573-
# query_builder.fusion
565+
# table_obj.fusion
574566

575567
Builds a fusion expression.
576568

577569
```python
578-
query_builder.fusion('rrf')
570+
table_obj.fusion('rrf')
579571
```
580572

581573
## Details
@@ -592,12 +584,12 @@ query_builder.fusion('rrf')
592584

593585
- self : `InfinityThriftQueryBuilder`
594586

595-
# query_builder.to_result
587+
# table_obj.output.to_result
596588

597589
Returns a data result.
598590

599591
```python
600-
table_obj.query_builder().output(["*"]).to_result()
592+
table_obj.output(["*"]).to_result()
601593
```
602594

603595
## Details
@@ -610,12 +602,12 @@ This method returns a data result of Python's built-in type.
610602

611603
- `tuple[dict[str, list[Any]], dict[str, Any]]`
612604

613-
# query_builder.to_df
605+
# table_obj.output.to_df
614606

615607
Returns a pandas result.
616608

617609
```python
618-
table_obj.query_builder().output(["*"]).to_df()
610+
table_obj.output(["*"]).to_df()
619611
```
620612

621613
## Details
@@ -626,12 +618,12 @@ This method returns a data result in pandas `DataFrame`.
626618

627619
- `pandas.DataFrame`
628620

629-
# query_builder.to_pl
621+
# table_obj.output.to_pl
630622

631623
Returns a polars result.
632624

633625
```python
634-
table_obj.query_builder().output(["*"]).to_pl()
626+
table_obj.output(["*"]).to_pl()
635627
```
636628

637629
## Details
@@ -642,12 +634,12 @@ This method returns a data result in polars `DataFrame`
642634

643635
- `polars.DataFrame`
644636

645-
# query_builder.to_arrow
637+
# table_obj.output.to_arrow
646638

647639
Returns a pyarrow result.
648640

649641
```python
650-
table_obj.query_builder().output(["*"]).to_arrow()
642+
table_obj.output(["*"]).to_arrow()
651643
```
652644

653645
## Details

python/hello_infinity.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from infinity.common import REMOTE_HOST
1919
import pandas as pds
2020

21+
2122
def main():
2223
infinity_obj = infinity.connect(REMOTE_HOST)
2324
db = infinity_obj.get_database("default")
@@ -43,7 +44,7 @@ def test():
4344
db.drop_table("my_table", if_exists=True)
4445
# Create a table named "my_table"
4546
table = db.create_table("my_table", {
46-
"num": "integer", "body": "varchar", "vec": "vector, 4, float"}, None)
47+
"num": "integer", "body": "varchar", "vec": "vector, 4, float"}, None)
4748
table.insert(
4849
[{"num": 1, "body": "unnecessary and harmful", "vec": [1.0, 1.2, 0.8, 0.9]}])
4950
table.insert(
@@ -94,6 +95,7 @@ def test():
9495
# print("------tabular - querybuilder-------")
9596
# print(qb_result)
9697

98+
9799
if __name__ == '__main__':
98100
# main()
99101
test()

python/test/test_convert.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
from infinity.errors import ErrorCode
3+
14
from python.test.common import common_values
25
import infinity
36

@@ -52,4 +55,23 @@ def test_to_df(self):
5255
res = table_obj.output(["c1", "c1"]).to_df()
5356
print(res)
5457
res = table_obj.output(["c1", "c2", "c1"]).to_df()
55-
print(res)
58+
print(res)
59+
60+
@pytest.mark.skip(reason="Cause core dumped.")
61+
def test_without_output_select_list(self):
62+
# connect
63+
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
64+
db_obj = infinity_obj.get_database("default")
65+
db_obj.drop_table("test_without_output_select_list", True)
66+
table_obj = db_obj.create_table("test_without_output_select_list", {
67+
"c1": "int", "c2": "float"}, None)
68+
69+
table_obj.insert([{"c1": 1, "c2": 2.0}])
70+
insert_res = table_obj.output([]).convert_type
71+
# FIXME insert_res = table_obj.output([]).to_arrow()
72+
# FIXME insert_res = table_obj.output([]).to_pl()
73+
print(insert_res)
74+
75+
# disconnect
76+
res = infinity_obj.disconnect()
77+
assert res.error_code == ErrorCode.OK

python/test/test_insert.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def test_insert_big_varchar(self):
126126

127127
db_obj.drop_table("test_insert_big_varchar")
128128

129+
res = infinity_obj.disconnect()
130+
assert res.error_code == ErrorCode.OK
131+
129132
def test_insert_embedding(self):
130133
"""
131134
target: test insert embedding column
@@ -176,6 +179,7 @@ def test_insert_embedding(self):
176179

177180
db_obj.drop_table("test_insert_embedding2")
178181

182+
@pytest.mark.skip("Unexpected error.")
179183
def test_insert_big_embedding(self):
180184
"""
181185
target: test insert embedding with big dimension
@@ -197,6 +201,7 @@ def test_insert_big_embedding(self):
197201
res = table_obj.insert([{"c1": [-9999999] * 65535}])
198202
assert res.error_code == ErrorCode.OK
199203

204+
@pytest.mark.skip("Unexpected error.")
200205
def test_insert_big_embedding_float(self):
201206
"""
202207
target: test insert embedding float with big dimension
@@ -220,6 +225,23 @@ def test_insert_big_embedding_float(self):
220225
res = db_obj.drop_table("test_insert_big_embedding_float")
221226
assert res.error_code == ErrorCode.OK
222227

228+
@pytest.mark.skip("Unexpected error.")
229+
@pytest.mark.parametrize("types", ["vector,65535,int", "vector,65535,float"])
230+
@pytest.mark.parametrize("types_examples", [[{"c1": [1] * 65535}],
231+
[{"c1": [4] * 65535}],
232+
[{"c1": [-9999999] * 65535}],
233+
[{"c1": [1.1] * 65535}],
234+
[{"c1": [-9999999.988] * 65535}],
235+
])
236+
def test_insert_big_embedding_various_type(self, types, types_examples):
237+
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
238+
db_obj = infinity_obj.get_database("default")
239+
db_obj.drop_table("test_insert_big_embedding", True)
240+
table_obj = db_obj.create_table("test_insert_big_embedding", {
241+
"c1": types}, None)
242+
res = table_obj.insert(types_examples)
243+
assert res.error_code == ErrorCode.OK
244+
223245
def test_insert_exceed_block_size(self):
224246
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
225247
db_obj = infinity_obj.get_database("default")
@@ -458,7 +480,7 @@ def test_insert_with_invalid_data_type(self, batch, types):
458480

459481
# batch insert, with invalid column count
460482
@pytest.mark.parametrize("batch", [10, 1024])
461-
def test_insert_with_invalid_column_count(self, batch):
483+
def test_batch_insert_with_invalid_column_count(self, batch):
462484
# connect
463485
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
464486
db_obj = infinity_obj.get_database("default")

python/test/test_update.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_update_inserted_data(self):
327327
assert res.error_code == ErrorCode.OK
328328

329329
# update inserted long before and select to check
330-
@pytest.mark.skip(reason="May cause core dumped, and cost too much time.")
330+
@pytest.mark.skip(reason="Taking too much time.")
331331
def test_update_inserted_long_before(self):
332332
# connect
333333
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
@@ -353,7 +353,6 @@ def test_update_inserted_long_before(self):
353353
assert res.error_code == ErrorCode.OK
354354

355355
# update dropped table
356-
@pytest.mark.skip(reason="May cause core dumped.")
357356
def test_update_dropped_table(self):
358357
# connect
359358
infinity_obj = infinity.connect(common_values.TEST_REMOTE_HOST)
@@ -363,9 +362,10 @@ def test_update_dropped_table(self):
363362
db_obj.drop_table("test_update_inserted_long_before")
364363

365364
# update
366-
table_obj.update("c1 = 1", [{"c2": 21}])
367-
update_res = table_obj.output(["*"]).to_df()
368-
print(update_res)
365+
with pytest.raises(Exception, match="ERROR:3022*"):
366+
table_obj.update("c1 = 1", [{"c2": 21}])
367+
update_res = table_obj.output(["*"]).to_df()
368+
print(update_res)
369369

370370
# disconnect
371371
res = infinity_obj.disconnect()

0 commit comments

Comments
 (0)