timeplus-io / timeplus-cpp

Timeplus C++ client
Apache License 2.0
1 stars 0 forks source link

The client failed to properly handle the insertion of illegal decimal data #8

Closed Jax-YHH closed 3 months ago

Jax-YHH commented 3 months ago

When the input data contains integers that exceed the bit range, the client does not handle them correctly, resulting in actual inserted data that is inconsistent with expectations. (in the Timeplusd-client, an error message will be prompted when act like this ) eg: insert 999999999 into decimal32(9,4), result is 131612.4912

void InsertTask(const ClientOptions& client_options, const size_t start_index, const size_t end_index) {
    try {
        Client client(client_options);

        // Create a table for each thread if necessary (optional, depends on the use case)
        client.Execute("DROP STREAM IF EXISTS test_insert");
        client.Execute("CREATE STREAM IF NOT EXISTS test_insert (id uint64, str string, d32 decimal32(4))");

        for (size_t i = start_index; i < end_index; ++i) {
            Block block;

            auto id = std::make_shared<ColumnUInt64>();
            auto s = std::make_shared<ColumnString>();
            auto d32 = std::make_shared<ColumnDecimal>(9,4);

            id->Append(static_cast<std::uint64_t>(i + 1));
            s->Append(std::to_string(i + 1));
            d32->Append(static_cast<std::string>("999999999"));

            block.AppendColumn("id", id);
            block.AppendColumn("str", s);
            block.AppendColumn("d32", d32);
            client.Insert("test_insert", block);
        }
    } catch (const std::exception& e) {
        std::cerr << "Thread " << std::this_thread::get_id() << " encountered an error: " << e.what() << std::endl;
    }
}

image

Jax-YHH commented 3 months ago

How should I handle the insertion when the integer part exceeds the specified number of digits?

1 retain the maximum number of digits for the integer, and treat the remaining part as a decimal.

2 or just throw invalid operation warning and not insert it.

Jax-YHH commented 3 months ago

The current approach is to throw an exception and not perform any operation.