-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement TEMPLATE
interceptor
#51
Comments
This is a big feature, it's another advantage over sqllogictest. We may need more document about interceptor after this is finished. |
-- SQLNESS TEMPLATE aggr={avg, count, stddev, stdvar, sum}, secret=env:MY_TOKEN
SELECT {{aggr}}(c) from t where token={{secret}}; How about this syntax to read environment variable? or just |
I still insist we need to separate
Anyway, let me first implement the consensus part, and put off the controversies |
I'm fine with two interceptors, just think of |
Cross ref #56. Do we have plan to go forward |
I'm afraid no one is working on this. |
I plan to work on it this week @tisonkun |
Thanks. Do you have a rough UI-level design of this interceptor? This interceptor is expected to be more flexible and complex than others. |
The syntax is minijinja, there is an online demo: The demo above use JSON to populate data for the template, this maybe a little verbose, I plan to explore if TOML is supported. For advanced usage like range replacement, minijinja support register functions to environment, and there is already one for us Also we can implement our functions in future to enhance it. |
I was investigating https://crates.io/crates/handlebars, the common problem with minijinja is we have to provide value and SQL templates separately. And they may be provided in either enumerate or range form. Wondering if you have some advice or examples. Another undetermined problem is whether we should render the expanded query in |
I have some experience in minijinja, it works well for me, and couldn't get what problems are you mean.
-- SQLNESS TEMPLATE
INSERT INTO t (c) VALUES
{% for num in range(1, 11) %}
({{ num }}),
{% endfor %}
;
-- SQLNESS TEMPLATE aggr={avg, count, stddev, stdvar, sum}
{%- for item in aggr %}
SELECT {{item}}(c) from t;
{%- endfor %} This is what it looks like for demo in description.
This sounds not a problem for me, if we ignore the rendered query, this will make it hard to debug, so we need to write them to result file. |
That is the problem I'm referring to. things like
I'm afraid rendering them out might make the file unreadable. Considering an insert with 10000 values. |
Template is complex, sooner or later we will need a DSL, minijinja is a popular one and it has all features we need, I don't think we can design a better one than it.
Maybe we can add an option to configure this. |
Describe This Problem
It's a bit frustrating when we want to repeat SQL several times. Like insert 100 rows
or query with all the aggregators
Proposal
Implement a query interceptor that can do this for us. It can automatically replace variables from the given value set. It will looks like
Additional Context
As @jiacai2050 mentioned in #50 (comment), crate minijinja may help to implement this
The text was updated successfully, but these errors were encountered: