You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/06/10 16:58:28 UTC
[GitHub] [solr] thelabdude opened a new pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
thelabdude opened a new pull request #173:
URL: https://github.com/apache/solr/pull/173
https://issues.apache.org/jira/browse/SOLR-15460
Also fixes: SOLR-15459 & SOLR-15463
# Description
Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
# Solution
New methods added for additional operators to SolrFilter; also made HavingTranslator extend Translator to reduce code duplication in this class.
# Tests
Additional unit tests added to the existing TestSQLHandler
# Checklist
Please review the following and check all that apply:
- [ ] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
- [ ] I have created a Jira issue and added the issue ID to my pull request title.
- [ ] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
- [ ] I have developed this patch against the `main` branch.
- [ ] I have run `./gradlew check`.
- [ ] I have added tests for my changes.
- [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] thelabdude commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
thelabdude commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651961736
##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
##########
@@ -69,34 +78,81 @@ public void implement(Implementor implementor) {
private static class Translator {
- private final List<String> fieldNames;
+ protected final List<String> fieldNames;
public boolean negativeQuery = true;
Translator(List<String> fieldNames) {
this.fieldNames = fieldNames;
}
- private String translateMatch(RexNode condition) {
- if (condition.getKind().belongsTo(SqlKind.COMPARISON)) {
+ protected String translateMatch(RexNode condition) {
+ final SqlKind kind = condition.getKind();
+ if (kind.belongsTo(SqlKind.COMPARISON) || kind == SqlKind.NOT) {
return translateComparison(condition);
} else if (condition.isA(SqlKind.AND)) {
- return "(" + translateAnd(condition) + ")";
+ // see if this is a translated range query of greater than or equals and less than or equal on same field
+ // if so, then collapse into a single range criteria, e.g. field:[gte TO lte] instead of two ranges AND'd together
+ RexCall call = (RexCall) condition;
+ List<RexNode> operands = call.getOperands();
+ return (operands.size() == 2 && operands.get(0).getKind() == SqlKind.GREATER_THAN_OR_EQUAL && operands.get(1).getKind() == SqlKind.LESS_THAN_OR_EQUAL)
+ ? translateRangeFilter(call) : "(" + translateAnd(condition) + ")";
} else if (condition.isA(SqlKind.OR)) {
return "(" + translateOr(condition) + ")";
+ } else if (kind == SqlKind.LIKE) {
+ return translateLike(condition, false);
+ } else if (kind == SqlKind.IS_NOT_NULL || kind == SqlKind.IS_NULL) {
+ return translateIsNullOrIsNotNull(condition);
} else {
return null;
}
}
- private String translateOr(RexNode condition) {
+ protected String translateRangeFilter(RexCall andNode) {
Review comment:
After completely botching this a few times, I think we have it sorted out. Thanks to @HoustonPutman for walking me through the seemingly simple nuances ;-)
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] madrob commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651149156
##########
File path: solr/solr-ref-guide/src/parallel-sql-interface.adoc
##########
@@ -240,16 +240,20 @@ The parallel SQL interface supports and pushes down most common SQL operators, s
|= |Equals |`fielda = 10` |`fielda:10`
|<> |Does not equal |`fielda <> 10` |`-fielda:10`
|!= |Does not equal |`fielda != 10` |`-fielda:10`
-|> |Greater than |`fielda > 10` | `fielda:{10 TO *]`
-|>= |Greater than or equals |`fielda >= 10` | `fielda:[10 TO *]`
-|< |Less than |`fielda < 10` | `fielda:[* TO 10}`
-|\<= |Less than or equals |`fielda \<= 10` | `fielda:[* TO 10]`
+|> |Greater than |`fielda > 10` |`fielda:{10 TO *]`
+|>= |Greater than or equals |`fielda >= 10` |`fielda:[10 TO *]`
+|< |Less than |`fielda < 10` |`fielda:[* TO 10}`
+|\<= |Less than or equals |`fielda \<= 10` |`fielda:[* TO 10]`
+|IN |Specify multiple values (shorthand for multiple OR clasues) |`fielda IN (10,20,30)` |`(fielda:10 OR fielda:20 OR fielda:30)`
+|LIKE |Wildcard match on string or text fields |`fielda LIKE 'day%'` |`{!complexphrase}fielda:"day*"`
+|BETWEEN |Range match |`fielda BETWEEN 2 AND 2` |`((fielda: [2 TO *]) AND (fielda: [* TO 4]))`
Review comment:
Did you mean
```suggestion
|BETWEEN |Range match |`fielda BETWEEN 2 AND 4` |`((fielda: [2 TO *]) AND (fielda: [* TO 4]))`
```
##########
File path: solr/solr-ref-guide/src/parallel-sql-interface.adoc
##########
@@ -240,16 +240,20 @@ The parallel SQL interface supports and pushes down most common SQL operators, s
|= |Equals |`fielda = 10` |`fielda:10`
|<> |Does not equal |`fielda <> 10` |`-fielda:10`
|!= |Does not equal |`fielda != 10` |`-fielda:10`
-|> |Greater than |`fielda > 10` | `fielda:{10 TO *]`
-|>= |Greater than or equals |`fielda >= 10` | `fielda:[10 TO *]`
-|< |Less than |`fielda < 10` | `fielda:[* TO 10}`
-|\<= |Less than or equals |`fielda \<= 10` | `fielda:[* TO 10]`
+|> |Greater than |`fielda > 10` |`fielda:{10 TO *]`
+|>= |Greater than or equals |`fielda >= 10` |`fielda:[10 TO *]`
+|< |Less than |`fielda < 10` |`fielda:[* TO 10}`
+|\<= |Less than or equals |`fielda \<= 10` |`fielda:[* TO 10]`
+|IN |Specify multiple values (shorthand for multiple OR clasues) |`fielda IN (10,20,30)` |`(fielda:10 OR fielda:20 OR fielda:30)`
+|LIKE |Wildcard match on string or text fields |`fielda LIKE 'day%'` |`{!complexphrase}fielda:"day*"`
+|BETWEEN |Range match |`fielda BETWEEN 2 AND 2` |`((fielda: [2 TO *]) AND (fielda: [* TO 4]))`
Review comment:
Also, it's weird to me that BETWEEN needs to be a conjunction of two ranges?
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] HoustonPutman commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
HoustonPutman commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651185894
##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
##########
@@ -69,34 +78,81 @@ public void implement(Implementor implementor) {
private static class Translator {
- private final List<String> fieldNames;
+ protected final List<String> fieldNames;
public boolean negativeQuery = true;
Translator(List<String> fieldNames) {
this.fieldNames = fieldNames;
}
- private String translateMatch(RexNode condition) {
- if (condition.getKind().belongsTo(SqlKind.COMPARISON)) {
+ protected String translateMatch(RexNode condition) {
+ final SqlKind kind = condition.getKind();
+ if (kind.belongsTo(SqlKind.COMPARISON) || kind == SqlKind.NOT) {
return translateComparison(condition);
} else if (condition.isA(SqlKind.AND)) {
- return "(" + translateAnd(condition) + ")";
+ // see if this is a translated range query of greater than or equals and less than or equal on same field
+ // if so, then collapse into a single range criteria, e.g. field:[gte TO lte] instead of two ranges AND'd together
+ RexCall call = (RexCall) condition;
+ List<RexNode> operands = call.getOperands();
+ return (operands.size() == 2 && operands.get(0).getKind() == SqlKind.GREATER_THAN_OR_EQUAL && operands.get(1).getKind() == SqlKind.LESS_THAN_OR_EQUAL)
+ ? translateRangeFilter(call) : "(" + translateAnd(condition) + ")";
} else if (condition.isA(SqlKind.OR)) {
return "(" + translateOr(condition) + ")";
+ } else if (kind == SqlKind.LIKE) {
+ return translateLike(condition, false);
+ } else if (kind == SqlKind.IS_NOT_NULL || kind == SqlKind.IS_NULL) {
+ return translateIsNullOrIsNotNull(condition);
} else {
return null;
}
}
- private String translateOr(RexNode condition) {
+ protected String translateRangeFilter(RexCall andNode) {
Review comment:
Unfortunately, I'm not sure this works...
With multi-value fields, this syntax is certainly not identical. i.e. fielda= [1, 5] does not match `fielda:[2 TO 4]`... but does match `fielda:[2 TO *] and fielda:[* TO 4]`
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] anshumg commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
anshumg commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r649583391
##########
File path: solr/solr-ref-guide/src/parallel-sql-interface.adoc
##########
@@ -95,7 +95,7 @@ The JDBC Driver ships with SolrJ. Below is sample code for creating a connection
----
Connection con = null;
try {
- con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1&aggregationMode=map_reduce&numWorkers=2");
+ con = DriverManager.getConnection("jdbc:solr://" zkHost "?collection=collection1&aggregationMode=map_reduce&numWorkers=2");
Review comment:
I guess this is accidental?
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] thelabdude commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
thelabdude commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651153308
##########
File path: solr/solr-ref-guide/src/parallel-sql-interface.adoc
##########
@@ -240,16 +240,20 @@ The parallel SQL interface supports and pushes down most common SQL operators, s
|= |Equals |`fielda = 10` |`fielda:10`
|<> |Does not equal |`fielda <> 10` |`-fielda:10`
|!= |Does not equal |`fielda != 10` |`-fielda:10`
-|> |Greater than |`fielda > 10` | `fielda:{10 TO *]`
-|>= |Greater than or equals |`fielda >= 10` | `fielda:[10 TO *]`
-|< |Less than |`fielda < 10` | `fielda:[* TO 10}`
-|\<= |Less than or equals |`fielda \<= 10` | `fielda:[* TO 10]`
+|> |Greater than |`fielda > 10` |`fielda:{10 TO *]`
+|>= |Greater than or equals |`fielda >= 10` |`fielda:[10 TO *]`
+|< |Less than |`fielda < 10` |`fielda:[* TO 10}`
+|\<= |Less than or equals |`fielda \<= 10` |`fielda:[* TO 10]`
+|IN |Specify multiple values (shorthand for multiple OR clasues) |`fielda IN (10,20,30)` |`(fielda:10 OR fielda:20 OR fielda:30)`
+|LIKE |Wildcard match on string or text fields |`fielda LIKE 'day%'` |`{!complexphrase}fielda:"day*"`
+|BETWEEN |Range match |`fielda BETWEEN 2 AND 2` |`((fielda: [2 TO *]) AND (fielda: [* TO 4]))`
Review comment:
Agreed on that ... that's existing code but will look into changing it ;-)
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] thelabdude commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
thelabdude commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651156752
##########
File path: solr/solr-ref-guide/src/parallel-sql-interface.adoc
##########
@@ -240,16 +240,20 @@ The parallel SQL interface supports and pushes down most common SQL operators, s
|= |Equals |`fielda = 10` |`fielda:10`
|<> |Does not equal |`fielda <> 10` |`-fielda:10`
|!= |Does not equal |`fielda != 10` |`-fielda:10`
-|> |Greater than |`fielda > 10` | `fielda:{10 TO *]`
-|>= |Greater than or equals |`fielda >= 10` | `fielda:[10 TO *]`
-|< |Less than |`fielda < 10` | `fielda:[* TO 10}`
-|\<= |Less than or equals |`fielda \<= 10` | `fielda:[* TO 10]`
+|> |Greater than |`fielda > 10` |`fielda:{10 TO *]`
+|>= |Greater than or equals |`fielda >= 10` |`fielda:[10 TO *]`
+|< |Less than |`fielda < 10` |`fielda:[* TO 10}`
+|\<= |Less than or equals |`fielda \<= 10` |`fielda:[* TO 10]`
+|IN |Specify multiple values (shorthand for multiple OR clasues) |`fielda IN (10,20,30)` |`(fielda:10 OR fielda:20 OR fielda:30)`
+|LIKE |Wildcard match on string or text fields |`fielda LIKE 'day%'` |`{!complexphrase}fielda:"day*"`
+|BETWEEN |Range match |`fielda BETWEEN 2 AND 2` |`((fielda: [2 TO *]) AND (fielda: [* TO 4]))`
Review comment:
heh ... it's because Calcite transforms the expression into `AND(>=($2, 2), <=($2, 4))`, i.e. BETWEEN is just syntactic sugar and the Solr code ends up seeing: `field >= 2 AND field <= 4`.
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] thelabdude commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
thelabdude commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651204998
##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
##########
@@ -69,34 +78,81 @@ public void implement(Implementor implementor) {
private static class Translator {
- private final List<String> fieldNames;
+ protected final List<String> fieldNames;
public boolean negativeQuery = true;
Translator(List<String> fieldNames) {
this.fieldNames = fieldNames;
}
- private String translateMatch(RexNode condition) {
- if (condition.getKind().belongsTo(SqlKind.COMPARISON)) {
+ protected String translateMatch(RexNode condition) {
+ final SqlKind kind = condition.getKind();
+ if (kind.belongsTo(SqlKind.COMPARISON) || kind == SqlKind.NOT) {
return translateComparison(condition);
} else if (condition.isA(SqlKind.AND)) {
- return "(" + translateAnd(condition) + ")";
+ // see if this is a translated range query of greater than or equals and less than or equal on same field
+ // if so, then collapse into a single range criteria, e.g. field:[gte TO lte] instead of two ranges AND'd together
+ RexCall call = (RexCall) condition;
+ List<RexNode> operands = call.getOperands();
+ return (operands.size() == 2 && operands.get(0).getKind() == SqlKind.GREATER_THAN_OR_EQUAL && operands.get(1).getKind() == SqlKind.LESS_THAN_OR_EQUAL)
+ ? translateRangeFilter(call) : "(" + translateAnd(condition) + ")";
} else if (condition.isA(SqlKind.OR)) {
return "(" + translateOr(condition) + ")";
+ } else if (kind == SqlKind.LIKE) {
+ return translateLike(condition, false);
+ } else if (kind == SqlKind.IS_NOT_NULL || kind == SqlKind.IS_NULL) {
+ return translateIsNullOrIsNotNull(condition);
} else {
return null;
}
}
- private String translateOr(RexNode condition) {
+ protected String translateRangeFilter(RexCall andNode) {
Review comment:
ah ha! thanks @HoustonPutman, did not know that! Will remove this and stick with the 2 AND'd clauses. I'll also get some unit tests with multi-valued fields in place for this as well
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] madrob commented on a change in pull request #173: SOLR-15460: Implement LIKE, IS NOT NULL, IS NULL, and support wildcard * in equals string literal
Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651180874
##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
##########
@@ -69,34 +78,81 @@ public void implement(Implementor implementor) {
private static class Translator {
- private final List<String> fieldNames;
+ protected final List<String> fieldNames;
public boolean negativeQuery = true;
Translator(List<String> fieldNames) {
this.fieldNames = fieldNames;
}
- private String translateMatch(RexNode condition) {
- if (condition.getKind().belongsTo(SqlKind.COMPARISON)) {
+ protected String translateMatch(RexNode condition) {
+ final SqlKind kind = condition.getKind();
+ if (kind.belongsTo(SqlKind.COMPARISON) || kind == SqlKind.NOT) {
return translateComparison(condition);
} else if (condition.isA(SqlKind.AND)) {
- return "(" + translateAnd(condition) + ")";
+ // see if this is a translated range query of greater than or equals and less than or equal on same field
+ // if so, then collapse into a single range criteria, e.g. field:[gte TO lte] instead of two ranges AND'd together
+ RexCall call = (RexCall) condition;
+ List<RexNode> operands = call.getOperands();
+ return (operands.size() == 2 && operands.get(0).getKind() == SqlKind.GREATER_THAN_OR_EQUAL && operands.get(1).getKind() == SqlKind.LESS_THAN_OR_EQUAL)
+ ? translateRangeFilter(call) : "(" + translateAnd(condition) + ")";
} else if (condition.isA(SqlKind.OR)) {
return "(" + translateOr(condition) + ")";
+ } else if (kind == SqlKind.LIKE) {
+ return translateLike(condition, false);
+ } else if (kind == SqlKind.IS_NOT_NULL || kind == SqlKind.IS_NULL) {
+ return translateIsNullOrIsNotNull(condition);
} else {
return null;
}
}
- private String translateOr(RexNode condition) {
+ protected String translateRangeFilter(RexCall andNode) {
Review comment:
Is this a generic optimization that would make sense to do outside of the SQL implementation, and we can leave the naive calcite translation in place?
--
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org