Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use ColumnTuple with ColumnArrayT? #397

Closed
howlotus opened this issue Oct 3, 2024 · 1 comment
Closed

how to use ColumnTuple with ColumnArrayT? #397

howlotus opened this issue Oct 3, 2024 · 1 comment

Comments

@howlotus
Copy link

howlotus commented Oct 3, 2024

With regular columns everything is ok (ColumnString, ColumnInt64, etc), with arrays of regular types everything is ok (ColumnArrayT, ColumnArrayT), with simple tuples it is also clear (ColumnTuple), but ColumnArrayT cannot be created.
Now I am trying to collect all references to tuples and create an array, but I get an array of a size that CH cannot process.

std::vector<ColumnRef> _refs = std::vector<ColumnRef>();
for (const auto& row: rows) {
    std::shared_ptr<ColumnInt64> item1 = std::make_shared<ColumnInt64>();
    std::shared_ptr<ColumnFloat32> item2 = std::make_shared<ColumnFloat32>();
    for (const auto& item: items) {
        item1 -> Append(item.item1);
        item2 -> Append(item.item2);
    }
    _refs.push_back(std::make_shared<ColumnTuple>(std::vector<ColumnRef>({item1, item2})));
}
std::shared_ptr<ColumnArrayT<ColumnTuple>> tuplesArray = std::make_shared<ColumnArrayT<ColumnTuple>>(_refs);

Got error: fail to send 11984 bytes of data: Operation now in progress

Please help me what is the correct approach for this? As I understand it, the library has no documentation for this.

@howlotus
Copy link
Author

solved.

std::shared_ptr<ColumnArrayT<ColumnTuple>> tuplesArray = std::make_shared<ColumnArrayT<ColumnTuple>>(
    std::make_shared<ColumnTuple>(
        std::vector<ColumnRef>({
            std::make_shared<ColumnInt64>(),
            std::make_shared<ColumnFloat32>()
        })
    )
)

for (const auto& row: rows) {
    auto it = std::make_shared<ColumnTuple>(
        std::vector<ColumnRef>({
            std::make_shared<ColumnInt64>(),
            std::make_shared<ColumnFloat32>()
        })
    );

    for (const auto& item: items) {
        (*it)[0] -> As<ColumnInt64>() -> Append(item.item1);
        (*it)[1] -> As<ColumnFloat32>() -> Append(item.item2);
    }
    tuplesArray -> As<ColumnArrayT<ColumnTuple>>() -> AppendAsColumn(it);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant