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

feat: adding FluxRecord.Result() function #287

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased
### Features
- [#285](https://github.com/influxdata/influxdb-client-go/pull/285) Added *Client.Ping()* function as the only validation method available in both OSS and Cloud.
- [#287](https://github.com/influxdata/influxdb-client-go/pull/287) Added *FluxRecord.Result()* function as a convenient way to retrieve the Flux result name of data.

### Bug fixes
- [#285](https://github.com/influxdata/influxdb-client-go/pull/285) Functions *Client.Health()* and *Client.Ready()* correctly report an error when called against InfluxDB Cloud.
Expand Down
6 changes: 6 additions & 0 deletions api/query/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func (r *FluxRecord) Field() string {
return stringValue(r.values, "_field")
}

// Result returns the value of the _result column, which represents result name.
// Returns empty string if there is no column "result".
func (r *FluxRecord) Result() string {
return stringValue(r.values, "result")
}

// Measurement returns the measurement name of the record
// Returns empty string if there is no column "_measurement".
func (r *FluxRecord) Measurement() string {
Expand Down
5 changes: 3 additions & 2 deletions api/query/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,26 @@ func TestRecord(t *testing.T) {
assert.Equal(t, mustParseTime("2020-02-17T22:19:49.747562847Z"), record.Start())
assert.Equal(t, mustParseTime("2020-02-18T22:19:49.747562847Z"), record.Stop())
assert.Equal(t, mustParseTime("2020-02-18T10:34:08.135814545Z"), record.Time())
assert.Equal(t, "_result", record.Result())
assert.Equal(t, "f", record.Field())
assert.Equal(t, 1.4, record.Value())
assert.Equal(t, "test", record.Measurement())
assert.Equal(t, 2, record.Table())

agRec := &FluxRecord{table: 0,
values: map[string]interface{}{
"result": "_result",
"room": "bathroom",
"sensor": "SHT",
"temp": 24.3,
"hum": 42,
},
}
require.Len(t, agRec.values, 5)
require.Len(t, agRec.values, 4)
assert.Equal(t, time.Time{}, agRec.Start())
assert.Equal(t, time.Time{}, agRec.Stop())
assert.Equal(t, time.Time{}, agRec.Time())
assert.Equal(t, "", agRec.Field())
assert.Equal(t, "", agRec.Result())
assert.Nil(t, agRec.Value())
assert.Equal(t, "", agRec.Measurement())
assert.Equal(t, 0, agRec.Table())
Expand Down
2 changes: 1 addition & 1 deletion api/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestQueryCVSResultMultiTables(t *testing.T) {
require.Equal(t, queryResult.table, expectedTable4)
require.NotNil(t, queryResult.Record())
require.Equal(t, queryResult.Record(), expectedRecord42)
assert.Equal(t, "_result4", queryResult.Record().ValueByKey("result"))
assert.Equal(t, "_result4", queryResult.Record().Result())

require.False(t, queryResult.Next())
require.Nil(t, queryResult.Err())
Expand Down