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

Implementing LIKE Operator #330

Closed
wants to merge 3 commits into from
Closed

Conversation

syedsafi30
Copy link

Overview
The backend changes required to implement LIKE Operator, similar to SQL (As explained in issue #310) in JAVA are included in this PR.

Changes Included

  1. Added Conditional Statements for executing the Pattern matching conditions.
  2. Added Switch-Case Statements which perform different functionalities of LIKE Operator.

Overview
The backend changes required to implement LIKE Operator, similar to SQL (As explained in issue polypheny#310) in JAVA are included in this PR.

Changes Included
1. Added Conditional Statements for executing the Pattern matching conditions.
2. Added Switch-Case Statements which perform different functionalities of LIKE Operator.
@nilshansen94
Copy link
Member

Hi @syedsafi30. If I understand correctly, your implementation of the LIKE operator returns always true. The implementation did not solve the problems described in the issue. The first goal is to create a regular expression where all necessary characters are escaped (for example a dot should be escaped). The second goal is to provide support for the % and _ wildcards, as described in the link in the issue.
Does your implementation of the FIRST/LAST/CONTAINS operators work? If yes, could you provide an example (SQL code) on how to use these operators?
To make an example, the LIKE 'a..bc%d_ef' should result in the regex a\\.\\.bc.*d.ef or even better a\Q..\Ebc.*d.ef.

@syedsafi30
Copy link
Author

Hi @nilshansen94 , thanks for your response.
You are absolutely right, the LIKE operator which is implemented in the code returns true only if the pattern matches with the other (if the two strings are alike). The other operations of like Operator are performed by CONTAINS operator. It checks if a particular string contains a certain pattern(as we check for a pattern in SQL by entering %abe.whe% to check in a string. The CONTAINS operator does this task and returns true/false. The rest of the operations to check if a regex starts with or ends with a certain pattern are performed by FIRST & LAST operator( i suppose this can be done by using RIGHT & LEFT operator too).

I’ll be happy to take suggestions and improve the code further.

@nilshansen94
Copy link
Member

Hi @syedsafi30, thank you for your work. Your code does not work unfortunately. As mentioned before, the code in the case LIKE: ... always returns true;
To test your implementation, please make sure to work with a table that is placed on a file store only. Here is an example SQL code on how to set up such a table. There is also an example of a LIKE query and the expected result. The implementation should work in the same way as it does with a hsqldb table.

ALTER ADAPTERS ADD "file" USING 'org.polypheny.db.adapter.file.FileStore' WITH '{}';
CREATE TABLE "public"."user"("id" BIGINT NOT NULL,"name" VARCHAR(20),"comment" VARCHAR(174),PRIMARY KEY ("id")) ON STORE "file";
INSERT INTO public."user" (id, name, comment) values (1, 'anna', 'Hello world, how are you'), (2, 'bob', 'Hello World, how ore ya'), (3, 'john', 'hi');
select * from "user" where comment like 'Hell_ wo%'; --matches only the row with anna, because we're matching case-sensitive

The idea is that the query string in the parameterValue should be escaped and that the % should be replaced with a .* in the regular expression and the _ should be replaced with .. In the example, the parameterValue Hell_ wo% should be replaced with the regular expression Hell. wo.*. In my previous comment I made an example on how to escape special characters.

@syedsafi30
Copy link
Author

syedsafi30 commented Apr 13, 2021

Hi @nilshansen94 Thanks for your briefed response, I have started writing an algorithm towards resolving the issue to implement the LIKE operator and the wildcards as you have described above.

@vogti vogti added the S-waiting-on-author The pull request requires changes by the author label Apr 22, 2021
The backend changes required to implement LIKE Operator, similar to SQL (As explained in issue polypheny#310) in JAVA are included in this PR.

Changes Included
1. Replaces the parameterValue "%" as ".*"
2. Replaces the "_" wildcard to "."
@syedsafi30
Copy link
Author

Hi @nilshansen94, I have made the necessary changes to the file, please review them.

@hennlo hennlo added the S-blocked Something is blocking this pull request from being merged label Feb 27, 2022
@vogti vogti closed this Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Something is blocking this pull request from being merged S-waiting-on-author The pull request requires changes by the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants