From 0f21e9c12b811890125febcbebbf741f10c6718b Mon Sep 17 00:00:00 2001 From: DaZuiZui Date: Wed, 2 Dec 2026 00:05:36 +0800 Subject: [PATCH] Fix numeric run-length column decoding in the Python client Generated-by: OpenAI Codex --- .../iotdb/tsfile/utils/tsblock_serde.py | 5 +- .../tests/unit/test_run_length_column.py | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 iotdb-client/client-py/tests/unit/test_run_length_column.py diff --git a/iotdb-client/client-py/iotdb/tsfile/utils/tsblock_serde.py b/iotdb-client/client-py/iotdb/tsfile/utils/tsblock_serde.py index cc5577e885c62..027eb2cd8b27b 100644 --- a/iotdb-client/client-py/iotdb/tsfile/utils/tsblock_serde.py +++ b/iotdb-client/client-py/iotdb/tsfile/utils/tsblock_serde.py @@ -237,10 +237,7 @@ def repeat(column, data_type, position_count): else: return np.array(column * position_count, dtype=object) else: - res = bytearray() - for _ in range(position_count): - res.extend(column if isinstance(column, bytes) else bytes(column)) - return bytes(res) + return column.repeat(position_count) def read_dictionary_column(buffer, data_type, position_count): diff --git a/iotdb-client/client-py/tests/unit/test_run_length_column.py b/iotdb-client/client-py/tests/unit/test_run_length_column.py new file mode 100644 index 0000000000000..dc209d909505b --- /dev/null +++ b/iotdb-client/client-py/tests/unit/test_run_length_column.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import struct + +import pytest + +from iotdb.utils.SessionDataSet import SessionDataSet + + +@pytest.fixture +def constant_int32_result(): + # One INT32 column, two rows. The time column is plain INT64 and the + # value column uses RLE with a single non-null INT32 inside it. + header = struct.pack(">iBiBB", 1, 1, 2, 2, 4) + timestamps = struct.pack(">?qq", False, 1, 2) + constant = struct.pack(">B?i", 1, False, 42) + return SessionDataSet( + sql="select 42 as v from t", + column_name_list=["v"], + column_type_list=["INT32"], + column_name_index={"v": 0}, + query_id=1, + statement_id=1, + client=None, + session_id=1, + query_result=[header + timestamps + constant], + ignore_timestamp=True, + time_out=0, + more_data=False, + fetch_size=100, + zone_id="UTC", + time_precision="ms", + column_index_2_tsblock_column_index_list=[0], + ) + + +def test_run_length_int32_rows(constant_int32_result): + values = [] + while constant_int32_result.has_next(): + row = constant_int32_result.next() + values.append(row.get_fields()[0].get_int_value()) + assert values == [42, 42] + + +def test_run_length_int32_dataframe(constant_int32_result): + assert constant_int32_result.todf()["v"].tolist() == [42, 42]