Skip to content

Nested tables support #40

Open

Description

@Ryssiouk11B

If I have simple table like this:

CREATE TABLE test.nested
(
account UInt64,
Orders Nested(
id UInt64,
order_id String)
)
ENGINE = MergeTree
ORDER BY account

account │ UInt64
Orders.id │ Array(UInt64)
Orders.order_id │ Array(String)

How I can insert data into this table using clickhouse-cpp API? I’m working with Orders.id and Orders.order_id columns as arrays but when method block.AppendColumn called, I’m getting exception:
all columns in block must have same count of rows.

Is there any existing workaround or plans to extend API for nested tables support?

Activity

  1. rpopescu commented on Oct 19, 2020

    @rpopescu
    Contributor

    @Ryssiouk11B is there a solution for this?
    tagging also @Enmk
    much appreciated!

  2. Ryssiouk11B commented on Oct 20, 2020

    @Ryssiouk11B
    Author
  3. rpopescu commented on Oct 20, 2020

    @rpopescu
    Contributor

    No, that's not an option. We need to push a lot of data in the shortest time possible (for example, reusing blocks, appending lots of rows before doing an insert), and also consume it in the shortest time possible and in an optimal format.

  4. romanholidaypancakes commented on Jun 22, 2022

    @romanholidaypancakes
    Contributor

    hi, is this still unusable?

  5. den818 commented on Nov 27, 2022

    @den818
    Contributor

    I try to write a simple test. And it works. Could you describe the case in more detail?

        client_->Execute("DROP TEMPORARY TABLE IF EXISTS test_clickhouse_nested;");
        client_->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS test_clickhouse_nested "
            " (account UInt64, Orders Nested(id UInt64, order_id String) )");
        auto account = std::make_shared<ColumnUInt64>();
        account->Append(1);
        account->Append(2);
        auto orders_id = std::make_shared<ColumnArrayT<ColumnUInt64>>();
        orders_id->Append({1, 2, 3, 4, 5});
        orders_id->Append({10, 20, 30, 40, 50, 60});
        auto orders_order_id = std::make_shared<ColumnArrayT<ColumnString>>();
        orders_order_id->Append({"a", "b", "c", "d", "e"});
        orders_order_id->Append({"A", "B", "C", "D", "E", "F"});
    
        Block b;
        b.AppendColumn("account", account);
        b.AppendColumn("Orders.id", orders_id);
        b.AppendColumn("Orders.order_id", orders_order_id);
    
        client_->Insert("test_clickhouse_nested", b);
    
        client_->Select("SELECT * FROM test_clickhouse_nested",
            [](const Block& block) {
                std::cerr << PrettyPrintBlock{block} << std::endl;
            }
        );
    
    +---------+--------------------------+--------------------+
    | account |     Orders.id            | Orders.order_id    |
    +---------+--------------------------+--------------------+
    |  UInt64 | Array(UInt64)            |   Array(String)    |
    +---------+--------------------------+--------------------+
    |       1 | [1, 2, 3, 4, 5]          | [a, b, c, d, e]    |
    |       2 | [10, 20, 30, 40, 50, 60] | [A, B, C, D, E, F] |
    +---------+--------------------------+--------------------+
    
  6. iso01 commented on May 13, 2025

    @iso01

    I need to support arbitrary level of nested structures. Lets complicated above Orders example with yet another nested layer:

    test_clickhouse_nested (account UInt64, Orders Nested(id UInt64, order_id String, Items Nested(id UInt64, description String)))

    What code should I write in this case?

  7. iso01 commented on May 15, 2025

    @iso01

    If I add

    client_->Execute("set flatten_nested=0;");
    

    then a table with arbitrary levels of nested types can be created.
    However if try a code inserting a tuple into nested column, I get unsupported exception:

    Caught exception: unsupported column type: Nested(id UInt64, order_id String)
    

    Presumably the nested columns are not supported by the c++ client at all.

    The case with flatten_nested=1 and replacing true nested types by arrays is not what I need.

  8. polyglotAI-bot commented on Nov 19, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed: review PR #575
    With the diff of PR #575, select and insert of a Nested(...) column work. The PR closes only #571: add Closes #40 to it, so that this issue closes when it merges.

    Analysis: With flatten_nested = 1 (the server default), the server stores a Nested column as Array columns, and the library already inserts and selects them; the error in the report comes from Block::AppendColumn (clickhouse/block.cpp:59) when the columns of a block have different row counts. With flatten_nested = 0, the server sends the type name Nested(...), which TypeParser does not know (clickhouse/types/type_parser.cpp:120), so Client throws (clickhouse/client.cpp:869). PR #575 creates such a column as Array(Tuple(...)), the same structure as the server's DataTypeNested.

    Automated triage by Polyglot AI. A maintainer makes the final decision. Shortened on 2026-11-20: the edit history has the first version.

  9. added
    data-typesArea: type names, value encoding and decoding, row mapping, data formats
    on Nov 19, 2026
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

    data-typesArea: type names, value encoding and decoding, row mapping, data formatsenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions