Skip to content
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

feat: add support for POSITION() #159

Merged
merged 2 commits into from
Mar 14, 2024
Merged

feat: add support for POSITION() #159

merged 2 commits into from
Mar 14, 2024

Conversation

crwen
Copy link
Member

@crwen crwen commented Mar 14, 2024

What problem does this PR solve?

Support for POSITION() Function. POSITION(pattern in s USING CHARACTERS/OCTETS) is not implemented since it's not supported by sqlparser

Issue link: #130

What is changed and how it works?

=> SELECT POSITION('bc' in 'abcd');
 position(bc in abcd)
----------------------
                    2
(1 row)

=> SELECT POSITION('de' in 'abcd');
 position(de in abcd)
----------------------
                    0
(1 row)

Code changes

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

@KKould KKould self-requested a review March 14, 2024 08:57
@KKould KKould added the enhancement New feature or request label Mar 14, 2024
Copy link
Member

@KKould KKould left a comment

Choose a reason for hiding this comment

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

Very good code, makes me spin, please take a look at my comment

@@ -2,10 +2,10 @@

# TODO: POSITION()
Copy link
Member

Choose a reason for hiding this comment

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

Please delete this comment

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

let pattern = unpack(expr)?;
let str = unpack(in_expr)?;
Ok(Arc::new(DataValue::Int32(
if let Some(pos) = str.find(&pattern) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the code can be simplified here

str.find(&pattern)
    .map(|pos| pos as i32 + 1)
    .unwrap_or(0)

@KKould KKould mentioned this pull request Mar 14, 2024
51 tasks
@KKould KKould merged commit be5cad5 into KipData:main Mar 14, 2024
3 checks passed
@KKould
Copy link
Member

KKould commented Mar 14, 2024

Thanks for your contribution.🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants