Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Support LIKE operator #534

Merged

Conversation

chloe-zh
Copy link
Member

@chloe-zh chloe-zh commented Jun 26, 2020

Issue #, if available:

Description of changes:

Syntax: string like pattern
The pattern supports string literal with percent(%) character for wildcard and underscore(_) character for single character. Here are some examples:
foobar like 'foobar%' -> true
foobar like '%bar' -> true
foobar like '%BAR' -> false
foobar like 'fooba_' -> true
foobar like 'foobar_' -> false
foobar like '%ba_' -> true

For null values and missing values in LIKE operation, the results follows AsterixDB standard:

A B A like B
NULL NULL NULL
NULL MISSING MISSING
MISSING NULL MISSING
MISSING MISSING MISSING

Reference: CrateDB

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Member

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides IT, could you add a doctest for this?

@chloe-zh
Copy link
Member Author

Besides IT, could you add a doctest for this?

Thanks @dai-chen ! The doc of operators have not been created/updated, can I add the doc test when adding the experimental doc in another PR?

@dai-chen
Copy link
Member

Besides IT, could you add a doctest for this?

Thanks @dai-chen ! The doc of operators have not been created/updated, can I add the doc test when adding the experimental doc in another PR?

Sure, no problem! Next time probably we can start from doc to drive the coding and save the trouble of adding all docs at last. :)

Copy link
Member

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!


private static final char DEFAULT_ESCAPE = '\\';

private static String patternToRegex(String patternString) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. could you seperate it from OperatorUtils in case is more focus on SQL regex to Java regex.
  2. by define the ESCAPE is defined in SQL language, how do we support it?
  3. is it possible to seperate the translation rule from translation logic.
    for example,
    TranslationRule.Buidler.put("//%", %").put("%", ".*").build()
    Then, apply rule on the input REGEX.

Copy link
Contributor

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chloe-zh chloe-zh merged commit 05d3699 into opendistro-for-elasticsearch:develop Jul 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants