xuzifu666 commented on code in PR #4434:
URL: https://github.com/apache/calcite/pull/4434#discussion_r2165248214


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/QueryBuilders.java:
##########
@@ -497,14 +510,80 @@ static class RegexpQueryBuilder extends QueryBuilder {
     private final String fieldName;
     @SuppressWarnings("unused")
     private final String value;
+    @SuppressWarnings("unused")
+    private String escape;
 
     RegexpQueryBuilder(final String fieldName, final String value) {
+      this(fieldName, value, "\\");
+    }
+
+    RegexpQueryBuilder(final String fieldName, final String value, final 
String escape) {
+      requireNonNull(fieldName, "fieldName");
+      requireNonNull(value, "value");
+      requireNonNull(escape, "escape");
       this.fieldName = fieldName;
-      this.value = value;
+      this.escape = escape;
+      // replace % to * and _ to ? for sql with like operator
+      HashMap<String, String> kv = new HashMap<>();
+      kv.put("%", "*");
+      kv.put("_", "?");
+      this.value = replaceWildcard(value, kv, escape);
+    }
+
+    public static String replaceWildcard(String value, Map<String, String> kv, 
String escape) {

Review Comment:
   Thank for the suggestion, I checked the specific implementation of 
SqlFunction.LIKE and found it is different from the LIKE in ElasticSearch, 
because the previous implementation does not need to replace escape char and is 
can not to reuse directly. 
   Another point is that the recording logic of ElasticSearch LIKE is made into 
json and then sunk to the ElasticSearch engine for execution, which is 
fundamentally different from SqlFunction.LIKE,so maybe this separate 
implementation is more appropriate IMO. @mihaibudiu 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to