From 9282bc66a164c920a18946cc013728dbb6672dd7 Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Wed, 28 Sep 2022 14:51:31 +0200 Subject: [PATCH 01/10] feat: add FluxRecord.Rows with response data stored in List --- Client.Core/Flux/Domain/FluxRecord.cs | 17 ++++++ Client.Core/Flux/Internal/FluxCsvParser.cs | 12 ++++ Examples/RecordRowExample.cs | 69 ++++++++++++++++++++++ Examples/RunExamples.cs | 1 + 4 files changed, 99 insertions(+) create mode 100644 Examples/RecordRowExample.cs diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index 9d4fad56e..abb66dde9 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -22,6 +22,23 @@ public class FluxRecord /// The record's values. /// public Dictionary Values { get; } = new Dictionary(); + + /// + /// The record's rows. + /// + public List Rows { get; } = new List(); + + public class Row + { + public string Field { get; } + public object Value { get; } + + public Row(string field, object value) + { + Field = field; + Value = value; + } + } public FluxRecord(int table) { diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index f4efc17aa..07eac34d0 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -267,7 +267,11 @@ private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) var strValue = csv[fluxColumn.Index + 1]; + if (record.Values.ContainsKey(columnName)) + record.Values.Remove(columnName); record.Values.Add(columnName, ToValue(strValue, fluxColumn)); + + record.Rows.Add(new FluxRecord.Row(columnName, ToValue(strValue, fluxColumn))); } return record; @@ -389,6 +393,14 @@ private void AddColumnNamesAndTags(FluxTable table, CsvReader columnNames) var fluxColumn = GetFluxColumn(ii, table); fluxColumn.Label = columnNames[ii + 1]; } + + var duplicates = table.Columns.GroupBy(col => col.Label) + .Where(rec => rec.Count() > 1) + .Select(label => label.Key).ToList(); + if (duplicates.Any()) + Console.WriteLine( + $"The response contains columns with duplicated names: {string.Join(", ", duplicates)}\n" + + "You should use the 'record.row' to access your data instead of 'record.values' dictionary."); } private FluxColumn GetFluxColumn(int columnIndex, FluxTable table) diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs new file mode 100644 index 000000000..0029bd445 --- /dev/null +++ b/Examples/RecordRowExample.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using InfluxDB.Client; +using InfluxDB.Client.Api.Domain; + + +namespace Examples +{ + public static class RecordRowExample + { + public static async Task Main() + { + const string url = "http://localhost:9999/"; + const string username = "my-user"; + const string password = "my-password"; + const string bucket = "my-bucket"; + const string org = "my-org"; + + using var client = InfluxDBClientFactory.Create(url, username, password.ToCharArray()); + + // + // Get ID of Organization with specified name + // + var orgId = (await client.GetOrganizationsApi().FindOrganizationsAsync(org: org)).First().Id; + + // + // Prepare Data + // + var writeApi = client.GetWriteApiAsync(); + for (var i = 1; i <= 5; i++) + await writeApi.WriteRecordAsync($"point,table=my-table result={i}", WritePrecision.Ns, bucket, org); + + // + // Query data with pivot + // + var queryApi = client.GetQueryApi(); + var fluxQuery = $"from(bucket: \"{bucket}\")\n" + + " |> range(start: -1m)" + + " |> filter(fn: (r) => (r[\"_measurement\"] == \"point\"))" + + " |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; + var tables = await queryApi.QueryAsync(fluxQuery, org: orgId); + + // + // Write data to output + // + if (tables != null) + { + // using FluxRecord.Values - Dictionary - can`t contains duplicity key names + Console.WriteLine("------------------------------- FluxTable.Records -------------------------------"); + foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) + Console.WriteLine("{" + string.Join(", ", + fluxRecord.Values.Select(kv => kv.Key + ": " + kv.Value).ToArray()) + "}"); + + // using FluxRecord.Rows - List - contains all data + Console.WriteLine("-------------------------------- FluxTable.Rows ---------------------------------"); + foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) + { + foreach (var row in fluxRecord.Rows) + Console.Write(row.Field + ": " + row.Value + ", "); + Console.Write("\n"); + } + + } + + client.Dispose(); + } + } +} diff --git a/Examples/RunExamples.cs b/Examples/RunExamples.cs index beb7e9133..c1e28fe0b 100644 --- a/Examples/RunExamples.cs +++ b/Examples/RunExamples.cs @@ -11,6 +11,7 @@ public static class RunExamples /// public static async Task Main(string[] args) { + await RecordRowExample.Main(); if (args.Length >= 1 && !string.IsNullOrEmpty(args[0])) { Console.WriteLine($"Run solution: {args[0]}"); From bd3d06291df616f6f15812b09b87ae53b16bce39 Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Wed, 28 Sep 2022 15:25:56 +0200 Subject: [PATCH 02/10] feat: add FluxRecord.Rows with response data stored in List --- CHANGELOG.md | 3 +++ Client.Core/Flux/Domain/FluxRecord.cs | 4 ++-- Client.Core/Flux/Internal/FluxCsvParser.cs | 9 +++++++-- Examples/RecordRowExample.cs | 15 +++++++-------- Examples/RunExamples.cs | 6 ++++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f09f3f6..b4b83285c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Update dependencies: ## 4.6.0 [2022-09-29] +### Features +1. [#376](https://github.com/influxdata/influxdb-client-csharp/pull/376): Added `FluxRecord.Rows` which stores response data in a list + ### Bug Fixes 1. [#353](https://github.com/influxdata/influxdb-client-csharp/pull/353): Support for `double` types in LINQ expression [LINQ] 1. [#360](https://github.com/influxdata/influxdb-client-csharp/pull/360): Designated `HealthAsync` as obsolete in `IInfluxDBClient` diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index abb66dde9..a320cfd2f 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -22,12 +22,12 @@ public class FluxRecord /// The record's values. /// public Dictionary Values { get; } = new Dictionary(); - + /// /// The record's rows. /// public List Rows { get; } = new List(); - + public class Row { public string Field { get; } diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index 07eac34d0..7477a3d70 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -268,9 +268,12 @@ private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) var strValue = csv[fluxColumn.Index + 1]; if (record.Values.ContainsKey(columnName)) + { record.Values.Remove(columnName); + } + record.Values.Add(columnName, ToValue(strValue, fluxColumn)); - + record.Rows.Add(new FluxRecord.Row(columnName, ToValue(strValue, fluxColumn))); } @@ -393,14 +396,16 @@ private void AddColumnNamesAndTags(FluxTable table, CsvReader columnNames) var fluxColumn = GetFluxColumn(ii, table); fluxColumn.Label = columnNames[ii + 1]; } - + var duplicates = table.Columns.GroupBy(col => col.Label) .Where(rec => rec.Count() > 1) .Select(label => label.Key).ToList(); if (duplicates.Any()) + { Console.WriteLine( $"The response contains columns with duplicated names: {string.Join(", ", duplicates)}\n" + "You should use the 'record.row' to access your data instead of 'record.values' dictionary."); + } } private FluxColumn GetFluxColumn(int columnIndex, FluxTable table) diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index 0029bd445..3ef4deb75 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -16,9 +16,9 @@ public static async Task Main() const string password = "my-password"; const string bucket = "my-bucket"; const string org = "my-org"; - + using var client = InfluxDBClientFactory.Create(url, username, password.ToCharArray()); - + // // Get ID of Organization with specified name // @@ -39,8 +39,8 @@ public static async Task Main() + " |> range(start: -1m)" + " |> filter(fn: (r) => (r[\"_measurement\"] == \"point\"))" + " |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; - var tables = await queryApi.QueryAsync(fluxQuery, org: orgId); - + var tables = await queryApi.QueryAsync(fluxQuery, orgId); + // // Write data to output // @@ -51,7 +51,7 @@ public static async Task Main() foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) Console.WriteLine("{" + string.Join(", ", fluxRecord.Values.Select(kv => kv.Key + ": " + kv.Value).ToArray()) + "}"); - + // using FluxRecord.Rows - List - contains all data Console.WriteLine("-------------------------------- FluxTable.Rows ---------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) @@ -60,10 +60,9 @@ public static async Task Main() Console.Write(row.Field + ": " + row.Value + ", "); Console.Write("\n"); } - } - + client.Dispose(); } } -} +} \ No newline at end of file diff --git a/Examples/RunExamples.cs b/Examples/RunExamples.cs index c1e28fe0b..edeb48d95 100644 --- a/Examples/RunExamples.cs +++ b/Examples/RunExamples.cs @@ -11,7 +11,6 @@ public static class RunExamples /// public static async Task Main(string[] args) { - await RecordRowExample.Main(); if (args.Length >= 1 && !string.IsNullOrEmpty(args[0])) { Console.WriteLine($"Run solution: {args[0]}"); @@ -70,6 +69,9 @@ public static async Task Main(string[] args) case "ParametrizedQuery": await ParametrizedQuery.Main(args); break; + case "RecordRowExample": + await RecordRowExample.Main(); + break; } } else @@ -79,7 +81,7 @@ public static async Task Main(string[] args) "FluxClientPocoExample, PlatformExample, WriteEventHandlerExample, WriteApiAsyncExample, " + "CustomDomainMapping, PocoQueryWriteExample, CustomDomainMappingAndLinq, " + "SynchronousQuery, InfluxDB18Example, QueryLinqCloud, ManagementExample, " + - " InvokableScripts, ParametrizedQuery"); + " InvokableScripts, ParametrizedQuery, RecordRowExample"); } } } From b4f188b7eb9732a04a5493c1e907ea25478f6553 Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Thu, 29 Sep 2022 13:07:56 +0200 Subject: [PATCH 03/10] feat: add FluxRecord.Rows with response data stored in List --- Client.Core/Flux/Domain/FluxRecord.cs | 14 +------------- Client.Core/Flux/Internal/FluxCsvParser.cs | 11 ++++------- Client.Legacy.Test/FluxCsvParserTest.cs | 22 ++++++++++++++++++++++ Examples/README.md | 2 ++ Examples/RecordRowExample.cs | 8 ++++---- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index a320cfd2f..9b920dadb 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -26,19 +26,7 @@ public class FluxRecord /// /// The record's rows. /// - public List Rows { get; } = new List(); - - public class Row - { - public string Field { get; } - public object Value { get; } - - public Row(string field, object value) - { - Field = field; - Value = value; - } - } + public List> Rows { get; } = new List>(); public FluxRecord(int table) { diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index 7477a3d70..20989aa61 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -267,14 +267,11 @@ private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) var strValue = csv[fluxColumn.Index + 1]; - if (record.Values.ContainsKey(columnName)) - { - record.Values.Remove(columnName); - } + var value = ToValue(strValue, fluxColumn); - record.Values.Add(columnName, ToValue(strValue, fluxColumn)); + record.Values[columnName] = value; - record.Rows.Add(new FluxRecord.Row(columnName, ToValue(strValue, fluxColumn))); + record.Rows.Add(new KeyValuePair(columnName, value)); } return record; @@ -404,7 +401,7 @@ private void AddColumnNamesAndTags(FluxTable table, CsvReader columnNames) { Console.WriteLine( $"The response contains columns with duplicated names: {string.Join(", ", duplicates)}\n" + - "You should use the 'record.row' to access your data instead of 'record.values' dictionary."); + "You should use the 'record.Rows' to access your data instead of 'record.Values' dictionary."); } } diff --git a/Client.Legacy.Test/FluxCsvParserTest.cs b/Client.Legacy.Test/FluxCsvParserTest.cs index eed209251..a5a196645 100644 --- a/Client.Legacy.Test/FluxCsvParserTest.cs +++ b/Client.Legacy.Test/FluxCsvParserTest.cs @@ -771,6 +771,28 @@ public void ParseWithoutDatatype() Assert.AreEqual("west", tables[0].Records[0].GetValueByKey("region")); } + [Test] + public void ParseDuplicateColumnNames() + { + const string data = + "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double\n" + + "#group,false,false,true,true,false,true,true,false\n" + + "#default,_result,,,,,,,\n" + + " ,result,table,_start,_stop,_time,_measurement,location,result\n" + + ",,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:33.746Z,my_measurement,Prague,25.3\n" + + ",,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:39.299Z,my_measurement,Prague,25.3\n" + + ",,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:40.454Z,my_measurement,Prague,25.3\n"; + + _parser = new FluxCsvParser(FluxCsvParser.ResponseMode.OnlyNames); + var tables = ParseFluxResponse(data); + Assert.AreEqual(1, tables.Count); + Assert.AreEqual(8, tables[0].Columns.Count); + Assert.AreEqual(3, tables[0].Records.Count); + Assert.AreEqual(7, tables[0].Records[0].Values.Count); + Assert.AreEqual(8, tables[0].Records[0].Rows.Count); + Assert.AreEqual(25.3, tables[0].Records[0].Rows[7].Value); + } + private List ParseFluxResponse(string data) { var consumer = new FluxCsvParser.FluxResponseConsumerTable(); diff --git a/Examples/README.md b/Examples/README.md index 1cd144a73..223d896fc 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -6,3 +6,5 @@ ## Others - [InvokableScripts.cs](InvokableScripts.cs) - How to use Invokable scripts Cloud API to create custom endpoints that query data - [ParametrizedQuery.cs](ParametrizedQuery.cs) - How to use parameterized Flux queries +- [RecordRowExample.cs](RecordRowExample.cs) - How to use FluxRecord.Rows (List) instead of FluxRecord.Values (Dictionary), +in case of duplicity column names \ No newline at end of file diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index 3ef4deb75..b41cc06cf 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -47,17 +47,17 @@ public static async Task Main() if (tables != null) { // using FluxRecord.Values - Dictionary - can`t contains duplicity key names - Console.WriteLine("------------------------------- FluxTable.Records -------------------------------"); + Console.WriteLine("------------------------------- FluxRecord.Values -------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) Console.WriteLine("{" + string.Join(", ", fluxRecord.Values.Select(kv => kv.Key + ": " + kv.Value).ToArray()) + "}"); - // using FluxRecord.Rows - List - contains all data - Console.WriteLine("-------------------------------- FluxTable.Rows ---------------------------------"); + // using FluxRecord.Rows - List> - contains all data + Console.WriteLine("-------------------------------- FluxRecord.Rows ---------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) { foreach (var row in fluxRecord.Rows) - Console.Write(row.Field + ": " + row.Value + ", "); + Console.Write(row.Key + ": " + row.Value + ", "); Console.Write("\n"); } } From bd9440b8740c281a5a7c0a780a3b2b08742dca7b Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Thu, 29 Sep 2022 14:11:05 +0200 Subject: [PATCH 04/10] feat: add FluxRecord.Row with response data stored in List --- CHANGELOG.md | 2 +- Client.Core/Flux/Domain/FluxRecord.cs | 2 +- Client.Core/Flux/Internal/FluxCsvParser.cs | 4 ++-- Client.Legacy.Test/FluxCsvParserTest.cs | 4 ++-- Examples/README.md | 2 +- Examples/RecordRowExample.cs | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4b83285c..c2fe5c735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Update dependencies: ## 4.6.0 [2022-09-29] ### Features -1. [#376](https://github.com/influxdata/influxdb-client-csharp/pull/376): Added `FluxRecord.Rows` which stores response data in a list +1. [#376](https://github.com/influxdata/influxdb-client-csharp/pull/376): Added `FluxRecord.Row` which stores response data in a list ### Bug Fixes 1. [#353](https://github.com/influxdata/influxdb-client-csharp/pull/353): Support for `double` types in LINQ expression [LINQ] diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index 9b920dadb..617a8488b 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -26,7 +26,7 @@ public class FluxRecord /// /// The record's rows. /// - public List> Rows { get; } = new List>(); + public List> Row { get; } = new List>(); public FluxRecord(int table) { diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index 20989aa61..0c08bac90 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -271,7 +271,7 @@ private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) record.Values[columnName] = value; - record.Rows.Add(new KeyValuePair(columnName, value)); + record.Row.Add(new KeyValuePair(columnName, value)); } return record; @@ -401,7 +401,7 @@ private void AddColumnNamesAndTags(FluxTable table, CsvReader columnNames) { Console.WriteLine( $"The response contains columns with duplicated names: {string.Join(", ", duplicates)}\n" + - "You should use the 'record.Rows' to access your data instead of 'record.Values' dictionary."); + "You should use the 'record.Row to access your data instead of 'record.Values' dictionary."); } } diff --git a/Client.Legacy.Test/FluxCsvParserTest.cs b/Client.Legacy.Test/FluxCsvParserTest.cs index a5a196645..0ffb45bf3 100644 --- a/Client.Legacy.Test/FluxCsvParserTest.cs +++ b/Client.Legacy.Test/FluxCsvParserTest.cs @@ -789,8 +789,8 @@ public void ParseDuplicateColumnNames() Assert.AreEqual(8, tables[0].Columns.Count); Assert.AreEqual(3, tables[0].Records.Count); Assert.AreEqual(7, tables[0].Records[0].Values.Count); - Assert.AreEqual(8, tables[0].Records[0].Rows.Count); - Assert.AreEqual(25.3, tables[0].Records[0].Rows[7].Value); + Assert.AreEqual(8, tables[0].Records[0].Row.Count); + Assert.AreEqual(25.3, tables[0].Records[0].Row[7].Value); } private List ParseFluxResponse(string data) diff --git a/Examples/README.md b/Examples/README.md index 223d896fc..6eca76b7a 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -6,5 +6,5 @@ ## Others - [InvokableScripts.cs](InvokableScripts.cs) - How to use Invokable scripts Cloud API to create custom endpoints that query data - [ParametrizedQuery.cs](ParametrizedQuery.cs) - How to use parameterized Flux queries -- [RecordRowExample.cs](RecordRowExample.cs) - How to use FluxRecord.Rows (List) instead of FluxRecord.Values (Dictionary), +- [RecordRowExample.cs](RecordRowExample.cs) - How to use FluxRecord.Row (List) instead of FluxRecord.Values (Dictionary), in case of duplicity column names \ No newline at end of file diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index b41cc06cf..f83cc1792 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -47,16 +47,16 @@ public static async Task Main() if (tables != null) { // using FluxRecord.Values - Dictionary - can`t contains duplicity key names - Console.WriteLine("------------------------------- FluxRecord.Values -------------------------------"); + Console.WriteLine("-------------------------------- FluxRecord.Values -------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) Console.WriteLine("{" + string.Join(", ", fluxRecord.Values.Select(kv => kv.Key + ": " + kv.Value).ToArray()) + "}"); - // using FluxRecord.Rows - List> - contains all data - Console.WriteLine("-------------------------------- FluxRecord.Rows ---------------------------------"); + // using FluxRecord.Row - List> - contains all data + Console.WriteLine("--------------------------------- FluxRecord.Row ---------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) { - foreach (var row in fluxRecord.Rows) + foreach (var row in fluxRecord.Row) Console.Write(row.Key + ": " + row.Value + ", "); Console.Write("\n"); } From f305a004cf7e6dcd2405b8545b1e6cfabd4f20e3 Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Mon, 3 Oct 2022 20:20:39 +0200 Subject: [PATCH 05/10] feat: add FluxRecord.Row with response data stored in List --- Client.Core/Flux/Domain/FluxRecord.cs | 2 +- Client.Core/Flux/Internal/FluxCsvParser.cs | 2 +- Client.Legacy.Test/FluxCsvParserTest.cs | 2 +- Examples/RecordRowExample.cs | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index 617a8488b..207ff263e 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -26,7 +26,7 @@ public class FluxRecord /// /// The record's rows. /// - public List> Row { get; } = new List>(); + public List Row { get; } = new List(); public FluxRecord(int table) { diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index 0c08bac90..3e7738f16 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -271,7 +271,7 @@ private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) record.Values[columnName] = value; - record.Row.Add(new KeyValuePair(columnName, value)); + record.Row.Add(value); } return record; diff --git a/Client.Legacy.Test/FluxCsvParserTest.cs b/Client.Legacy.Test/FluxCsvParserTest.cs index 0ffb45bf3..d6a85d986 100644 --- a/Client.Legacy.Test/FluxCsvParserTest.cs +++ b/Client.Legacy.Test/FluxCsvParserTest.cs @@ -790,7 +790,7 @@ public void ParseDuplicateColumnNames() Assert.AreEqual(3, tables[0].Records.Count); Assert.AreEqual(7, tables[0].Records[0].Values.Count); Assert.AreEqual(8, tables[0].Records[0].Row.Count); - Assert.AreEqual(25.3, tables[0].Records[0].Row[7].Value); + Assert.AreEqual(25.3, tables[0].Records[0].Row[7]); } private List ParseFluxResponse(string data) diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index f83cc1792..5f8340a4e 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -56,8 +56,7 @@ public static async Task Main() Console.WriteLine("--------------------------------- FluxRecord.Row ---------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) { - foreach (var row in fluxRecord.Row) - Console.Write(row.Key + ": " + row.Value + ", "); + Console.WriteLine("{" + string.Join(", ", fluxRecord.Row) + "}"); Console.Write("\n"); } } From 7f1cbf362f2c3286b745beaf0ec1407280ab0141 Mon Sep 17 00:00:00 2001 From: michaelahojna Date: Tue, 4 Oct 2022 08:26:52 +0200 Subject: [PATCH 06/10] refactor: record row example --- Client.Core/Flux/Internal/FluxCsvParser.cs | 2 +- Examples/RecordRowExample.cs | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Client.Core/Flux/Internal/FluxCsvParser.cs b/Client.Core/Flux/Internal/FluxCsvParser.cs index 3e7738f16..6d1544f22 100644 --- a/Client.Core/Flux/Internal/FluxCsvParser.cs +++ b/Client.Core/Flux/Internal/FluxCsvParser.cs @@ -401,7 +401,7 @@ private void AddColumnNamesAndTags(FluxTable table, CsvReader columnNames) { Console.WriteLine( $"The response contains columns with duplicated names: {string.Join(", ", duplicates)}\n" + - "You should use the 'record.Row to access your data instead of 'record.Values' dictionary."); + "You should use the 'FluxRecord.Row to access your data instead of 'FluxRecord.Values' dictionary."); } } diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index 5f8340a4e..419503430 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -12,17 +12,11 @@ public static class RecordRowExample public static async Task Main() { const string url = "http://localhost:9999/"; - const string username = "my-user"; - const string password = "my-password"; + const string token = "my-token"; const string bucket = "my-bucket"; const string org = "my-org"; - using var client = InfluxDBClientFactory.Create(url, username, password.ToCharArray()); - - // - // Get ID of Organization with specified name - // - var orgId = (await client.GetOrganizationsApi().FindOrganizationsAsync(org: org)).First().Id; + using var client = InfluxDBClientFactory.Create(url, token.ToCharArray()); // // Prepare Data @@ -39,7 +33,7 @@ public static async Task Main() + " |> range(start: -1m)" + " |> filter(fn: (r) => (r[\"_measurement\"] == \"point\"))" + " |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; - var tables = await queryApi.QueryAsync(fluxQuery, orgId); + var tables = await queryApi.QueryAsync(fluxQuery, org); // // Write data to output @@ -55,10 +49,7 @@ public static async Task Main() // using FluxRecord.Row - List> - contains all data Console.WriteLine("--------------------------------- FluxRecord.Row ---------------------------------"); foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) - { Console.WriteLine("{" + string.Join(", ", fluxRecord.Row) + "}"); - Console.Write("\n"); - } } client.Dispose(); From f719fba17a2aac814cb0492a2d0c58832dd71c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bedn=C3=A1=C5=99?= Date: Tue, 4 Oct 2022 06:15:28 +0200 Subject: [PATCH 07/10] docs: clarify meaning --- Client.Core/Flux/Domain/FluxRecord.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index 207ff263e..2f64f9656 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -24,7 +24,7 @@ public class FluxRecord public Dictionary Values { get; } = new Dictionary(); /// - /// The record's rows. + /// The record's columns. /// public List Row { get; } = new List(); @@ -119,4 +119,4 @@ public override string ToString() .ToString(); } } -} \ No newline at end of file +} From 86a877026059ebfcc4741e50b28834ab7ea4b229 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 4 Oct 2022 06:39:42 +0200 Subject: [PATCH 08/10] fix: code style --- Client.Core/Flux/Domain/FluxRecord.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client.Core/Flux/Domain/FluxRecord.cs b/Client.Core/Flux/Domain/FluxRecord.cs index 2f64f9656..a35195b3c 100644 --- a/Client.Core/Flux/Domain/FluxRecord.cs +++ b/Client.Core/Flux/Domain/FluxRecord.cs @@ -119,4 +119,4 @@ public override string ToString() .ToString(); } } -} +} \ No newline at end of file From 16c08a114499e2fdba847860038a0f24bc214181 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 4 Oct 2022 09:13:52 +0200 Subject: [PATCH 09/10] chore: client.Dispose() is useless --- Examples/RecordRowExample.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/RecordRowExample.cs b/Examples/RecordRowExample.cs index 419503430..1bd0e9808 100644 --- a/Examples/RecordRowExample.cs +++ b/Examples/RecordRowExample.cs @@ -51,8 +51,6 @@ public static async Task Main() foreach (var fluxRecord in tables.SelectMany(fluxTable => fluxTable.Records)) Console.WriteLine("{" + string.Join(", ", fluxRecord.Row) + "}"); } - - client.Dispose(); } } } \ No newline at end of file From 956f230376f74d58007d25c978a61487dab2b09b Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 4 Oct 2022 09:15:35 +0200 Subject: [PATCH 10/10] docs: update CHANGELOG.md --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2fe5c735..df0fc79c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 4.7.0 [unreleased] +### Features +1. [#376](https://github.com/influxdata/influxdb-client-csharp/pull/376): Added `FluxRecord.Row` which stores response data in a list + ### Dependencies Update dependencies: @@ -8,9 +11,6 @@ Update dependencies: ## 4.6.0 [2022-09-29] -### Features -1. [#376](https://github.com/influxdata/influxdb-client-csharp/pull/376): Added `FluxRecord.Row` which stores response data in a list - ### Bug Fixes 1. [#353](https://github.com/influxdata/influxdb-client-csharp/pull/353): Support for `double` types in LINQ expression [LINQ] 1. [#360](https://github.com/influxdata/influxdb-client-csharp/pull/360): Designated `HealthAsync` as obsolete in `IInfluxDBClient`