-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add column type to a query result of InfluxDB #6505
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aa0bce0
Add column type to a query result of InfluxDB
masayuki038 aeb7f0f
Remove an unused import
masayuki038 eb3601e
Migrate to pytest
masayuki038 dd4b22f
Rename test names to descriptive
masayuki038 283661e
Merge branch 'master' into influx-column-type
guidopetri 5cec158
Merge branch 'master' into influx-column-type
justinclift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import json | ||
|
||
from influxdb.resultset import ResultSet | ||
|
||
from redash.query_runner import ( | ||
TYPE_FLOAT, | ||
TYPE_INTEGER, | ||
TYPE_STRING, | ||
) | ||
from redash.query_runner.influx_db import _transform_result | ||
|
||
raw = { | ||
"series": [ | ||
{ | ||
"name": "typetest", | ||
"columns": ["time", "k1", "v1", "v2"], | ||
"values": [ | ||
["2023-10-06T13:30:51.323358136Z", "foo", 0.5, 2], | ||
["2023-10-06T13:31:08.882953339Z", "bar", 0.6, 4], | ||
], | ||
} | ||
] | ||
} | ||
|
||
raw_no_rows = {"series": [{"name": "typetest", "columns": ["time", "k1", "v1", "v2"], "values": []}]} | ||
|
||
|
||
def test_result(): | ||
result = ResultSet(raw) | ||
transformed = _transform_result([result]) | ||
expected = { | ||
"columns": [ | ||
{"name": "time", "type": TYPE_STRING}, | ||
{"name": "k1", "type": TYPE_STRING}, | ||
{"name": "v1", "type": TYPE_FLOAT}, | ||
{"name": "v2", "type": TYPE_INTEGER}, | ||
], | ||
"rows": [ | ||
{"k1": "foo", "time": "2023-10-06T13:30:51.323358136Z", "v1": 0.5, "v2": 2}, | ||
{"k1": "bar", "time": "2023-10-06T13:31:08.882953339Z", "v1": 0.6, "v2": 4}, | ||
], | ||
} | ||
assert json.loads(transformed) == expected | ||
|
||
|
||
def test_no_rows_result(): | ||
result = ResultSet(raw_no_rows) | ||
transformed = _transform_result([result]) | ||
expected = { | ||
"columns": [ | ||
{"name": "time", "type": TYPE_STRING}, | ||
{"name": "k1", "type": TYPE_STRING}, | ||
{"name": "v1", "type": TYPE_STRING}, | ||
{"name": "v2", "type": TYPE_STRING}, | ||
], | ||
"rows": [], | ||
} | ||
assert json.loads(transformed) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we rename the tests to be more descriptive? Maybe something like
test_influxdb_result_types_with_rows
andtest_influxdb_result_types_with_no_rows_are_string
?