[CALCITE-6042] Add test cases for ARRAY-related functions by using spark array function#3462
[CALCITE-6042] Add test cases for ARRAY-related functions by using spark array function#3462chucheng92 wants to merge 1 commit intoapache:mainfrom
Conversation
069b86c to
b1650cd
Compare
b1650cd to
34e14a4
Compare
| + "'SORT_ARRAY\\(<INTEGER ARRAY>, <INTEGER>\\)'\\." | ||
| + " Supported form\\(s\\): 'SORT_ARRAY\\(<ARRAY>\\)'\n" | ||
| + "'SORT_ARRAY\\(<ARRAY>, <BOOLEAN>\\)'", false); | ||
|
|
There was a problem hiding this comment.
This code is highly repetitive. There should be a way to reduce repetitions and make sure that the exact same code is executed modulo the array constructor. The test should be inside of a loop that iterates twice: once for constructors, once for functions.
Here is a possible way to implement this, not necessarily the best:
The query is generated by some string substitution process, e.g., a helper function "array_query" that is invoked like: array_query(false, "sort_array(%A%0)", "2, null, 1")
First argument is a false for arrays, and true for constructors, the second argument is a pattern, and the following arguments are all strings, with values to substitute in the pattern for %0, %1, etc. In this example %A%0 is substituted with either array(%0) or array[%0]; afterwards %0 is a positional argument that is substituted with the first argument.
If some tests do not work with constructors perhaps a second flag is needed to skip these, but I have proposed in the past to allow constructors for empty arrays. Hopefully we'll implement that as well, and then all the tests should pass in both cases.
There was a problem hiding this comment.
@mihaibudiu thanks mihai for reviewing, good comments, agree with you. I till try to optimize this duplication.
|
I have wrote a array-expr-generator, it looks like: the usage: the implemented method:
I feel it will be less readable, but it does remove duplicate code. @mihaibudiu what do you think? |
|
There is actually an even better way to do it, I should have thought about it sooner. The idea is to use Calcite itself to rewrite the code. The way this is done is by implementing a SqlShuttle which replaces calls to one of the operators with calls to the other one. Then for each test you:
Let me know if you need help implementing this solution. |
|
thanks for suggestions. @mihaibudiu Frankly speaking, I'm not sure if this is the best solution, it may be over-optimized, and the duplication in the PR may just be sonar's strategy (since I handle all array functions) Try to see if others have other opinions, I might be leaning towards good readability. |
…ark array function
34e14a4 to
e3d89b7
Compare
|
Kudos, SonarCloud Quality Gate passed! |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |








https://issues.apache.org/jira/browse/CALCITE-6042
Add test cases by using spark array function rather than calcite array constructor.
these cases only work in spark library.