Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
338 stars 61 forks source link

Appender treating decimal column as bool? #166

Closed mosiman closed 5 months ago

mosiman commented 5 months ago

Hi. I'm using version 0.9.2 of DuckDB.NET.Data.Full on an M1 Macbook Air. With a minimal Program.cs I am unable to build, as the appender thinks the column should be bool when it actually should be a decimal.

// Program.cs
using (var conn = new DuckDB.NET.Data.DuckDBConnection("Data Source=:memory:"))
{
    conn.Open();

    using var command = conn.CreateCommand();

    command.CommandText = "CREATE TABLE IF NOT EXISTS table_with_decimal (id INTEGER, val DECIMAL(18, 8));";
    command.ExecuteNonQuery();

    using (var appender = conn.CreateAppender("table_with_decimal"))
    {
        var n = 10;
        for (var i = 0; i < n; i++)
        {
            var row = appender.CreateRow();
            row.AppendValue(i).AppendValue(i * 0.1m);
            row.EndRow();
        }
    }

}

When I try to dotnet build, I get the following error:

(nix:nix-shell-env) Dillons-Air:duckdb_net_appender_decimal_bug mosiman$ dotnet build
MSBuild version 17.7.4+3ebbd7c49 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/Users/mosiman/tmp/duckdb_net_appender_decimal_bug/Program.cs(16,44): error CS1503: Argument 1: cannot convert from 'decimal' to 'bool?' [/Users/mosiman/tmp/duckdb_net_appender_decimal_bug/duckdb_net_appender_decimal_bug.csproj]

Build FAILED.

/Users/mosiman/tmp/duckdb_net_appender_decimal_bug/Program.cs(16,44): error CS1503: Argument 1: cannot convert from 'decimal' to 'bool?' [/Users/mosiman/tmp/duckdb_net_appender_decimal_bug/duckdb_net_appender_decimal_bug.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.85

Please let me know if any more information is needed to reproduce. Thanks for all your work on this library 🙌

Giorgi commented 5 months ago

You get that error because no AppendValue overload takes a decimal? There is no such method in the Appender Api

mosiman commented 5 months ago

oh, I didn't actually look at the original appender API. just sort of assumed it would have a method for that but I guess it doesn't. thanks for clearing that up!

Giorgi commented 5 months ago

It can probably be implemented with duckdb_append_data_chunk but I haven't looked into it.