Skip to content

[C++] An unstable crash may appears when reading table from a json file. #20253

Open

Description

@asfimport

An unstable crash may appears when reading table from a json file.

arrow and parquet are installed by apt-get.

g++ test_arrow_json.cpp -o test_arrow_json -larrow -lparquet && ./test_arrow_json

/build/apache-arrow-8.0.0/cpp/src/arrow/result.cc:28: ValueOrDie called on an error: NotImplemented: JSON conversion to struct<timestamp_deprecated: int64, traffic_light_id: timestamp[s], camera_id: timestamp[s], camera_center_timestamp: int64, camera_trigger_timestamp: int64, tl_yaw_diff: int64, distance: int64, color: timestamp[s], shape: timestamp[s], score: int64, flashing: bool, occluded: bool, occlusion_ratio: int64, raw_color: timestamp[s], temporal_fused_color: timestamp[s], temporal_fused_flashing: bool, state_source: timestamp[s], x: int64, y: int64, width: int64, height: int64, original_width: int64, original_height: int64, light_body_bboxes: list<item: struct<x: int64, y: int64, width: int64, height: int64>>, light_bboxes: list<item: struct<x: int64, y: int64, width: int64, height: int64>>, countdown: timestamp[s]> is not supported
/usr/lib/x86_64-linux-gnu/libarrow.so.800(+0x39e131)[0x7f07b843e131]
/usr/lib/x86_64-linux-gnu/libarrow.so.800(_ZN5arrow4util8ArrowLogD1Ev+0xdd)[0x7f07b878e83d]
/usr/lib/x86_64-linux-gnu/libarrow.so.800(_ZN5arrow8internal17InvalidValueOrDieERKNS_6StatusE+0x17d)[0x7f07b8626e8d]
./test_arrow_json(+0x1b9b)[0x5613e4b53b9b]
./test_arrow_json(+0x12f2)[0x5613e4b532f2]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f07b772fc87]
./test_arrow_json(+0xfba)[0x5613e4b52fba]
Aborted (core dumped)

Reporter: Jack Tondon

Original Issue Attachments:

Note: This issue was originally created as ARROW-16615. Please see the migration documentation for further details.

Activity

  1. asfimport commented on May 19, 2022

    @asfimport
    Author

    Antoine Pitrou / @pitrou:
    Hmm... are you complaining about the crash or about the error?

    As the name implies, the ValueOrDie method will abort the process if the Result<T> instance contains an error instead of a successful result. This is also explained in the method documentation:
    https://arrow.apache.org/docs/cpp/api/support.html?highlight=valueordie#_CPPv4NKR5arrow6Result10ValueOrDieEv

    This method should only be called if this Result object’s status is OK (i.e. a call to ok() returns true), otherwise this call will abort.

  2. asfimport commented on May 19, 2022

    @asfimport
    Author

    Antoine Pitrou / @pitrou:
    The file does succeed loading in PyArrow here, though. Or is the problem you see sporadic?

  3. asfimport commented on May 19, 2022

    @asfimport
    Author

    Antoine Pitrou / @pitrou:
    Ok, this can be reproduced in PyArrow when the block size is a bit too small.

    With a much too small block size, one gets the expected error:

    >>> tab = json.read_json("test.json", read_options=json.ReadOptions(block_size=4096*2))
    Traceback (most recent call last):
      ...
    ArrowInvalid: straddling object straddles two block boundaries (try to increase block size?)

    With a large enough block size, reading the JSON file succeeds:

    >>> tab = json.read_json("test.json", read_options=json.ReadOptions(block_size=4096*128))
    >>> tab.column_names
    ['run_name', 'pose_proto', 'traffic_light_states_proto']
    >>> tab.num_rows
    1890

    But with a block size that's somewhat in-between, reading the JSON file fails with that unexpected unsupported conversion error:

    >>> tab = json.read_json("test.json", read_options=json.ReadOptions(block_size=4096*16))
    Traceback (most recent call last):
      ...
    ArrowNotImplementedError: JSON conversion to struct<timestamp_deprecated: int64, traffic_light_id: timestamp[s], camera_id: timestamp[s], camera_center_timestamp: int64, camera_trigger_timestamp: int64, tl_yaw_diff: int64, distance: int64, color: timestamp[s], shape: timestamp[s], score: int64, flashing: bool, occluded: bool, occlusion_ratio: int64, raw_color: timestamp[s], temporal_fused_color: timestamp[s], temporal_fused_flashing: bool, state_source: timestamp[s], x: int64, y: int64, width: int64, height: int64, original_width: int64, original_height: int64, light_body_bboxes: list<item: struct<x: int64, y: int64, width: int64, height: int64>>, light_bboxes: list<item: struct<x: int64, y: int64, width: int64, height: int64>>, countdown: timestamp[s]> is not supported

    @bkietz Is this something that you know might happen?

  4. asfimport commented on May 20, 2022

    @asfimport
    Author

    Jack Tondon:
    Sorry for the late response. The problem is sporadic with default ReadOptions. As you see, arrow infer that traffic_light_id is a timestamp type, but I do sure that it's a string, and other string fields, such as camera_id, are also be infered as timestamp.

  5. asfimport commented on May 20, 2022

    @asfimport
    Author

    Jack Tondon:
    Seems with use_threads=false, the problem reappears stably

  6. added
    Status: confirmed
    on Nov 9, 2026
  7. thisisnic commented on Nov 9, 2026

    @thisisnic
    Member

    Still reproduces, needs more investigation, AI analysis below but requires verification


    Still reproduces on 26.0.1 with the attached test.json: default options fail about half the time, use_threads=False fails every
    time. The error is always ArrowNotImplementedError: JSON conversion to struct<...> is not supported; it never produces a table with wrong column types.

    The timestamp[s] types in the message are a red herring (strings are inferred as timestamp first and widened to utf8 later). The
    actual cause is in cross-block type promotion. When a block's conversion fails, chunked_builder.cc calls Promote() on the leaf
    builder. For a column whose type was fixed as null by an earlier block, Promote() falls through to Infer(), which returns a
    struct or list type if the value in the new block is an object or array. That type is then passed to MakeConverter(), which has no
    struct or list case and returns NotImplemented. Which block fixes the type first depends on block boundaries and thread scheduling,
    hence the sporadic behaviour.

    Fix needed: a null-typed leaf builder promoted to a nested type should get a nested chunked builder instead of a leaf converter.
    Regression test: a column that is null in block 1 and an object in block 2. Retitled to reflect this.

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

    Component: C++Status: confirmedType: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions