Skip to content

Conversation

@MaxKsyunz
Copy link

@MaxKsyunz MaxKsyunz commented Apr 26, 2022

  • Add support for match_phrase function in SQL parser
  • Extend and reorganize list of arguments of relevance functions
  • Add simple SQL parser test for match and match_phrase functions
  • Add complex random test for these functions for SQL parser

Signed-off-by: Yury Fridlyand [email protected]

@MaxKsyunz
Copy link
Author

@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++)
Copy link
Author

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) {
Copy link
Author

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())
Copy link
Author

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() ? "," : ", ");
Copy link
Author

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() ? ")" : ");");
Copy link
Author

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() ? '\'' : '"';
Copy link
Author

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[]>();
Copy link
Author

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.

@MaxKsyunz MaxKsyunz merged commit db81145 into dev-match_phrase-#185 Apr 28, 2022
@Yury-Fridlyand Yury-Fridlyand deleted the dev-match_phrase-#185-sql-syntax-min branch May 31, 2022 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants