Skip to content

Commit c2bc31d

Browse files
authored
fix: duplicate columns warning shows in improper situations (#123)
1 parent 1f9a854 commit c2bc31d

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 2.9.0 [unreleased]
22

3+
### Bug Fixes
4+
1. [#123](https://github.com/influxdata/influxdb-client-ruby/pull/123): Duplicate columns warning shows in improper situations
5+
36
## 2.8.0 [2022-10-27]
47

58
### Features

lib/influxdb2/client/client.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class Client
5151
# @option options [Logger] :logger Logger used for logging. Disable logging by set to false.
5252
# @option options [bool] :debugging Enable debugging for HTTP request/response.
5353
# @option options [Hash] :tags Default tags which will be added to each point written by api.
54-
# the body line-protocol
5554
def initialize(url, token, options = nil)
5655
@auto_closeable = []
5756
@options = options ? options.dup : {}

lib/influxdb2/client/flux_csv_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _add_column_names_and_tags(table, csv)
188188
i += 1
189189
end
190190

191-
duplicates = table.columns.group_by { :label }.select { |_k, v| v.size > 1 }
191+
duplicates = table.columns.group_by(&:label).select { |_k, v| v.size > 1 }
192192

193193
warning = "The response contains columns with duplicated names: #{duplicates.keys.join(', ')}
194194
You should use the 'FluxRecord.row to access your data instead of 'FluxRecord.values' hash."

test/influxdb/flux_csv_parser_test.rb

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,44 @@ def test_parse_duplicate_column_names
516516
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:39.299Z,my_measurement,Prague,25.3
517517
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:40.454Z,my_measurement,Prague,25.3'
518518

519-
tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
520-
.parse
521-
.tables
522-
assert_equal 1, tables.size
523-
assert_equal 8, tables[0].columns.size
524-
assert_equal 3, tables[0].records.size
525-
assert_equal 7, tables[0].records[0].values.size
526-
assert_equal 8, tables[0].records[0].row.size
527-
assert_equal 25.3, tables[0].records[0].row[7]
519+
out, = capture_io do
520+
tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
521+
.parse
522+
.tables
523+
524+
assert_equal 1, tables.size
525+
assert_equal 8, tables[0].columns.size
526+
assert_equal 3, tables[0].records.size
527+
assert_equal 7, tables[0].records[0].values.size
528+
assert_equal 8, tables[0].records[0].row.size
529+
assert_equal 25.3, tables[0].records[0].row[7]
530+
end
531+
532+
assert_match 'The response contains columns with duplicated names: result', out
533+
end
534+
535+
def test_parse_without_duplicates
536+
data = '#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double
537+
#group,false,false,true,true,false,true,true,false
538+
#default,_result,,,,,,,
539+
,result,table,_start,_stop,_time,_measurement,location,result2
540+
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:33.746Z,my_measurement,Prague,25.3
541+
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:39.299Z,my_measurement,Prague,25.3
542+
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:40.454Z,my_measurement,Prague,25.3'
543+
544+
out, = capture_io do
545+
tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
546+
.parse
547+
.tables
548+
549+
assert_equal 1, tables.size
550+
assert_equal 8, tables[0].columns.size
551+
assert_equal 3, tables[0].records.size
552+
assert_equal 8, tables[0].records[0].values.size
553+
assert_equal 8, tables[0].records[0].row.size
554+
assert_equal 25.3, tables[0].records[0].row[7]
555+
end
556+
557+
assert_equal '', out
528558
end
529559
end

0 commit comments

Comments
 (0)