-
Notifications
You must be signed in to change notification settings - Fork 611
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
RFC: DocSlt, documentation examples as sqllogictest tests #5117
Comments
I propose a simple alternative: just say IMO what you want to do is to introduce an additional tool to keep doc example in sync with e2e tests. My point is that e2e tests + references when needed is already good enough, considering:
|
Agree with xxchan. I feel it is a cool idea, but the ROI is not high enough given its engineering complexity. |
I think it is not a good idea to maintain test cases in code comments. Those examples in the comment are just for illustration purposes. And to make DocSlt cases in sync with the latest version code you need to add those DocSlt cases to CI pipeline too. |
Agree with this, so the ROI is indeed not high enough, like Tao said.
Actually what I want is exactly to turn these examples for illustration into e2e tests, not the reverse. I'm not encouraging people to write e2e tests in doc comments, just like rustdoc doesn't encourage people to write unittests or integration tests in doctest. So I was thinking about introducing a simplified DSL for such tests, like:
so the tests won't be as verbose as slt tests. My point is that, we can have a more convenient way to document a function that handles some specific SQL cases, not to test the function. And since we can document it with SQL examples, why not execute it to force the correctness? I think the motivation is the same as Rust doctests.
Developer experience matters! Yes, a ref link to e2e tests is good, but it's apparently not that convenient. E2e tests are intended to test all possible cases, including corner cases and complex ones, however IMO they are too verbose to serve as examples. OTOH, they're also too distant from the code, devs may not be aware of that they break the e2e tests until the code modification is completed (think of small refactoring that seems do no harm). |
This is not my purpose. I want to make SQL examples in documentation tested, not to sync these examples with e2e tests. Converting the examples to e2e tests is the method, not the purpose. |
I'm sure its engineering complexity is very low. I can even finish it in one day :) |
Weak +1, I think it's a good idea just like I think rust doctest is very cool, and we've found a way to finish it with only a few effort. The SQL examples in comments are very WYSIWYG, and I think it's more clear than some long nerual language comments. |
We can't refer to a specified statements in this way (line number will be changed quickly and unmaintainable). We may have to create too many slt files if we use this way. |
The engineering complexity is very low, in brief:
|
I think if we always think things in the ROI way, we even can't get risedev :) |
Yep, I already finished most parts of the tool last night with less than 200 LoC. |
Request @skyzh for comments 😄
Too many slt files isn't bad IMO. Or what about considering |
Most e2e test now needs complex set-ups (like a few session variables). If we add more such variables in the future, I guess it would be hard to find and modify each single case in rustdoc. I don't have a clear answer for now whether we need docslt. It would be good to have a try and decide whether to migrate later. Some measures could be taken to reduce the complexity of docslt. e.g., we only allow testing simple projections / computation in slt. |
They (implementations of functions) are just the most useful use cases of docslt I can imagine. 🤔 |
(Off topic) Fun fact: only @BugenZhao @ZENOTME @wangrunji0408 and me has written doctests, and most of then are |
My doubt is that, unlike the doc test of Rust, we'll have no intuitive way to guarantee that the |
Since #5246 is merged, you can now write SQL examples in sqllogictest syntax in doc comments. The tests will be run on CI to force the correctness. Looking forward to bug reports and improvement suggestions. I also added some documentation for this tool in developer guide, feel free to check it out.😋 |
Background
Currently we write e2e tests in the form of sqllogictest scripts, and we have a dedicated
e2e_test
folder in the source tree for this. However, sometimes we may want to write some SQL examples directly in comments near the code to document the behavior of code, so that further modification won't break the tests easily.Such cases include:
risingwave/src/expr/src/expr/expr_array_concat.rs
Lines 76 to 83 in 14de3bf
https://github.com/risingwavelabs/risingwave/blob/5f8fd83064691677ea91d18c1a960d920c2f3a07/src/expr/src/vector_op/agg/functions.rs#L128-L133
https://github.com/risingwavelabs/risingwave/blob/5f8fd83064691677ea91d18c1a960d920c2f3a07/src/frontend/src/binder/query.rs#L48-L78
Design
Like rustdoc's documentation tests, this RFC introduces DocSlt, to allow running slt tests in doc comments.
Developers can write examples in slt syntax like below:
Then use the following commands to generate slt files from such documentation and run those slt tests:
The generated slt files should be added into source version control, just like the yaml files of planner tests.
The generation is in granularity of file, which means all the docslt blocks in one source file are placed in one slt file.
You can use
slt-setup
andslt-teardown
blocks to control the setup and teardown process, like this:All setup blocks in one source file will be added at the beginning of generated slt file. Similarly, all teardown blocks will be added at the end.
I've already implemented a demo for this RFC on branch
rc/docslt
, you can see the changes here: main...rc/docslt.Please feel free to give any comments!
Future Optimizations
No response
Discussions
Q&A
No response
The text was updated successfully, but these errors were encountered: