Skip to content

[Bug] Python client misreads run-length encoded numeric query columns #19484

Backlog

Description

@DaZuiZui

Search before asking

  • I searched the existing issues for this problem.

Version

IoTDB server 2.0.12, table model. Tested with the PyPI apache-iotdb==2.0.12 client and with Python client source at 92efb381eee5968236383cdc422766537b20b0af on macOS 15.3.2, Python 3.12.

Describe the bug and provide the minimal reproduce step

A numeric constant in a table query can be returned as a run-length encoded (RLE) TsBlock column. The Python client misreads this column when iterating rows and fails to convert it to a DataFrame.

Create a table in a fresh test database using the table SQL dialect:

CREATE DATABASE rle_example;
USE rle_example;
CREATE TABLE readings (device STRING TAG, v INT32 FIELD);
INSERT INTO readings (time, device, v) VALUES (1, 'a', 11), (2, 'a', 22);

With a Python TableSession connected to rle_example, run the same query twice to get a fresh result for each reader:

sql = "SELECT 42 AS label FROM readings"
with session.execute_query_statement(sql) as result:
    print([row.get_fields()[0].get_int_value() for row in iter(result.next, None)])
with session.execute_query_statement(sql) as result:
    print(result.todf()["label"].tolist())

What did you expect to see?

Both calls should return [42, 42], one integer per input row. With SELECT v, 42 AS label FROM readings, the Java CLI returns (11, 42) and (22, 42).

What did you see instead?

Python client Row iteration todf()
92efb381ee [0, 0, 0, 42, 0, 0, 0, 42] (eight rows) AttributeError: 'bytes' object has no attribute 'dtype'
PyPI 2.0.12 AttributeError: 'bytes' object has no attribute 'dtype' Same exception

With SELECT v, 42 AS label FROM readings, row iteration at 92efb381ee silently returns (11, 0) and (22, 0). The ordinary column limits the result to two rows and masks the row-count error.

Anything else?

The numeric branch of repeat() receives a typed NumPy array, converts it to bytes and concatenates those bytes once per position. For an INT32 value of 42, each copy contributes four bytes (00 00 00 2a). The row reader iterates those bytes individually, and the DataFrame reader tries to access their missing .dtype. An ordinary INT32 column with the same two values decodes correctly. RLE decoder

The proposed fix is to repeat the elements of the numeric array with column.repeat(position_count), preserving the dtype and the existing null bitmap. A regression test should check the values and row count through both public readers.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Prepared with assistance from OpenAI Codex.

Activity

  1. DaZuiZui commented on Dec 1, 2026

    @DaZuiZui
    ContributorAuthor

    The same decoding bug also affects FLOAT, INT64, and DOUBLE. With two non-null values in a single RLE column, row iteration at 92efb381ee returned 8 rows for FLOAT and 16 for INT64 and DOUBLE. Calling todf() on a fresh result raised the same AttributeError for all three.

    I also checked two SQL projections against IoTDB 2.0.12 using the two-row readings table from the report:

    Projection Before the fix With #19485
    CAST('2025-11-23' AS DATE) Reading the dates failed with Invalid date format; todf() raised TypeError. Both readers returned two copies of 2025-11-23.
    CAST(1000 AS TIMESTAMP) Both readers returned 16 timestamps for two input rows. Both readers returned two timestamps, each 1000 ms after the Unix epoch.

    The server sent these DATE and TIMESTAMP constants as RLE columns containing INT32 and INT64 values, respectively. Local checks with the patch returned the expected values and row counts for all affected types above. The tested non-null BOOLEAN, TEXT, STRING, and BLOB constants returned the expected two rows both before and after the patch.

  2. DaZuiZui commented on Dec 1, 2026

    @DaZuiZui
    ContributorAuthor

    Confirmed on 12m2d, 2026y with the latest PyPI release and current upstream master, both against an IoTDB 2.0.12 server. For a table-model query projecting the INT32 literal 43, the server returned a run-length encoded column. The Python decoder expanded the value as raw bytes.

    • PyPI apache-iotdb==2.0.12: row iteration and todf() both raised AttributeError: 'bytes' object has no attribute 'dtype'.
    • Upstream master at 585d88d72ed217846eee813986ca76a772d53a82: row iteration silently returned individual bytes as values, producing incorrect values and extra rows. todf() raised the same exception.

    Both clients read the ordinary INT32 measurement column in the same table correctly. The expected result for the literal is one integer 43 per input row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions