If I'm understanding your intent correctly, I think you could do that with Zillion.
https://github.com/totalhack/zillion
Disclaimer: been sidetracked by an acquisition at my day job this year, intend to put more time into this project soon, but I use it in production to great effect.
Sure, I could do that in Zillion the same way I'm currently composing queries in Python at runtime with PyPika.
I'm looking for a more programming language agnostic solution that tools like this (e.g. also PRQL, Malloy) usually offer.