Repository navigation
Sync Python SDK source - #19477
Sync Python SDK source#19477hongzhi-gao wants to merge 3 commits into
Conversation
| if self.__data_type == 5 or self.__data_type == 11: | ||
| if self.__data_type in (TSDataType.TEXT, TSDataType.STRING): | ||
| return self.value.decode("utf-8") | ||
| elif self.__data_type == TSDataType.OBJECT: |
There was a problem hiding this comment.
major iotdb-client/client-py/iotdb/utils/Field.py:196 — OBJECT field string/object accessors decode raw object binary as UTF-8
An OBJECT column value is [int64 objectSize][serialized IObjectPath] (see ObjectTypeUtils.parseObjectBinaryToSizeStringPathPair / readObjectContent(Binary,...)), not text. get_string_value() (line 196) and get_object_value(TSDataType.OBJECT) (line 236) do self.value.decode("utf-8"), so reading any OBJECT column through RowRecord/str(field) yields control characters plus the path, and raises UnicodeDecodeError for non-UTF-8 bytes (e.g. 4-byte region ids).
Fix: Return the raw bytes (or format size/path like Java's parseObjectByteArrayToString) instead of UTF-8 decoding the object binary, and cover it with a non-UTF-8 payload test.
There was a problem hiding this comment.
Fixed in 5f76d5034c. Field.get_object_value(OBJECT) now returns the raw result bytes, and str(field) uses the printable Python bytes representation. The regression test decodes a binary result containing non-UTF-8 bytes and checks both accessors.
| Raises: | ||
| IoTDBConnectionException: If there is an issue with the database connection. | ||
| """ | ||
| if isinstance(tablet, Tablet): |
There was a problem hiding this comment.
major iotdb-client/client-py/iotdb/table_session.py:119 — All multi-device Tablets are split per device, not only OBJECT tablets
_split_tablet_by_device_for_object never checks the data types (data_types is fetched at line 173 but unused, and the imported TSDataType is unused), so every Tablet whose rows have different tag values is split. A tablet like the ones in tests/integration/test_relational_session.py (15 distinct tags) previously used one insertTablet RPC; now N RPCs are sent and a failure after the first leaves earlier devices committed (partial insert). NumpyTablet is not split at all.
Fix: Return None early unless TSDataType.OBJECT in data_types, and either split NumpyTablet the same way or document that the object path only covers Tablet.
There was a problem hiding this comment.
Fixed in 5f76d5034c. The Python table session now sends the whole tablet through the existing connection for the table. This follows the Java client's behavior when all devices use the same connection. Tablet and NumpyTablet both use that path. The regression test checks one insertTablet RPC for a two-device batch, with both ordinary and OBJECT fields. I also verified multi-device OBJECT writes and readback against an OBJECT-enabled server.
| values_tobe_packed = [] | ||
| for cell in value: | ||
| if isinstance(cell, str): | ||
| if data_type == TSDataType.OBJECT: |
There was a problem hiding this comment.
minor iotdb-client/client-py/iotdb/utils/NumpyTablet.py:217 — NumpyTablet OBJECT column cannot represent null cells
For OBJECT columns get_binary_values raises TypeError("OBJECT column must be bytes (use add_value_object)") for any non-bytes cell, so a null cell expressed as None (plus a bitmap entry, as _copy_blob_column supports for BLOB) cannot be packed: NumpyTablet(..., data_types=[...OBJECT], values=[np.array([cell, None], dtype=object)], bitmaps=[bm]) fails inside insert() even after add_value_object was used for the other rows.
Fix: Treat None as an empty payload (b"") and let the bitmap mark the row null, matching the BLOB branch, and drop the misleading "use add_value_object" hint.
There was a problem hiding this comment.
Fixed in 5f76d5034c. A None cell marked in the bitmap now writes a zero-length placeholder, with the bitmap carrying the NULL flag. An unmarked None still raises TypeError. The regression test checks the packed bytes and the bitmap.
| "object_table", column_names, data_types, values, timestamps, column_types | ||
| ) | ||
| tablet.add_value_object(0, 4, True, 0, b"payload-bytes") | ||
| assert tablet.get_binary_values() is not None |
There was a problem hiding this comment.
minor iotdb-client/client-py/tests/unit/test_object_column.py:65 — OBJECT packing test asserts only non-None output
assert tablet.get_binary_values() is not None cannot fail (the method returns bytes or raises), so a wrong OBJECT header/length prefix, a dropped column_types entry, or a mis-encoded cell would still pass. The new _split_tablet_by_device_for_object helper and the OBJECT query decoders (Field, read_binary_column) have no unit tests either.
Fix: Assert the exact packed bytes (or run decode_object_cell over the packed column), and add tests for the tablet-split helper and OBJECT result decoding.
There was a problem hiding this comment.
Fixed in 5f76d5034c. The packing test now compares the complete serialized buffer. The new tests verify the RPC count, row count, column categories, and request payload for multi-device batches, and exercise the binary OBJECT decoder with non-UTF-8 bytes.
| if timestamps.dtype != TSDataType.INT64.np_dtype(): | ||
| timestamps = timestamps.astype(TSDataType.INT64.np_dtype()) | ||
| for i, data_type in enumerate(data_types): | ||
| if data_type == TSDataType.OBJECT: |
There was a problem hiding this comment.
minor - OBJECT columns can be silently truncated for fixed-width byte arrays
The constructor skips dtype normalization for OBJECT columns. If one is backed by a fixed-width NumPy byte array (for example, dtype="S1"), add_value_object() assigns the encoded header and payload into that fixed-width slot; NumPy silently truncates it, and get_binary_values() then serializes the corrupted bytes.
Please normalize OBJECT arrays to dtype=object (or reject a non-object dtype) before writing cells, and add a regression test for this case.
There was a problem hiding this comment.
Fixed in 5f76d5034c. NumpyTablet now normalizes OBJECT columns to NumPy object dtype before add_value_object() assigns a cell. The regression test starts with an S1 array and checks that the full header and payload, including a trailing zero byte, are serialized.
|
minor
Fix: Add |
Summary
OBJECTtablet writes and query result decoding. Keep IoTDB's default login credentials.tablet.add_value_object(0, 1, True, 0, b"data")encodes a completeOBJECTvalue at offset zero in row 0, column 1.Testing
python3 -m pytest -q tests/unit(73 passed)