You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/02/22 19:36:20 UTC
[GitHub] [geode] mkevo opened a new pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
mkevo opened a new pull request #6044:
URL: https://github.com/apache/geode/pull/6044
Thank you for submitting a contribution to Apache Geode.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
- [x] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
- [x] Is your initial contribution a single, squashed commit?
- [x] Does `gradlew build` run cleanly?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
### Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] kirklund commented on a change in pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
kirklund commented on a change in pull request #6044:
URL: https://github.com/apache/geode/pull/6044#discussion_r583876477
##########
File path: geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommandDUnitTestBase.java
##########
@@ -200,6 +212,14 @@ private static void prepareDataForRegion(String regionPath) {
}
}
+ private static void prepareDataForRegionWithSpecialCharacters(String regionPath) {
+ InternalCache cache = ClusterStartupRule.getCache();
+ Region dataRegion = cache.getRegion(regionPath);
Review comment:
Don't worry about the other lines in this old class that use raw types.
##########
File path: geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommandDUnitTestBase.java
##########
@@ -200,6 +212,14 @@ private static void prepareDataForRegion(String regionPath) {
}
}
+ private static void prepareDataForRegionWithSpecialCharacters(String regionPath) {
+ InternalCache cache = ClusterStartupRule.getCache();
+ Region dataRegion = cache.getRegion(regionPath);
Review comment:
Please try to use non-raw types in places like this. There's an IntelliJ inspection you can enable that'll highlight lines like this:
```
Region<Integer, String> dataRegion = cache.getRegion(regionPath);
dataRegion.put(1, "value$");
dataRegion.put(2, "value%");
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] agingade commented on a change in pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
agingade commented on a change in pull request #6044:
URL: https://github.com/apache/geode/pull/6044#discussion_r582372036
##########
File path: geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledLike.java
##########
@@ -349,6 +349,30 @@ private String getRegexPattern(String pattern) {
sb.append(ch);
}
break;
+ case '$': // replace with [$]
+ if (prevMetaChar) {
+ sb.append('\\');
+ sb.append('E');
+ prevMetaChar = false;
+ }
+
+ numConsecutiveBackSlash = 0;
+ for (int j = i - 1; j > -1; --j) {
+ if (pattern.charAt(j) == '\\') {
+ ++numConsecutiveBackSlash;
+ } else {
+ break;
+ }
+ }
+
+ // Check if the $ has a valid escape. Backtrack to check for \.
Review comment:
Why "$" needs to be escaped being a literal in like predicate value. The special characters that are used in LIKE or "_", "%" and "\" these chars needs to be escaped with escape char "\".
I think we should be able to compare the "$" literal within the like predicate without escaping it. Please let me know if I am missing anything.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mkevo commented on a change in pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
mkevo commented on a change in pull request #6044:
URL: https://github.com/apache/geode/pull/6044#discussion_r582591477
##########
File path: geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledLike.java
##########
@@ -349,6 +349,30 @@ private String getRegexPattern(String pattern) {
sb.append(ch);
}
break;
+ case '$': // replace with [$]
+ if (prevMetaChar) {
+ sb.append('\\');
+ sb.append('E');
+ prevMetaChar = false;
+ }
+
+ numConsecutiveBackSlash = 0;
+ for (int j = i - 1; j > -1; --j) {
+ if (pattern.charAt(j) == '\\') {
+ ++numConsecutiveBackSlash;
+ } else {
+ break;
+ }
+ }
+
+ // Check if the $ has a valid escape. Backtrack to check for \.
Review comment:
When it use the compare operation it checks string, but when using LIKE operation it check character by character, and when comes to "$" character it present it like endline character and cannot got right results. Now with escaping it will check if string has "$" character and compare it like any other character.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mkevo merged pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
mkevo merged pull request #6044:
URL: https://github.com/apache/geode/pull/6044
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nabarunnag commented on a change in pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
nabarunnag commented on a change in pull request #6044:
URL: https://github.com/apache/geode/pull/6044#discussion_r580678544
##########
File path: geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/QueryCommandDUnitTestBase.java
##########
@@ -141,6 +141,19 @@ public void testSimpleQuery() {
new String[] {"ID", "status", "createTime", "pk", "floatMinValue"});
}
+ @Test
+ public void testSimpleQueryWithEscapingCharacter() {
+ server1.invoke(() -> prepareDataForRegionWithSpecialCharacters(DATA_PAR_REGION_NAME_PATH));
+ String query = "query --query=\"select * from " + DATA_PAR_REGION_NAME_PATH
+ + " e where e LIKE 'value\\$'\"";
+ String query1 = "query --query=\"select * from " + DATA_PAR_REGION_NAME_PATH
+ + " e where e LIKE 'value\\%'\"";
+ CommandResult commandResult = gfsh.executeCommand(query);
+ CommandResult commandResult1 = gfsh.executeCommand(query1);
+ validateSelectResult(commandResult, true, 1, null);
+ validateSelectResult(commandResult1, true, 1, null);
Review comment:
```suggestion
gfsh.executeAndAssertThat(query).statusIsSuccess().containsOutput("value$");
gfsh.executeAndAssertThat(query1).statusIsSuccess().containsOutput("value%");
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mkevo commented on pull request #6044: GEODE-8962: add an option to escape dollar($) character in query
Posted by GitBox <gi...@apache.org>.
mkevo commented on pull request #6044:
URL: https://github.com/apache/geode/pull/6044#issuecomment-800057034
Hi @nabarunnag, can you please re-review this?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org