questdb / net-questdb-client

Apache License 2.0
34 stars 7 forks source link

Support added for dynamic add of columns #1

Closed lasse-tarp-CA closed 2 years ago

lasse-tarp-CA commented 2 years ago

If columns are added dynamic then you need to suppress exception for Metrics test.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

ideoma commented 2 years ago

Thanks for PR. The code looks fine but can you please explain what problem you're solving here.

In the usage example

using var ls = new LineTcpSender(IPAddress.Loopback.ToString(), 9009);
ls.Table("metric_name", true)
    .Symbol("Symbol", "value")
    .Column("number", 10);

ls
     // Why do you need to call Table() here again? You can continue with Column()
     .Column("string", "born to shine")
    .At(new DateTime(2021, 11, 25, 0, 46, 26));
ls.Flush();
lasse-tarp-CA commented 2 years ago

We upload data from 30 different systems all with different structure. Each system send information about structure along with data. We solve this by doing this:

for (int i = 0; i < value.Values.Length; i++) { // Switch on type from source system = valueType switch { Type a when typeof(Double) == a => writer.Table(table, true).Column(valueNames[i], (double)value.Values[i]), Type a when typeof(string) == a => writer.Table(table, true).Column(valueNames[i], (string)value.Values[i]), Type a when typeof(long) == a => writer.Table(table, true).Column(valueNames[i], (long)value.Values[i]), Type a when typeof(ulong) == a => writer.Table(table, true).Column(valueNames[i], (ulong)value.Values[i]), => throw new NotImplementedException() };} Issue is that we don't know what comes first, which means that we can't add ls.Table(?).Column("something"). We don't have "something" on all systems.

ideoma commented 2 years ago

You better do something like this instead, call Table() in the beginning

writer.Table(table);
for (int i = 0; i < value.Values.Length; i++)
{
// Switch on type from source system
_ = valueType switch
{
  Type a when typeof(Double) == a => writer.Column(valueNames[i], (double)value.Values[i]),
  Type a when typeof(string) == a => writer.Column(valueNames[i], (string)value.Values[i]),
  Type a when typeof(long) == a => writer.Column(valueNames[i], (long)value.Values[i]),
  Type a when typeof(ulong) == a => writer.Column(valueNames[i], (ulong)value.Values[i]),
  _ => throw new NotImplementedException()
};
}
writer.AtNow();
lasse-tarp-CA commented 2 years ago

That works fine.