You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/04/23 04:05:13 UTC
[iotdb] 02/04: RegularExpression
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch IOTDB-2962
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 84403422b7bd9343544d47caf142b70d00b6518a
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Fri Apr 22 09:24:57 2022 +0800
RegularExpression
---
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 4 +-
.../iotdb/db/query/expression/Expression.java | 4 -
.../query/expression/unary/RegularExpression.java | 181 +++++++++++++++++++++
3 files changed, 183 insertions(+), 6 deletions(-)
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index c83c704f1d..24c8dfb88c 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -845,10 +845,10 @@ expression
| leftExpression=expression (STAR | DIV | MOD) rightExpression=expression
| leftExpression=expression (PLUS | MINUS) rightExpression=expression
| leftExpression=expression (OPERATOR_GT | OPERATOR_GTE | OPERATOR_LT | OPERATOR_LTE | OPERATOR_DEQ | OPERATOR_NEQ) rightExpression=expression
- | leftExpression=expression (OPERATOR_AND | OPERATOR_OR) rightExpression=expression
- | functionName LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
| unaryBeforeRegularExpression=expression (REGEXP | LIKE) STRING_LITERAL
| unaryBeforeInExpression=expression OPERATOR_IN LR_BRACKET constant (COMMA constant)* RR_BRACKET
+ | leftExpression=expression (OPERATOR_AND | OPERATOR_OR) rightExpression=expression
+ | functionName LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
| suffixPathCanInExpr
| time=(TIME | TIMESTAMP)
| constant
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java b/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
index 1e481c2db5..0a54966cf5 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
@@ -66,10 +66,6 @@ public abstract class Expression {
return false;
}
- public void bindInputColumnIndex(int inputColumnIndex) {
- this.inputColumnIndex = inputColumnIndex;
- }
-
public abstract void concat(
List<PartialPath> prefixPaths,
List<Expression> resultExpressions,
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/RegularExpression.java b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/RegularExpression.java
new file mode 100644
index 0000000000..3a712c9b89
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/RegularExpression.java
@@ -0,0 +1,181 @@
+/*
+ * 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.query.expression.unary;
+
+import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.mpp.common.schematree.PathPatternTree;
+import org.apache.iotdb.db.mpp.sql.rewriter.WildcardsRemover;
+import org.apache.iotdb.db.qp.physical.crud.UDTFPlan;
+import org.apache.iotdb.db.query.expression.Expression;
+import org.apache.iotdb.db.query.udf.core.executor.UDTFContext;
+import org.apache.iotdb.db.query.udf.core.executor.UDTFExecutor;
+import org.apache.iotdb.db.query.udf.core.layer.IntermediateLayer;
+import org.apache.iotdb.db.query.udf.core.layer.LayerMemoryAssigner;
+import org.apache.iotdb.db.query.udf.core.layer.RawQueryInputLayer;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+public class RegularExpression extends Expression {
+
+ private final Expression expression;
+ private final String patternString;
+ private final Pattern pattern;
+
+ public RegularExpression(Expression expression, String patternString) {
+ this.expression = expression;
+ this.patternString = patternString;
+ pattern = Pattern.compile(patternString);
+ }
+
+ public RegularExpression(Expression expression, String patternString, Pattern pattern) {
+ this.expression = expression;
+ this.patternString = patternString;
+ this.pattern = pattern;
+ }
+
+ @Override
+ public void concat(
+ List<PartialPath> prefixPaths,
+ List<Expression> resultExpressions,
+ PathPatternTree patternTree) {
+ List<Expression> resultExpressionsForRecursion = new ArrayList<>();
+ expression.concat(prefixPaths, resultExpressionsForRecursion, patternTree);
+ for (Expression resultExpression : resultExpressionsForRecursion) {
+ resultExpressions.add(new RegularExpression(resultExpression, patternString, pattern));
+ }
+ }
+
+ @Override
+ public void concat(List<PartialPath> prefixPaths, List<Expression> resultExpressions) {
+ List<Expression> resultExpressionsForRecursion = new ArrayList<>();
+ expression.concat(prefixPaths, resultExpressionsForRecursion);
+ for (Expression resultExpression : resultExpressionsForRecursion) {
+ resultExpressions.add(new RegularExpression(resultExpression, patternString, pattern));
+ }
+ }
+
+ @Override
+ public void removeWildcards(WildcardsRemover wildcardsRemover, List<Expression> resultExpressions)
+ throws StatementAnalyzeException {
+ List<Expression> resultExpressionsForRecursion = new ArrayList<>();
+ expression.removeWildcards(wildcardsRemover, resultExpressionsForRecursion);
+ for (Expression resultExpression : resultExpressionsForRecursion) {
+ resultExpressions.add(new RegularExpression(resultExpression, patternString, pattern));
+ }
+ }
+
+ @Override
+ public void removeWildcards(
+ org.apache.iotdb.db.qp.utils.WildcardsRemover wildcardsRemover,
+ List<Expression> resultExpressions)
+ throws LogicalOptimizeException {
+ List<Expression> resultExpressionsForRecursion = new ArrayList<>();
+ expression.removeWildcards(wildcardsRemover, resultExpressionsForRecursion);
+ for (Expression resultExpression : resultExpressionsForRecursion) {
+ resultExpressions.add(new RegularExpression(resultExpression, patternString, pattern));
+ }
+ }
+
+ @Override
+ public void collectPaths(Set<PartialPath> pathSet) {
+ expression.collectPaths(pathSet);
+ }
+
+ @Override
+ public void constructUdfExecutors(
+ Map<String, UDTFExecutor> expressionName2Executor, ZoneId zoneId) {
+ expression.constructUdfExecutors(expressionName2Executor, zoneId);
+ }
+
+ @Override
+ public void bindInputLayerColumnIndexWithExpression(UDTFPlan udtfPlan) {
+ expression.bindInputLayerColumnIndexWithExpression(udtfPlan);
+ inputColumnIndex = udtfPlan.getReaderIndexByExpressionName(toString());
+ }
+
+ @Override
+ public void updateStatisticsForMemoryAssigner(LayerMemoryAssigner memoryAssigner) {
+ expression.updateStatisticsForMemoryAssigner(memoryAssigner);
+ memoryAssigner.increaseExpressionReference(this);
+ }
+
+ @Override
+ public IntermediateLayer constructIntermediateLayer(
+ long queryId,
+ UDTFContext udtfContext,
+ RawQueryInputLayer rawTimeSeriesInputLayer,
+ Map<Expression, IntermediateLayer> expressionIntermediateLayerMap,
+ Map<Expression, TSDataType> expressionDataTypeMap,
+ LayerMemoryAssigner memoryAssigner)
+ throws QueryProcessException, IOException {
+ // TODO
+ throw new RuntimeException();
+ }
+
+ @Override
+ protected boolean isConstantOperandInternal() {
+ return expression.isConstantOperand();
+ }
+
+ @Override
+ public List<Expression> getExpressions() {
+ return Collections.singletonList(expression);
+ }
+
+ @Override
+ protected String getExpressionStringInternal() {
+ // TODO
+ throw new RuntimeException();
+ }
+
+ @Override
+ public boolean isTimeSeriesGeneratingFunctionExpression() {
+ return !isUserDefinedAggregationFunctionExpression();
+ }
+
+ @Override
+ public boolean isUserDefinedAggregationFunctionExpression() {
+ return expression.isUserDefinedAggregationFunctionExpression()
+ || expression.isBuiltInAggregationFunctionExpression();
+ }
+
+ public static RegularExpression deserialize(ByteBuffer buffer) {
+ // TODO
+ throw new RuntimeException();
+ }
+
+ @Override
+ public void serialize(ByteBuffer byteBuffer) {
+ // TODO
+ throw new RuntimeException();
+ }
+}