-
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 Tinybird query runner #5616
Add Tinybird query runner #5616
Conversation
@pandomic , thanks for the PR! We've updated a lot of things now that we're Community-driven so - if you're still interested in getting this merged - would you mind rebasing off master to re-run the CI? We're trying to clean up our PR todo list, so if you're not interested, that's fine - we'll close the PR in about a week if we don't hear back. If you're interested in reopening the PR afterwards, we would also very much welcome that. |
Hi @guidopetri, thanks for the update, I will try to align the PR in the next following days 🙌 |
0be05c9
to
7d8a80b
Compare
Hey @guidopetri, I just rebased the PR. Hope it looks good. Looking forward to getting Tinybird support 🙌 |
@pandomic Looks like it's about 99.95% done, but still not quite finished. It's failing the formatting check lint test:
We have instructions on how to get that fixed if that's useful? https://github.com/getredash/redash/wiki/Local-development-setup It's the |
7d8a80b
to
5f8aaac
Compare
Codecov Report
@@ Coverage Diff @@
## master #5616 +/- ##
==========================================
+ Coverage 60.77% 60.97% +0.20%
==========================================
Files 154 156 +2
Lines 12656 12780 +124
Branches 1721 1735 +14
==========================================
+ Hits 7692 7793 +101
- Misses 4739 4753 +14
- Partials 225 234 +9
|
@pandomic thanks for your patience and for updating the PR! Any chance you could add some tests to make the Codecov bot happy? |
3de96c4
to
512ed91
Compare
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.
@pandomic thanks for adding these tests. I left a few comments but this looks good to me. I'll approve and merge tomorrow unless you want to change anything in response to the feedback.
redash/query_runner/tinybird.py
Outdated
def test_connection(self): | ||
try: | ||
self._send_query("SELECT count() FROM tinybird.pipe_stats LIMIT 1 FORMAT JSON") | ||
return True | ||
except Exception: | ||
return False |
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.
I think if we set Tinybird.noop_query
this should work automatically and we don't have to override the base class implementation.
redash/query_runner/tinybird.py
Outdated
@classmethod | ||
def name(cls): | ||
return "Tinybird" | ||
|
||
@classmethod | ||
def type(cls): | ||
return "tinybird" |
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.
Same here, I don't think we have to override this.
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.
Makes sense 👍 Slightly adjusted the ClickHouse class to re-use the underlying type()
method
redash/query_runner/tinybird.py
Outdated
url = endpoint % self.configuration.get("url", self.DEFAULT_URL) | ||
authorization = "Bearer %s" % self.configuration.get("token") |
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.
In general, I think we should lean on f
-strings or .format()
- I believe it's safer than using string interpolation with %s
tests/query_runner/test_tinybird.py
Outdated
|
||
class TestTinybird(TestCase): | ||
@patch("requests.get") | ||
def test_get_schema(self, get_request): |
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.
Both the test cases here are testing downstream functionality (i.e. get_schema
and run_query
, that are not directly implemented in the Tinybird runner). One potential improvement would be to test the Tinybird query runner directly, since it uses the base implementation for these methods.
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.
👍 I adjusted the test name to reflect what is happening in get_schema
(it collects the schema from available pipes and datasources).
I am not sure what else to test when it comes to query execution though, as it's essentially just a tiny GET request which is already being tested for proper formatting and with mocked response handling 🤔
Co-authored-by: Thomas Rausch <[email protected]> Co-authored-by: Vlad Gramuzov <[email protected]>"
82c2998
to
4e46071
Compare
Looks like it's passing all of the tests. Weirdly though, the Code coverage tests don't seem to have automatically-rerun. Not sure why. 🤔 |
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.
Thanks again for your contribution :) I retriggered the CI but it should be passing.
What type of PR is this? (check all applicable)
Description
Tinybird is a fast-growing service providing real-time analytics for large amounts of data. Integrating it with powerful Redash tools will open new opportunities for real-time data analysis and visualizations, especially when mixed with other data sources like Python.
Under the hood, Tinybird uses ClickHouse, which makes it possible to re-use existing query runner with minimal adjustments.
Implementation Details
Connection Testing
Tinybird has few system data sources that should become queriable once the connection is properly configured. We use one of those (
tinybird.pipe_stats
) to test whether it can be executed or not.Data Querying
There are different ways how you may run SQL queries against Tinybird. The most flexible one is of course the
/sql
endpoint which does not enforce you to use a single data source or pipe.Schema Fetching
Schema for pipes and data sources can not be easily observed through SQL queries. Thus you may notice a little trick here: we are fetching lists of pipes and data sources and then running a simple query on each of them. Result schema is then returned as
meta
attribute. There is one limitation though, for pipes schema can only be observed if it is exported as an endpoint (because you are restricted to run queries only against shared pipes).Related Tickets & Documents
Proactive initiative
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
The following Loom recording shows the Tinybird query runner at work
https://www.loom.com/share/8d96d361e2534de09710216df528af44