tomasfabian / ksqlDB.RestApi.Client-DotNet

ksqlDb.RestApi.Client is a C# LINQ-enabled client API for issuing and consuming ksqlDB push and pull queries and executing statements.
MIT License
93 stars 24 forks source link

c# decimal is mapped to STRUCT type. #81

Closed mrt181 closed 4 weeks ago

mrt181 commented 1 month ago

Describe the bug When I define a Property like this:

[JsonPropertyName("volume")]
[Decimal(20,8)]
public decimal Volume { get; set; }

The created statement during an insert uses this type

`volume` := STRUCT()

The volume property is within an ARRAY[STRUCT()] type that itself is within an ARRAY[STRUCT] type. When I change the property type to double it uses the DECIMAL(20,8) in the insert statement.

Expected behavior The DECIMAL(20,8) type should be used when the property has that attribute even when its c# type is decimal.

Environment (please complete the following information):

tomasfabian commented 1 month ago

Hi @mrt181, could you please confirm that the expected generated KSQL statement should match the following?

INSERT INTO Amounts (volume) VALUES (1.12345678912345);
private record Amount
{
  [JsonPropertyName("volume")]
  [Decimal(20, 8)]
  public decimal Volume { get; init; }
}

var amount = new Amount
{
  Volume = 1.12345678912345M,
};

string statement = new CreateInsert(new ModelBuilder()).Generate(amount);
mrt181 commented 1 month ago

Hi @mrt181, could you please confirm that the expected generated KSQL statement should match the following?

INSERT INTO Amounts (volume) VALUES (1.12345678912345);

That's correct the current implemenation creates this:

INSERT INTO Amounts (volume) VALUES (STRUCT());

While it also creates this table definition:

string createTable = new StatementGenerator().CreateTable<Amount>(metadata);
CREATE TABLE `Amounts` (
`volume` DECIMAL(20,8)
) WITH ( KAFKA_TOPIC='amounts', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' );
tomasfabian commented 1 month ago

I published a hot fix:

dotnet add package ksqlDb.RestApi.Client --version 6.0.2