Add Enum Support for Query Parameters


#1

Most of the time, parameters have a few valid inputs that you’d like to choose from. It’d be nice to allow a select input for parameters.

I think at first having simple per-parameter configuration would be best, but maybe down the road it would useful to either allow query results to be in the select or have a way to update multiple query enums at once.


#2

I had very similar thoughts about this. I was actually thinking to start from implementing support for loading values for the parameter from a query, as it serves both use cases. While it’s cucumbersome, you can implement the static list as a “static” query:

SELECT 1 as value, 'V1' as name

UNION ALL

SELECT 2 as value, 'V2' as name

...

But you’re welcome to implement the “enum” first as I believe from implementation point of view, it will be easier.


This along with the global/dashboard parameters, keep leading me to the idea of having a dedicated place in Redash to define parameters. So you can have definitions for parameters in one place, which you can reuse in queries. This way you need to define if a parameter is global only once, or edit the enum only once.

The user should still be able to define an “adhoc” parameter in a query, but he can also choose from existing ones.

What do you think of this?


#3

I do like the idea of configurating parameters only once, I’m not exactly sure how the linking bit between queries and parameters would work. But this idea of 1st class parameters is what I was eventually getting at.


#4

Linking –

  1. We will use the parameter name (the part between the curly brackets) as the unique identifier.
  2. If we already have a definition for a parameter with the same id, we will reuse it.
  3. We will autocomplete parameter names based on the list of existing ones.

Creating new ones – when you add a new parameter (wasn’t defined before) to a query, we add it to the list of existing ones.

It doesn’t feel 100% robust, so additional comments/ideas are appreciated.


#5

What do you think about changing the parameter type to ‘Query’ in the parameter settings page, and then you get a dropdown (w/ autocomplete) of queries to pick from? I think that is more explicit and should help with feature discovery, then you can use any query that you’ve already made to do this.

Also how would refreshing the query work? Would it have to be a scheduled query to be updated, or should there be an explict refresh button the parameter settings.


#6

Now I read again and realized that by “linking parameters to queries” we were talking about different things… in the context of linking parameter to query for values, the way you described it is exactly what I had in mind. :slight_smile:

I think it’s reasonable to expect the user to set a refresh schedule if it’s needed.


#7

@arikfr is there a way to create a query parameter dropdown list from a query? If so that would be awesome


#8

Currently you can only add a static drop-down list. I have been planning on adding this to redash, but am waiting for another PR to be merged first. If you’d like to contribute this, feel free!


#9

@rockwotj sure, I’d love to help. Mind pointing me to the PR that needs to be merged first and also roughly what parts of the code I would need to touch? Thanks!


#10

@azymnis @rockwotj I have given this a shot. Lemme know what you guys think: https://github.com/getredash/redash/pull/1928


#11

@arikfr ^^ (Could only mention 2 in one comment)


#12

Thank you, this is going to be so useful! :slight_smile: