Thoughts on adding support for queries with parameters in query results data source


#21

Hey all,
following this thread with great interest, is there any progress / status update on implementing this feature in an upcoming redash (beta) version @arikfr ?

Im afraid I will run into the same problems as @leshik if I apply the patch that @ariarijp posted…


#22

I explored this option in the past, but at the time I think it needed Cython to run. I did another try now and while it didn’t work with Ubuntu’s Docker image it did work with the python:2 Docker image (which @jezdez started porting our base image to anyway ).

Creating a table function will definitely be much better than what we do now.

Unless I miss something we can create a generic query_result table function that takes query id (and optional parameters) instead of creating a query specific function. We will probably need to support the query_<id> format for some time for backward compatibility, but we can implement it using our current method.


#23

Giving this another look, it looks like TableFunction need to declare its parameters during definition. So maybe we should create a specific function for each query? :thinking:


#24

Either you declare each source query, perhaps according to a configuration on the data source as I suggested earlier, or you declare a single generic query_result() as you suggested. That query would accept two parameters:

  • The query id
  • A json string parameter as suggested by @ariarijp

In either case, for backward compatibility, you can do a simple regex replace on old queries, trading query_xx for query_result(xx, {}) (or query_xx()) before executing the query with sqlite.