Skip to content

Commit

Permalink
Fix typos (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
unflag committed Oct 13, 2023
1 parent 6fdac65 commit c10d0b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,23 @@ Note that `PER PARTITION LIMIT 1` used instead of `LIMIT 1` to query one row for
#### Unix epoch time format
Usually there are no problems - Cassandra can store timestamps using different formats as shown in [documentation](https://cassandra.apache.org/doc/latest/cassandra/cql/types.html#timestamps).
However, it is not always enough. One of possible cases could be unix time, which is just number of seconds or milliseconds and usually stored as integer type.
1. If time is stored as number of milliseconds in a `bigint` column, then it should be converted into the `timestamp` type before return data to grafana:
1. If time is stored as a number of milliseconds in a `bigint` column, then it should be converted into the `timestamp` type before return the data to grafana:
```
SELECT sensor_id, temperature, dateOf(maxTimeuuid(registered_at)), location
FROM test.test WHERE sensor_id = 99051fe9-6a9c-46c2-b949-38ef78858dd0
AND registered_at > $__timeFrom and registered_at < $__timeTo
```
This query returns proper timestamp even if it stored as number of milliseconds.

2. If time is stored as number of seconds, then it is not possible to convert it into the timestamp natively, but there is a trick:
2. If time is stored as a number of seconds, then it is not possible to convert it into the timestamp natively, but there is a trick:
```
SELECT sensor_id, temperature, dateOf(maxTimeuuid(registered_at*1000)), location
FROM test.test WHERE sensor_id = 99051fe9-6a9c-46c2-b949-38ef78858dd0
AND registered_at > $__unixEpochFrom and registered_at < $__unixEpochTo
```
* There are two important parts in this query:
* `dateOf(maxTimeuuid(registered_at*1000))` used to convert seconds to milliseconds(`registered_at*1000`) and then convert milliseconds to `timestamp` type.
* `$__unixEpochFrom` and `$__unixEpochTo` are variables with unix time in seconds format which used to fill conditions part.

* `dateOf(maxTimeuuid(registered_at*1000))` used to convert seconds to milliseconds(`registered_at*1000`) and then to convert milliseconds to `timestamp` type, which is handed over to grafana.
* `$__unixEpochFrom` and `$__unixEpochTo` are variables with unix time in the seconds format that are used to fill out conditions part of the query.

## Development

Expand Down
4 changes: 2 additions & 2 deletions backend/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestPlugin_ExecQuery(t *testing.T) {
p := &Plugin{repo: tc.repo}
dataFrames, err := p.ExecQuery(context.TODO(), tc.query)
assert.NoError(t, err)
assert.Equal(t, tc.want, dataFrames)
assert.EqualValues(t, tc.want, dataFrames)
})
}
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func Test_makeDataFrameFromPoints(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dataFrame := makeDataFrameFromPoints(tc.id, tc.alias, tc.rows)
assert.Equal(t, tc.want, dataFrame)
assert.EqualValues(t, tc.want, dataFrame)
})
}
}
Expand Down

0 comments on commit c10d0b5

Please sign in to comment.