You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/07/30 07:52:04 UTC

[GitHub] [iotdb] ijihang opened a new pull request #3649: [IOTDB-1536]Support fuzzy query

ijihang opened a new pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649


   JIRA:https://issues.apache.org/jira/browse/IOTDB-1536
   
   support:
   select * from root.sg.device where s1 like 'String'
   select * from root.sg.device where s1 like 'String' and time > timestamp
   select * from root.sg.device where s1 like 'String' and s2 like 'String' 
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Superainbower commented on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Superainbower commented on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897492816


   @ijihang 
   Hi, i try to modify org.apache.iotdb.tsfile.read.filter.operator.Like like this:
   ![image](https://user-images.githubusercontent.com/35786966/129174589-6244a075-f34d-4fc8-aba6-7460a2f046ee.png)
   
   And get result like this:
   ![image](https://user-images.githubusercontent.com/35786966/129174467-8a7de44b-c41e-4006-8b1f-87feda2f62ae.png)
   
    We should use % like mysql 
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Alima777 commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Alima777 commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r684736877



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  private Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    if (filterType != FilterType.VALUE_FILTER) {
+      return false;
+    }
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", value.toString(), e.getIndex());
+    }

Review comment:
       Put this in constructor method and storage pattern as class parameter.




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/41993503/badge)](https://coveralls.io/builds/41993503)
   
   Coverage decreased (-1.0%) to 67.292% when pulling **7342c6334648dc7133bf4e78a4be7f01a2258fae on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Alima777 commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Alima777 commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r684730355



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+/** fuzzy query structure LikeOperator. */
+public class LikeOperator extends FunctionOperator {
+
+  private static final Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {

Review comment:
       It's never used, please remove it.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  private Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    if (filterType != FilterType.VALUE_FILTER) {
+      return false;
+    }
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", value.toString(), e.getIndex());
+    }

Review comment:
       Put this in constructor method and storage pattern as class paramter.

##########
File path: docs/zh/UserGuide/Appendix/SQL-Reference.md
##########
@@ -704,6 +704,23 @@ E.g. select * as temperature from root.sg.d1
 
 这种情况如果 * 匹配多个传感器,则无法正常显示。
 
+```
+* Like 语句
+
+模糊查询,仅支持数据类型为TEXT,匹配时为Java标准库风格的正则表达式

Review comment:
       ```suggestion
   模糊查询,仅支持数据类型为 TEXT,匹配时为 Java 标准库风格的正则表达式
   ```

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+/** fuzzy query structure LikeOperator. */
+public class LikeOperator extends FunctionOperator {
+
+  private static final Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {
+    return value;
+  }
+
+  @Override
+  protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
+      Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
+      throws LogicalOperatorException, MetadataException {
+    TSDataType type = pathTSDataTypeHashMap.get(singlePath);
+    if (type == null) {
+      throw new MetadataException(
+          "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
+    }
+    IUnaryExpression ret;
+    if (type != TEXT) {
+      throw new LogicalOperatorException(type.toString(), "");

Review comment:
       Specify message `Only TEXT is supported in 'Like'`  

##########
File path: docs/zh/UserGuide/Appendix/SQL-Reference.md
##########
@@ -704,6 +704,23 @@ E.g. select * as temperature from root.sg.d1
 
 这种情况如果 * 匹配多个传感器,则无法正常显示。
 
+```
+* Like 语句
+
+模糊查询,仅支持数据类型为TEXT,匹配时为Java标准库风格的正则表达式
+```
+SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause>
+Select Clause : <Path> [COMMA <Path>]*
+FromClause : < PrefixPath > [COMMA < PrefixPath >]*
+WhereClause : andExpression (OPERATOR_OR andExpression)*
+andExpression : predicate (OPERATOR_AND predicate)*
+predicate : (suffixPath | fullPath) LIKE stringLiteral
+stringLiteral : SINGLE_QUOTE_STRING_LITERAL | DOUBLE_QUOTE_STRING_LITERAL
+
+Eg. select s1 from root.sg.d1 where s1 like 'Regex'
+Eg. select s1, s2 FROM root.sg.d1 where s1 like 'regex' and s2 like 'Regex'
+Eg. select * from root.sg.d1 where s1 like "Regex"
+Eg. select * from root.sg.d1 where s1 like "Regex" and time > 100

Review comment:
       Sorry, but generally in IoTDB we specify single quote represents the string literal while double quotes contain special characters. For example, select "s.1" from root.sg.d1 where "s.1" like 'regex'.
   We'd better restrict it strictly in case it's confusing for users.

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+/** fuzzy query structure LikeOperator. */
+public class LikeOperator extends FunctionOperator {
+
+  private static final Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {
+    return value;
+  }
+
+  @Override
+  protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
+      Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
+      throws LogicalOperatorException, MetadataException {
+    TSDataType type = pathTSDataTypeHashMap.get(singlePath);
+    if (type == null) {
+      throw new MetadataException(
+          "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
+    }
+    IUnaryExpression ret;
+    if (type != TEXT) {
+      throw new LogicalOperatorException(type.toString(), "");
+    } else {
+      ret =
+          Like.getUnaryExpression(
+              singlePath,
+              (value.startsWith("'") && value.endsWith("'"))
+                      || (value.startsWith("\"") && value.endsWith("\""))
+                  ? value.substring(1, value.length() - 1)
+                  : value);

Review comment:
       The same as above. From my point of view, only single quote should be supported.

##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryDemoIT.java
##########
@@ -483,4 +483,147 @@ public void InTest() throws ClassNotFoundException {
     }
     return actualIndexToExpectedIndexList;
   }
+
+  @Test
+  public void LikeTest() throws ClassNotFoundException {
+    String[] retArray =
+        new String[] {
+          "1509465600000,v2,true,", "1509465660000,v2,true,", "1509465720000,v1,false,",
+        };
+
+    Class.forName(Config.JDBC_DRIVER_NAME);

Review comment:
       It's better to split this test into three single test. It will be easier to debug and maintain.

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
##########
@@ -1998,14 +1999,25 @@ private FilterOperator parseAndExpression(AndExpressionContext ctx) {
 
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
   private FilterOperator parsePredicate(PredicateContext ctx) {
+    PartialPath path = null;
     if (ctx.OPERATOR_NOT() != null) {
       FilterOperator notOp = new FilterOperator(FilterType.KW_NOT);
       notOp.addChildOperator(parseOrExpression(ctx.orExpression()));
       return notOp;
     } else if (ctx.LR_BRACKET() != null && ctx.OPERATOR_NOT() == null) {
       return parseOrExpression(ctx.orExpression());
+    } else if (ctx.LIKE() != null) {
+      if (ctx.suffixPath() != null) {
+        path = parseSuffixPath(ctx.suffixPath());
+      }
+      if (ctx.fullPath() != null) {
+        path = parseFullPath(ctx.fullPath());
+      }

Review comment:
       Use `else if` since suffixPath and fullPath cannot exsit at the same time.




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679798740



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+public class LikeOperator extends FunctionOperator {
+
+  private Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {
+    return value;
+  }
+
+  @Override
+  protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
+      Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
+      throws LogicalOperatorException, MetadataException {
+    TSDataType type = pathTSDataTypeHashMap.get(singlePath);
+    if (type == null) {
+      throw new MetadataException(
+          "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
+    }
+    IUnaryExpression ret;
+    if (type != TEXT) {
+      throw new LogicalOperatorException(type.toString(), "");
+    } else {
+      ret =
+          LIKE.getUnaryExpression(
+              singlePath,
+              (value.startsWith("'") && value.endsWith("'"))
+                      || (value.startsWith("\"") && value.endsWith("\""))
+                  ? value.substring(1, value.length() - 1)
+                  : value);
+    }
+    return new Pair<>(ret, singlePath.getFullPath());
+  }
+
+  private static class LIKE {

Review comment:
       Thanks. The new commit has been modified




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r680628173



##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryDemoIT.java
##########
@@ -483,4 +483,68 @@ public void InTest() throws ClassNotFoundException {
     }
     return actualIndexToExpectedIndexList;
   }
+
+  @Test
+  public void LikeTest() throws ClassNotFoundException {
+    String[] retArray =
+        new String[] {
+          "1509465600000,v2,true,", "1509465660000,v2,true,", "1509465720000,v1,false,",
+        };
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+
+      statement.setFetchSize(4);
+      Assert.assertEquals(4, statement.getFetchSize());
+      // Matches a string consisting of one lowercase letter and one digit. such as: "v1","v2"
+      boolean hasResultSet =
+          statement.execute(
+              "select hardware,status from root.ln.wf02.wt02 where hardware like '^[a-z][0-9]$' and time < 1509465780000");
+      Assert.assertTrue(hasResultSet);
+      try (ResultSet resultSet = statement.getResultSet()) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time," + "root.ln.wf02.wt02.hardware,root.ln.wf02.wt02.status,",
+                new int[] {
+                  Types.TIMESTAMP, Types.VARCHAR, Types.BOOLEAN,
+                });
+
+        int cnt = 0;
+        while (resultSet.next()) {
+          String[] expectedStrings = retArray[cnt].split(",");
+          StringBuilder expectedBuilder = new StringBuilder();
+          StringBuilder actualBuilder = new StringBuilder();
+          for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
+            actualBuilder.append(resultSet.getString(i)).append(",");
+            expectedBuilder
+                .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)])
+                .append(",");
+          }
+          Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString());
+          cnt++;
+        }
+        Assert.assertEquals(3, cnt);
+      }
+
+      hasResultSet =
+          statement.execute(
+              "select hardware,status from root.ln.wf02.wt02 where hardware like 'v*' ");

Review comment:
       New commit added test




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang removed a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang removed a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897498847


   In mysql, like and regex are separated. Like only knows_ And% are not recognized by regex_ And%, maybe you can combine these two functions directly
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   At 2021-08-12 17:37:10, "Superainbower" ***@***.***> wrote:
   
   @ijihang
   Hi, i try to modify org.apache.iotdb.tsfile.read.filter.operator.Like like this:
   
   
   And get result like this:
   
   
   We should use % like mysql
   
   —
   You are receiving this because you were mentioned.
   Reply to this email directly, view it on GitHub, or unsubscribe.
   Triage notifications on the go with GitHub Mobile for iOS or Android.


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897498847


   In mysql, like and regex are separated. Like only knows_ And% are not recognized by regex_ And%, maybe you can combine these two functions directly
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   At 2021-08-12 17:37:10, "Superainbower" ***@***.***> wrote:
   
   @ijihang
   Hi, i try to modify org.apache.iotdb.tsfile.read.filter.operator.Like like this:
   
   
   And get result like this:
   
   
   We should use % like mysql
   
   —
   You are receiving this because you were mentioned.
   Reply to this email directly, view it on GitHub, or unsubscribe.
   Triage notifications on the go with GitHub Mobile for iOS or Android.


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/41817715/badge)](https://coveralls.io/builds/41817715)
   
   Coverage increased (+0.05%) to 68.329% when pulling **0ef0d71567606a431c005773ba247b79c3249f78 on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679803928



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
##########
@@ -1505,25 +1506,7 @@ private void parseIndexPredicate(IndexPredicateClauseContext ctx) {
     } else {
       path = parseFullPath(ctx.fullPath());
     }
-    if (ctx.LIKE() != null) {

Review comment:
       Now,if it is a likeIndex, ANTLR will be resolved to indexpredicateclause. If it is a fuzzy query, ANTLR will be resolved to predict




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679799175



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+public class LikeOperator extends FunctionOperator {

Review comment:
       ok, new commit add




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] JackieTien97 commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
JackieTien97 commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r680344865



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    Object v = filterType == FilterType.TIME_FILTER ? time : value;

Review comment:
       Time can be used in `like` predicate?

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}

Review comment:
       If so, it may be better to declare the constructor as private

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+/** fuzzy query structure LikeOperator. */
+public class LikeOperator extends FunctionOperator {
+
+  private Logger logger = LoggerFactory.getLogger(LikeOperator.class);

Review comment:
       ```suggestion
     private static final Logger logger = LoggerFactory.getLogger(LikeOperator.class);
   ```

##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryDemoIT.java
##########
@@ -483,4 +483,68 @@ public void InTest() throws ClassNotFoundException {
     }
     return actualIndexToExpectedIndexList;
   }
+
+  @Test
+  public void LikeTest() throws ClassNotFoundException {
+    String[] retArray =
+        new String[] {
+          "1509465600000,v2,true,", "1509465660000,v2,true,", "1509465720000,v1,false,",
+        };
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+
+      statement.setFetchSize(4);
+      Assert.assertEquals(4, statement.getFetchSize());
+      // Matches a string consisting of one lowercase letter and one digit. such as: "v1","v2"
+      boolean hasResultSet =
+          statement.execute(
+              "select hardware,status from root.ln.wf02.wt02 where hardware like '^[a-z][0-9]$' and time < 1509465780000");
+      Assert.assertTrue(hasResultSet);
+      try (ResultSet resultSet = statement.getResultSet()) {
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        List<Integer> actualIndexToExpectedIndexList =
+            checkHeader(
+                resultSetMetaData,
+                "Time," + "root.ln.wf02.wt02.hardware,root.ln.wf02.wt02.status,",
+                new int[] {
+                  Types.TIMESTAMP, Types.VARCHAR, Types.BOOLEAN,
+                });
+
+        int cnt = 0;
+        while (resultSet.next()) {
+          String[] expectedStrings = retArray[cnt].split(",");
+          StringBuilder expectedBuilder = new StringBuilder();
+          StringBuilder actualBuilder = new StringBuilder();
+          for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
+            actualBuilder.append(resultSet.getString(i)).append(",");
+            expectedBuilder
+                .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)])
+                .append(",");
+          }
+          Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString());
+          cnt++;
+        }
+        Assert.assertEquals(3, cnt);
+      }
+
+      hasResultSet =
+          statement.execute(
+              "select hardware,status from root.ln.wf02.wt02 where hardware like 'v*' ");

Review comment:
       Add more tests, like, `select hardware,status from root.ln.wf02.wt02 where hardware like 's*'`, which should return an empty dataset




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Alima777 commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Alima777 commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r685161071



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  private Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    if (filterType != FilterType.VALUE_FILTER) {
+      return false;
+    }
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", value.toString(), e.getIndex());
+    }

Review comment:
       Why not put `pattern = Pattern.compile(this.value);` in the constructor method? We don't have to execute it every time.




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r684955301



##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryDemoIT.java
##########
@@ -483,4 +483,147 @@ public void InTest() throws ClassNotFoundException {
     }
     return actualIndexToExpectedIndexList;
   }
+
+  @Test
+  public void LikeTest() throws ClassNotFoundException {
+    String[] retArray =
+        new String[] {
+          "1509465600000,v2,true,", "1509465660000,v2,true,", "1509465720000,v1,false,",
+        };
+
+    Class.forName(Config.JDBC_DRIVER_NAME);

Review comment:
       I split this test into two single test,One can find the result, the other can't find the result




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897466758


   @Superainbower  
   Hi, It is a little different from mysql,You can enter regular in single quotes to match,1% is No match
   Please look at the picture below:
   ![20210812165705](https://user-images.githubusercontent.com/55303647/129168877-5b169772-1584-4b9c-bceb-5f87bec8cd37.png)
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/41816007/badge)](https://coveralls.io/builds/41816007)
   
   Coverage increased (+0.01%) to 68.293% when pulling **4e5ece39acebc0e24c9df5892b8758c27e1c4acc on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r680628301



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    Object v = filterType == FilterType.TIME_FILTER ? time : value;

Review comment:
       The new commit has been modified and only value filtering is allowed




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/42086550/badge)](https://coveralls.io/builds/42086550)
   
   Coverage increased (+0.001%) to 67.27% when pulling **41d1b0b174d9b5f6696331da1235a50651683df9 on ijihang:addGrammer** into **b6538cdf49bcf73095931c08164b337541af045d on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/41779511/badge)](https://coveralls.io/builds/41779511)
   
   Coverage decreased (-0.02%) to 68.258% when pulling **4937ca47d3759447fbb35cf58c775cdae4df775a on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Superainbower commented on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Superainbower commented on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897436811


   @ijihang
   Hi,  i find it doesn't support 'String%' or '%String'


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r684954734



##########
File path: docs/zh/UserGuide/Appendix/SQL-Reference.md
##########
@@ -704,6 +704,23 @@ E.g. select * as temperature from root.sg.d1
 
 这种情况如果 * 匹配多个传感器,则无法正常显示。
 
+```
+* Like 语句
+
+模糊查询,仅支持数据类型为TEXT,匹配时为Java标准库风格的正则表达式
+```
+SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause>
+Select Clause : <Path> [COMMA <Path>]*
+FromClause : < PrefixPath > [COMMA < PrefixPath >]*
+WhereClause : andExpression (OPERATOR_OR andExpression)*
+andExpression : predicate (OPERATOR_AND predicate)*
+predicate : (suffixPath | fullPath) LIKE stringLiteral
+stringLiteral : SINGLE_QUOTE_STRING_LITERAL | DOUBLE_QUOTE_STRING_LITERAL
+
+Eg. select s1 from root.sg.d1 where s1 like 'Regex'
+Eg. select s1, s2 FROM root.sg.d1 where s1 like 'regex' and s2 like 'Regex'
+Eg. select * from root.sg.d1 where s1 like "Regex"
+Eg. select * from root.sg.d1 where s1 like "Regex" and time > 100

Review comment:
       new commit modify single quote




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] wangchao316 commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
wangchao316 commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679748034



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+public class LikeOperator extends FunctionOperator {
+
+  private Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {
+    return value;
+  }
+
+  @Override
+  protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
+      Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
+      throws LogicalOperatorException, MetadataException {
+    TSDataType type = pathTSDataTypeHashMap.get(singlePath);
+    if (type == null) {
+      throw new MetadataException(
+          "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
+    }
+    IUnaryExpression ret;
+    if (type != TEXT) {
+      throw new LogicalOperatorException(type.toString(), "");
+    } else {
+      ret =
+          LIKE.getUnaryExpression(
+              singlePath,
+              (value.startsWith("'") && value.endsWith("'"))
+                      || (value.startsWith("\"") && value.endsWith("\""))
+                  ? value.substring(1, value.length() - 1)
+                  : value);
+    }
+    return new Pair<>(ret, singlePath.getFullPath());
+  }
+
+  private static class LIKE {

Review comment:
       Good Job.
   "LIKE" class name should  be "Like" in code style  

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}

Review comment:
       empty structure?

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    Object v = filterType == FilterType.TIME_FILTER ? time : value;
+
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", v.toString(), e.getIndex());
+    }
+    return pattern.matcher(v.toString()).find();
+  }
+
+  @Override
+  public boolean satisfyStartEndTime(long startTime, long endTime) {
+    return true;
+  }
+
+  @Override
+  public boolean containStartEndTime(long startTime, long endTime) {
+    return true;
+  }
+
+  @Override
+  public Filter copy() {
+    return new Like(value, filterType);
+  }
+
+  @Override
+  public void serialize(DataOutputStream outputStream) {
+    try {
+      outputStream.write(getSerializeId().ordinal());
+      outputStream.write(filterType.ordinal());
+      ReadWriteIOUtils.writeObject(value, outputStream);
+    } catch (IOException ignored) {
+      // ignored

Review comment:
       need print log , Ability to detect problems

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+public class LikeOperator extends FunctionOperator {

Review comment:
       add some notes in class head, or public method.

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+public class LikeOperator extends FunctionOperator {
+
+  private Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {
+    return value;
+  }
+
+  @Override
+  protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
+      Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
+      throws LogicalOperatorException, MetadataException {
+    TSDataType type = pathTSDataTypeHashMap.get(singlePath);
+    if (type == null) {
+      throw new MetadataException(
+          "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
+    }
+    IUnaryExpression ret;
+    if (type != TEXT) {
+      throw new LogicalOperatorException(type.toString(), "");
+    } else {
+      ret =
+          LIKE.getUnaryExpression(
+              singlePath,
+              (value.startsWith("'") && value.endsWith("'"))
+                      || (value.startsWith("\"") && value.endsWith("\""))
+                  ? value.substring(1, value.length() - 1)
+                  : value);
+    }
+    return new Pair<>(ret, singlePath.getFullPath());
+  }
+
+  private static class LIKE {
+    public static <T extends Comparable<T>> IUnaryExpression getUnaryExpression(
+        PartialPath path, String value) {
+      return new SingleSeriesExpression(path, ValueFilter.like(value));
+    }
+
+    public <T extends Comparable<T>> Filter getValueFilter(String value) {
+      return ValueFilter.like(value);
+    }
+  }
+
+  @Override
+  public String showTree(int spaceNum) {
+    StringContainer sc = new StringContainer();
+    for (int i = 0; i < spaceNum; i++) {
+      sc.addTail("  ");
+    }
+    sc.addTail(singlePath.getFullPath(), getFilterSymbol(), value, ", single\n");
+    return sc.toString();
+  }
+
+  @Override
+  public LikeOperator copy() {
+    LikeOperator ret;
+    try {
+      ret =
+          new LikeOperator(this.filterType, new PartialPath(singlePath.getNodes().clone()), value);
+    } catch (SQLParserException e) {
+      logger.error("error copy:", e);
+      return null;

Review comment:
       if return null,  Whether to perform processing at the upper layer?




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls commented on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/41778034/badge)](https://coveralls.io/builds/41778034)
   
   Coverage decreased (-0.008%) to 68.275% when pulling **4937ca47d3759447fbb35cf58c775cdae4df775a on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679801443



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}

Review comment:
       Yes, this method will not be used.  need to use the construction method with 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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] mychaow commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
mychaow commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679739944



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
##########
@@ -1505,25 +1506,7 @@ private void parseIndexPredicate(IndexPredicateClauseContext ctx) {
     } else {
       path = parseFullPath(ctx.fullPath());
     }
-    if (ctx.LIKE() != null) {

Review comment:
       seems conflict with the index query, maybe you could chose another key word like match




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/42086476/badge)](https://coveralls.io/builds/42086476)
   
   Coverage decreased (-0.02%) to 67.244% when pulling **41d1b0b174d9b5f6696331da1235a50651683df9 on ijihang:addGrammer** into **b6538cdf49bcf73095931c08164b337541af045d on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r685649996



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  private Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    if (filterType != FilterType.VALUE_FILTER) {
+      return false;
+    }
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", value.toString(), e.getIndex());
+    }

Review comment:
       new commit modify , Please check whether it is right, Thanks




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] mychaow merged pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
mychaow merged pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649


   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] Superainbower removed a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
Superainbower removed a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-897492816


   @ijihang 
   Hi, i try to modify org.apache.iotdb.tsfile.read.filter.operator.Like like this:
   ![image](https://user-images.githubusercontent.com/35786966/129174589-6244a075-f34d-4fc8-aba6-7460a2f046ee.png)
   
   And get result like this:
   ![image](https://user-images.githubusercontent.com/35786966/129174467-8a7de44b-c41e-4006-8b1f-87feda2f62ae.png)
   
    We should use % like mysql 
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r679800053



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.iotdb.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Like.
+ *
+ * @param <T> comparable data type
+ */
+public class Like<T extends Comparable<T>> implements Filter {
+
+  private static final long serialVersionUID = 2171102599229260789L;
+
+  protected String value;
+
+  protected FilterType filterType;
+
+  public Like() {}
+
+  public Like(String value, FilterType filterType) {
+    this.value = value;
+    this.filterType = filterType;
+  }
+
+  @Override
+  public boolean satisfy(Statistics statistics) {
+    return true;
+  }
+
+  @Override
+  public boolean satisfy(long time, Object value) {
+    Object v = filterType == FilterType.TIME_FILTER ? time : value;
+
+    Pattern pattern;
+    try {
+      pattern = Pattern.compile(this.value);
+    } catch (PatternSyntaxException e) {
+      throw new PatternSyntaxException("Regular expression error", v.toString(), e.getIndex());
+    }
+    return pattern.matcher(v.toString()).find();
+  }
+
+  @Override
+  public boolean satisfyStartEndTime(long startTime, long endTime) {
+    return true;
+  }
+
+  @Override
+  public boolean containStartEndTime(long startTime, long endTime) {
+    return true;
+  }
+
+  @Override
+  public Filter copy() {
+    return new Like(value, filterType);
+  }
+
+  @Override
+  public void serialize(DataOutputStream outputStream) {
+    try {
+      outputStream.write(getSerializeId().ordinal());
+      outputStream.write(filterType.ordinal());
+      ReadWriteIOUtils.writeObject(value, outputStream);
+    } catch (IOException ignored) {
+      // ignored

Review comment:
       ok,throw a Exception




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] ijihang commented on a change in pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
ijihang commented on a change in pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#discussion_r684954448



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/logical/crud/LikeOperator.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.db.qp.logical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.FilterConstant.FilterType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.StringContainer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.iotdb.tsfile.file.metadata.enums.TSDataType.TEXT;
+
+/** fuzzy query structure LikeOperator. */
+public class LikeOperator extends FunctionOperator {
+
+  private static final Logger logger = LoggerFactory.getLogger(LikeOperator.class);
+
+  protected String value;
+
+  public LikeOperator(FilterType filterType, PartialPath path, String value) {
+    super(filterType);
+    this.singlePath = path;
+    this.value = value;
+    isLeaf = true;
+    isSingle = true;
+  }
+
+  public String getPatternMap() {

Review comment:
       ok 




-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] coveralls edited a comment on pull request #3649: [IOTDB-1536]Support fuzzy query

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3649:
URL: https://github.com/apache/iotdb/pull/3649#issuecomment-889782173


   
   [![Coverage Status](https://coveralls.io/builds/42020757/badge)](https://coveralls.io/builds/42020757)
   
   Coverage decreased (-1.03%) to 67.251% when pulling **f8223cc56e1e76295aaf8dbf1d39f9f7f14094b4 on ijihang:addGrammer** into **902dbfb6fdda03e5d608dc12f9ebb28177b4fed9 on apache:master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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