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 09:48:35 UTC

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

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