Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate columns warning shows in improper situations #123

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 2.9.0 [unreleased]

### Bug Fixes
1. [#123](https://github.com/influxdata/influxdb-client-ruby/pull/123): Duplicate columns warning shows in improper situations

## 2.8.0 [2022-10-27]

### Features
Expand Down
1 change: 0 additions & 1 deletion lib/influxdb2/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class Client
# @option options [Logger] :logger Logger used for logging. Disable logging by set to false.
# @option options [bool] :debugging Enable debugging for HTTP request/response.
# @option options [Hash] :tags Default tags which will be added to each point written by api.
# the body line-protocol
def initialize(url, token, options = nil)
@auto_closeable = []
@options = options ? options.dup : {}
Expand Down
2 changes: 1 addition & 1 deletion lib/influxdb2/client/flux_csv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _add_column_names_and_tags(table, csv)
i += 1
end

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

warning = "The response contains columns with duplicated names: #{duplicates.keys.join(', ')}
You should use the 'FluxRecord.row to access your data instead of 'FluxRecord.values' hash."
Expand Down
48 changes: 39 additions & 9 deletions test/influxdb/flux_csv_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,44 @@ def test_parse_duplicate_column_names
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:39.299Z,my_measurement,Prague,25.3
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:40.454Z,my_measurement,Prague,25.3'

tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
.parse
.tables
assert_equal 1, tables.size
assert_equal 8, tables[0].columns.size
assert_equal 3, tables[0].records.size
assert_equal 7, tables[0].records[0].values.size
assert_equal 8, tables[0].records[0].row.size
assert_equal 25.3, tables[0].records[0].row[7]
out, = capture_io do
tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
.parse
.tables

assert_equal 1, tables.size
assert_equal 8, tables[0].columns.size
assert_equal 3, tables[0].records.size
assert_equal 7, tables[0].records[0].values.size
assert_equal 8, tables[0].records[0].row.size
assert_equal 25.3, tables[0].records[0].row[7]
end

assert_match 'The response contains columns with duplicated names: result', out
end

def test_parse_without_duplicates
data = '#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double
#group,false,false,true,true,false,true,true,false
#default,_result,,,,,,,
,result,table,_start,_stop,_time,_measurement,location,result2
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:33.746Z,my_measurement,Prague,25.3
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:39.299Z,my_measurement,Prague,25.3
,,0,2022-09-13T06:14:40.469404272Z,2022-09-13T06:24:40.469404272Z,2022-09-13T06:24:40.454Z,my_measurement,Prague,25.3'

out, = capture_io do
tables = InfluxDB2::FluxCsvParser.new(data, stream: false, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
.parse
.tables

assert_equal 1, tables.size
assert_equal 8, tables[0].columns.size
assert_equal 3, tables[0].records.size
assert_equal 8, tables[0].records[0].values.size
assert_equal 8, tables[0].records[0].row.size
assert_equal 25.3, tables[0].records[0].row[7]
end

assert_equal '', out
end
end