This is an automated email from the ASF dual-hosted git repository.
HTHou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new b0ce164b614 [Python] Keep NumpyTablet null bitmaps aligned when
sorting timestamps (#19403)
b0ce164b614 is described below
commit b0ce164b614a602ec4e8bd73346219d591a89a66
Author: DaZuiZui <[email protected]>
AuthorDate: Fri Nov 27 12:16:22 2026 +0800
[Python] Keep NumpyTablet null bitmaps aligned when sorting timestamps
(#19403)
* Keep NumpyTablet null bitmaps aligned when sorting timestamps
* Vectorize NumpyTablet bitmap sorting and release value columns
incrementally
---
iotdb-client/client-py/iotdb/utils/NumpyTablet.py | 17 ++++++++++++++
.../client-py/tests/unit/test_numpy_tablet.py | 27 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/iotdb-client/client-py/iotdb/utils/NumpyTablet.py
b/iotdb-client/client-py/iotdb/utils/NumpyTablet.py
index 9a0860d3a43..b484d12e055 100644
--- a/iotdb-client/client-py/iotdb/utils/NumpyTablet.py
+++ b/iotdb-client/client-py/iotdb/utils/NumpyTablet.py
@@ -74,6 +74,8 @@ class NumpyTablet(object):
timestamps = timestamps[index]
for i in range(len(values)):
values[i] = values[i][index]
+ if bitmaps is not None:
+ bitmaps = [self._sort_bitmap(bitmap, index) for bitmap in
bitmaps]
if timestamps.dtype != TSDataType.INT64.np_dtype():
timestamps = timestamps.astype(TSDataType.INT64.np_dtype())
@@ -96,6 +98,21 @@ class NumpyTablet(object):
else:
self.__column_types = column_types
+ @staticmethod
+ def _sort_bitmap(bitmap, index):
+ if bitmap is None:
+ return None
+ sorted_bitmap = BitMap(bitmap.get_size())
+ if not bitmap.is_all_unmarked():
+ packed = np.asarray(bitmap.bits, dtype=np.uint8)
+ # BitMap stores the first row in the low bit of each byte.
+ rows = np.unpackbits(packed).reshape(-1, 8)[:, ::-1]
+ sorted_rows = np.zeros(rows.size, dtype=np.uint8)
+ sorted_rows[: len(index)] = rows.flat[index]
+ sorted_bytes = np.packbits(sorted_rows.reshape(-1, 8)[:, ::-1])
+ sorted_bitmap.bits = sorted_bytes.tolist()
+ return sorted_bitmap
+
@staticmethod
def check_sorted(timestamps):
for i in range(1, len(timestamps)):
diff --git a/iotdb-client/client-py/tests/unit/test_numpy_tablet.py
b/iotdb-client/client-py/tests/unit/test_numpy_tablet.py
index 217df22ea2d..812e93a0534 100644
--- a/iotdb-client/client-py/tests/unit/test_numpy_tablet.py
+++ b/iotdb-client/client-py/tests/unit/test_numpy_tablet.py
@@ -17,6 +17,7 @@
#
import numpy as np
+import pytest
from iotdb.utils.BitMap import BitMap
from iotdb.utils.IoTDBConstants import TSDataType
@@ -153,6 +154,32 @@ def test_sort_numpy_tablet():
assert tablet_.get_binary_values() == np_tablet_.get_binary_values()
[email protected]("row_count", [8, 9])
+def test_sort_numpy_tablet_with_null_bitmaps(row_count):
+ timestamps = [row_count, *range(1, row_count)]
+ columns = ["a", "b", "c"]
+ types = [TSDataType.INT32] * len(columns)
+ first_nulls = BitMap(len(timestamps))
+ first_nulls.mark(0) # The null moves to bit 7 or 8.
+ second_nulls = BitMap(len(timestamps))
+ second_nulls.mark(1)
+ rows = [
+ (None if t == row_count else t, None if t == 1 else t, t) for t in
timestamps
+ ]
+ expected = Tablet("root.sg.d", columns, types, rows, timestamps)
+ tablet = NumpyTablet(
+ "root.sg.d",
+ columns,
+ types,
+ [np.array([0 if v is None else v for v in column]) for column in
zip(*rows)],
+ np.array(timestamps),
+ [first_nulls, second_nulls, None],
+ )
+
+ assert tablet.get_binary_timestamps() == expected.get_binary_timestamps()
+ assert tablet.get_binary_values() == expected.get_binary_values()
+
+
def test_numpy_tablet_auto_correct_datatype():
measurements_ = ["s_01", "s_02", "s_03", "s_04", "s_05", "s_06"]