Jackie-Jiang commented on a change in pull request #7214:
URL: https://github.com/apache/pinot/pull/7214#discussion_r687254438



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {

Review comment:
       (nit)
   ```suggestion
   public class LikeToRegexpLikePatternConverterUtils {
   ```

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {
+  /* Represents all metacharacters to be processed */
+  public static final String[] REGEXP_METACHARACTERS  = 
{"\\","^","$","{","}","[","]","(",")",
+      "*","+","?","|","<",">","-","&"};
+
+  /**
+   * Process an incoming LIKE string and make it regexp friendly
+   * @param value LIKE operator styled predicate
+   * @return Result regex
+   */
+  public static String processValue(String value) {
+    String result = escapeMetaCharacters(value);
+
+    result = result.replace(".", "\\.");
+    // ... escape any other potentially problematic characters here
+    result = result.replace("?", ".");
+
+    return result.replaceAll("(?<!\\\\)%", ".*");
+  }
+
+  /**
+   * Add escape characters before special characters
+   */
+  private static String escapeMetaCharacters(String inputString) {
+
+    for (int i = 0 ; i < REGEXP_METACHARACTERS.length ; i++){

Review comment:
       Also reformat
   ```suggestion
       for (String metaCharacter : REGEXP_METACHARACTERS) {
   ```

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {
+  /* Represents all metacharacters to be processed */
+  public static final String[] REGEXP_METACHARACTERS  = 
{"\\","^","$","{","}","[","]","(",")",
+      "*","+","?","|","<",">","-","&"};
+
+  /**
+   * Process an incoming LIKE string and make it regexp friendly
+   * @param value LIKE operator styled predicate
+   * @return Result regex
+   */
+  public static String processValue(String value) {
+    String result = escapeMetaCharacters(value);
+
+    result = result.replace(".", "\\.");
+    // ... escape any other potentially problematic characters here
+    result = result.replace("?", ".");
+
+    return result.replaceAll("(?<!\\\\)%", ".*");

Review comment:
       Why do we replace all of them instead of just `%`?

##########
File path: 
pinot-common/src/test/java/org/apache/pinot/util/TestLikeSyntaxConverter.java
##########
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.util;
+
+import org.apache.pinot.common.utils.LikeToRegexFormatConverterUtil;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@LikeToRegexFormatConverterUtil}
+ */
+public class TestLikeSyntaxConverter {
+
+  private static final String TRAILING_WILDCARD = "C+%";

Review comment:
       Can we add more test cases? Currently there is no test case with single 
character pattern, or wildcard in the middle

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {
+  /* Represents all metacharacters to be processed */
+  public static final String[] REGEXP_METACHARACTERS  = 
{"\\","^","$","{","}","[","]","(",")",
+      "*","+","?","|","<",">","-","&"};
+
+  /**
+   * Process an incoming LIKE string and make it regexp friendly
+   * @param value LIKE operator styled predicate
+   * @return Result regex
+   */
+  public static String processValue(String value) {
+    String result = escapeMetaCharacters(value);
+
+    result = result.replace(".", "\\.");

Review comment:
       Why not handle `.` as meta character?

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {
+  /* Represents all metacharacters to be processed */
+  public static final String[] REGEXP_METACHARACTERS  = 
{"\\","^","$","{","}","[","]","(",")",
+      "*","+","?","|","<",">","-","&"};
+
+  /**
+   * Process an incoming LIKE string and make it regexp friendly
+   * @param value LIKE operator styled predicate
+   * @return Result regex
+   */
+  public static String processValue(String value) {

Review comment:
       (nit)
   ```suggestion
     public static String convertLikePattern(String pattern) {
   ```

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/Predicate.java
##########
@@ -28,7 +28,7 @@
  */
 public interface Predicate {
   enum Type {
-    EQ, NOT_EQ, IN, NOT_IN, RANGE, REGEXP_LIKE, TEXT_MATCH, JSON_MATCH, 
IS_NULL, IS_NOT_NULL;
+    EQ, NOT_EQ, IN, NOT_IN, RANGE, REGEXP_LIKE, LIKE, TEXT_MATCH, JSON_MATCH, 
IS_NULL, IS_NOT_NULL;

Review comment:
       We don't need to add `LIKE` since it is solved as `REGEXP_LIKE`

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexFormatConverterUtil.java
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+/**
+ * Utility for converting LIKE operator syntax to a regex
+ */
+public class LikeToRegexFormatConverterUtil {
+  /* Represents all metacharacters to be processed */
+  public static final String[] REGEXP_METACHARACTERS  = 
{"\\","^","$","{","}","[","]","(",")",
+      "*","+","?","|","<",">","-","&"};
+
+  /**
+   * Process an incoming LIKE string and make it regexp friendly
+   * @param value LIKE operator styled predicate
+   * @return Result regex
+   */
+  public static String processValue(String value) {
+    String result = escapeMetaCharacters(value);
+
+    result = result.replace(".", "\\.");
+    // ... escape any other potentially problematic characters here
+    result = result.replace("?", ".");

Review comment:
       Which standard are we taking here? Per this page: 
https://www.w3schools.com/sql/sql_like.asp, `_` is used to represent single 
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.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to