You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/UserGuide/Master/Table/API/Programming-Python-Native-API_timecho.md
+181-2Lines changed: 181 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,19 @@ if has_next:
66
66
67
67
**Note:** Avoid mixing different traversal methods (e.g., combining `todf()` with `next_df()`), which may cause unexpected errors.
68
68
69
+
**Since V2.0.8.3**, the Python client has supported `TSDataType.OBJECT` for Tablet batch write and Session value serialization. Query results are read via the `Field` object. The related interfaces are defined as follows:
70
+
71
+
| Function Name | Description | Parameters | Return Value |
|`encode_object_cell`| Encodes a single OBJECT cell into wire-format bytes |`is_eof: bool`,<br>`offset: int`,<br>`content: bytes`|`bytes`: `|[eof 1B]|[offset 8B BE]|[payload]|` |
74
+
|`decode_object_cell`| Parses a wire-format cell back into `eof`, `offset`, and `payload`|`cell: bytes` (length ≥ 9) |`Tuple[bool, int, bytes]`: `(is_eof, offset, payload)`|
75
+
|`Tablet.add_value_object`| Writes an OBJECT cell at the specified row and column (internally calls `encode_object_cell`) |`row_index: int`,<br>`column_index: int`,<br>`is_eof: bool`,<br>`offset: int`,<br>`content: bytes`|`None`|
76
+
|`Tablet.add_value_object_by_name`| Same as above, locates column by name |`column_name: str`,<br>`row_index: int`,<br>`is_eof: bool`,<br>`offset: int`,<br>`content: bytes`|`None`|
77
+
|`NumpyTablet.add_value_object`| Same semantics as `Tablet.add_value_object`, column data is stored as `ndarray`| Same as above (`row_index`, `column_index`, ...) |`None`|
78
+
|`Field.get_object_value`| Converts the value to a Python value based on the **target type**|`data_type: TSDataType`| Depends on type:<br>For OBJECT: `str` decoded from the entire `self.value` in UTF-8 (see Field.py) |
79
+
|`Field.get_string_value`| Returns a string representation | None |`str`;<br>For OBJECT: `self.value.decode("utf-8")`|
80
+
|`Field.get_binary_value`| Gets the binary data of TEXT/STRING/BLOB | None |`bytes` or `None`;<br>**Throws an error for OBJECT columns and should not be called**|
81
+
69
82
70
83
#### Sample Code
71
84
@@ -511,7 +524,7 @@ def query_data():
511
524
while res.has_next():
512
525
print(res.next())
513
526
514
-
print("get data from table1")
527
+
print("get data from table1")
515
528
with session.execute_query_statement("select * from table1") as res:
516
529
while res.has_next():
517
530
print(res.next())
@@ -521,7 +534,7 @@ def query_data():
521
534
with session.execute_query_statement("select * from table0") as res:
522
535
while res.has_next_df():
523
536
print(res.next_df())
524
-
537
+
525
538
session.close()
526
539
527
540
@@ -571,3 +584,169 @@ session_pool.close()
571
584
print("example is finished!")
572
585
```
573
586
587
+
**Object Type Usage Example**
588
+
589
+
```python
590
+
import os
591
+
592
+
import numpy as np
593
+
import pytest
594
+
595
+
from iotdb.utils.IoTDBConstants import TSDataType
596
+
from iotdb.utils.NumpyTablet import NumpyTablet
597
+
from iotdb.utils.Tablet import Tablet, ColumnType
598
+
from iotdb.utils.object_column import decode_object_cell
599
+
600
+
601
+
def_require_thrift():
602
+
pytest.importorskip("iotdb.thrift.common.ttypes")
603
+
604
+
605
+
def_session_endpoint():
606
+
host = os.environ.get("IOTDB_HOST", "127.0.0.1")
607
+
port =int(os.environ.get("IOTDB_PORT", "6667"))
608
+
return host, port
609
+
610
+
611
+
@pytest.fixture(scope="module")
612
+
deftable_session():
613
+
_require_thrift()
614
+
from iotdb.Session import Session
615
+
from iotdb.table_session import TableSession, TableSessionConfig
0 commit comments