-
Notifications
You must be signed in to change notification settings - Fork 0
Add match_phrase and slop optional parameter to SQL parser #44
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
Add match_phrase and slop optional parameter to SQL parser #44
Conversation
Signed-off-by: Yury Fridlyand <[email protected]>
…ents. Signed-off-by: Yury Fridlyand <[email protected]>
Signed-off-by: Yury Fridlyand <[email protected]>
Signed-off-by: Yury Fridlyand <[email protected]>
Signed-off-by: Yury Fridlyand <[email protected]>
|
@Yury-Fridlyand , FYI, SQL Java CI tasks are failing because PrettyFormatResponseIT test uses match_phrase. It should start passing once FilterQueryBuilder is updated. |
| private void generateAndTestQuery(String function, HashMap<String, Object[]> functionArgs) { | ||
| var rand = new Random(); | ||
|
|
||
| for (int i = 0; i < 100; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should exercise all combinations that are worth testing.
We can end up with a non-deterministic unit test if there are more than 100 test cases and there's a problem with one of them.
| assertNotNull(parser.parse("SELECT * FROM test WHERE match_phrase(column, 100500)")); | ||
| } | ||
|
|
||
| private void generateAndTestQuery(String function, HashMap<String, Object[]> functionArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test generator!
It's pretty complex -- let's make it easier to understand.
In this PR I'll comment on this test specifically.
As a separate task, I'd like to update it to use parametrized tests and to also use it for PPL.
| var args = new ArrayList<String>(); | ||
| for (var pair : functionArgs.entrySet()) | ||
| { | ||
| if (rand.nextBoolean()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this if-else control exactly?
| if (rand.nextBoolean()) | ||
| { | ||
| var arg = new StringBuilder(); | ||
| arg.append(rand.nextBoolean() ? "," : ", "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either "," or ", " are sufficient. Currently, it is exercising the existing lexer as opposed to the parser changes.
| Collections.shuffle(args); | ||
| for (var arg : args) | ||
| query.append(arg); | ||
| query.append(rand.nextBoolean() ? ")" : ");"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd skip switching between ")" and ");".
This is testing area of the parser that we did not affect.
| arg.append(rand.nextBoolean() ? pair.getKey().toLowerCase() : pair.getKey().toUpperCase()); | ||
| arg.append(rand.nextBoolean() ? "=" : " = "); | ||
| if (pair.getValue() instanceof String[] || rand.nextBoolean()) { | ||
| var quoteSymbol = rand.nextBoolean() ? '\'' : '"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pick either single or double quote and stick to that.
|
|
||
| generateAndTestQuery("match", matchArgs); | ||
|
|
||
| var matchPhraseArgs = new HashMap<String, Object[]>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good place to use ImmutableMap builder -- https://guava.dev/releases/19.0/api/docs/com/google/common/collect/ImmutableMap.Builder.html
SQL plugin already depends on guava.
match_phrasefunction in SQL parsermatchandmatch_phrasefunctionsSigned-off-by: Yury Fridlyand [email protected]