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



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexpLikePatternConverterUtils.java
##########
@@ -0,0 +1,56 @@
+/**
+ * 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 LikeToRegexpLikePatternConverterUtils {
+  /* 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);
+
+    // ... 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 (String metaCharacter : REGEXP_METACHARACTERS) {
+      if(inputString.contains(metaCharacter)){

Review comment:
       (nit) code format

##########
File path: 
pinot-common/src/test/java/org/apache/pinot/util/TestLikeSyntaxConverter.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.LikeToRegexpLikePatternConverterUtils;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@LikeToRegexFormatConverterUtil}
+ */
+public class TestLikeSyntaxConverter {
+
+  private static final String TRAILING_WILDCARD = "C+%";
+  private static final String LEADING_WILDCARD = "%++";

Review comment:
       (nit) put `LEADING_WILDCARD` in front of `TRAILING_WILDCARD` to match 
the order of the test for readability.
   Also suggest putting the expected result as constant for clarity

##########
File path: 
pinot-common/src/test/java/org/apache/pinot/util/TestLikeSyntaxConverter.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.LikeToRegexpLikePatternConverterUtils;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@LikeToRegexFormatConverterUtil}

Review comment:
       Update the class name

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/utils/LikeToRegexpLikePatternConverterUtils.java
##########
@@ -0,0 +1,56 @@
+/**
+ * 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 LikeToRegexpLikePatternConverterUtils {
+  /* 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);
+
+    // ... escape any other potentially problematic characters here
+    result = result.replace("_", ".");
+
+    return result.replaceAll("%", ".*");

Review comment:
       Use `replace` instead of `replaceAll` to avoid regex match. The first 
replace can be optimized by passing in `char` instead of `String`. The whole 
method can be simplified to:
   ```suggestion
       return escapeMetaCharacters(value).replace('_', '.').replace("%", ".*");
   ```

##########
File path: 
pinot-core/src/test/java/org/apache/pinot/queries/FSTBasedRegexpLikeQueriesTest.java
##########
@@ -344,6 +344,22 @@ public void testFSTBasedRegexLike()
     testSelectionResults(query, 5, null);
   }
 
+  @Test
+  public void testLikeOperator()
+      throws Exception {
+    String query = "SELECT INT_COL, URL_COL FROM MyTable WHERE DOMAIN_NAMES 
LIKE 'www.domain1%' LIMIT 50000";

Review comment:
       Let's add some queries with `_` and mixed `_` and `%`

##########
File path: 
pinot-common/src/test/java/org/apache/pinot/util/TestLikeSyntaxConverter.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.LikeToRegexpLikePatternConverterUtils;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests for {@LikeToRegexFormatConverterUtil}
+ */
+public class TestLikeSyntaxConverter {

Review comment:
       Suggest renaming to `LikeToRegexpLikePatternConverterUtilsTest` to match 
the naming convention for the tests




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