Can I extract just the list of values from the field filter for my SQL queries and not have it expand to IN
clause?
My scenario is that I want to use a different table to get my field filter values from.
- Say I have {{test_field_filter}} on field
table_a.column_a
- I want to write a query
SELECT * FROM table_b WHERE column_b IN {{test_field_filter}}
- However, the above query gets generated as
SELECT * FROM table_b WHERE column_b IN column_a IN ('value1', 'value2', 'value3')
Simple reason is that table_a
and table_b
come from entirely different data sources/backends. Creating materialisation will be overkill and using joins will be inefficient.
If theres a way to not have the IN
clause, it will also solve some of the issue here: Ability to create pre-populated SQL filters · Issue #5245 · metabase/metabase · GitHub
(i.e. one could just create a view and refer that in the field filter).
If it is currently not possible, I'm happy to hack about the code to make it work for me if someone can point me to the right files in the codebase. My guess is it will be in the src/metabase/driver/sql/parameters/substitution.clj
and src/metabase/driver/sql/parameters/substitute.clj
.
I am using the community driver metabase-clickhouse-driver
, So I could also modify it. If someone can help me with the best way to do it.
p.s. I am a Python and C++ programmer and Java, Clojure, JS is a bit foreign to me :-/ so help would be really really appreciated.
p.p.s Also the Field Filter syntax is bit weird when used in queries and it makes queries hard to understand. Mabye I'm missing something, so it would be good to understand the logic behind such syntax)