This is an automated email from the ASF dual-hosted git repository.
hui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new dbef84905a [IOTDB-4649] Fix the problem that constants which have same
valueString but different types can not be distinguished. (#7619)
dbef84905a is described below
commit dbef84905a72f61d5138323fb6e32f5004e852c3
Author: Liao Lanyu <[email protected]>
AuthorDate: Tue Oct 18 09:48:15 2022 +0800
[IOTDB-4649] Fix the problem that constants which have same valueString but
different types can not be distinguished. (#7619)
---
.../java/org/apache/iotdb/db/it/IoTDBFilterIT.java | 24 +++++++++--
.../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java | 4 +-
.../mpp/plan/expression/leaf/ConstantOperand.java | 4 +-
.../plan/expression/leaf/TimeSeriesOperand.java | 9 +++++
.../dag/input/ConstantInputReader.java | 3 +-
.../transformation/dag/util/TransformUtils.java | 3 +-
.../db/mpp/common/schematree/NodeRefTest.java | 47 ++++++++++++++++++++++
7 files changed, 84 insertions(+), 10 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
index 76662fb1b4..d063743635 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
@@ -93,6 +93,8 @@ public class IoTDBFilterIT {
String.format(
"insert into root.vehicle.testNaN(timestamp,d1,d2)
values(%d,%d,%d)", i, i, i));
}
+ statement.execute(
+ " insert into root.sg1.d1(time, s1, s2) aligned values (1,1, \"1\"),
(2,2,\"2\")");
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
@@ -102,9 +104,8 @@ public class IoTDBFilterIT {
public void testFilterNaN() {
String sqlStr = "select d1 from root.vehicle.testNaN where d1/d2 > 0";
try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery(sqlStr);
-
+ Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sqlStr)) {
int count = 0;
while (resultSet.next()) {
++count;
@@ -116,4 +117,21 @@ public class IoTDBFilterIT {
fail(throwable.getMessage());
}
}
+
+ @Test
+ public void testSameConstantWithDifferentType() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement();
+ ResultSet resultSet =
+ statement.executeQuery(
+ "select s2 from root.** where s1 = 1 and s2 >= \"1\" and s2 <=
\"2\";")) {
+ int count = 0;
+ while (resultSet.next()) {
+ ++count;
+ }
+ assertEquals(1, count);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
index 92a70eddbf..fa31c9d2ba 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
@@ -50,7 +50,6 @@ import org.apache.iotdb.db.mpp.plan.Coordinator;
import org.apache.iotdb.db.mpp.plan.execution.ExecutionResult;
import org.apache.iotdb.db.mpp.plan.expression.Expression;
import org.apache.iotdb.db.mpp.plan.expression.ExpressionType;
-import org.apache.iotdb.db.mpp.plan.expression.leaf.ConstantOperand;
import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
import org.apache.iotdb.db.mpp.plan.planner.plan.parameter.FillDescriptor;
@@ -737,7 +736,8 @@ public class AnalyzeVisitor extends
StatementVisitor<Analysis, MPPQueryContext>
outputExpressions.clear();
for (String tagKey : tagKeys) {
- Expression tagKeyExpression = new ConstantOperand(TSDataType.TEXT,
tagKey);
+ Expression tagKeyExpression =
+ TimeSeriesOperand.constructColumnHeaderExpression(tagKey,
TSDataType.TEXT);
analyzeExpression(analysis, tagKeyExpression);
outputExpressions.add(new Pair<>(tagKeyExpression, null));
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/ConstantOperand.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/ConstantOperand.java
index 0d4801c3be..592c339f7b 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/ConstantOperand.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/ConstantOperand.java
@@ -113,7 +113,9 @@ public class ConstantOperand extends LeafOperand {
@Override
public String getExpressionStringInternal() {
- return valueString;
+ // Currently, we use Expression String to distinguish the expressions.
+ // So we need to distinguish number 1 and text "1"
+ return dataType.equals(TSDataType.TEXT) ? String.format("\"%s\"",
valueString) : valueString;
}
@Override
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/TimeSeriesOperand.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/TimeSeriesOperand.java
index eb7cc767e4..2f671dd8cf 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/TimeSeriesOperand.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/leaf/TimeSeriesOperand.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.mpp.plan.expression.leaf;
+import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathDeserializeUtil;
import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
@@ -28,6 +29,7 @@ import
org.apache.iotdb.db.mpp.plan.expression.visitor.ExpressionVisitor;
import org.apache.iotdb.db.mpp.plan.planner.plan.parameter.InputLocation;
import org.apache.iotdb.db.mpp.transformation.dag.memory.LayerMemoryAssigner;
import org.apache.iotdb.db.qp.physical.crud.UDTFPlan;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -48,6 +50,13 @@ public class TimeSeriesOperand extends LeafOperand {
path = (PartialPath) PathDeserializeUtil.deserialize(byteBuffer);
}
+ public static TimeSeriesOperand constructColumnHeaderExpression(
+ String columnName, TSDataType dataType) {
+ MeasurementPath measurementPath =
+ new MeasurementPath(new PartialPath(columnName, false), dataType);
+ return new TimeSeriesOperand(measurementPath);
+ }
+
public PartialPath getPath() {
return path;
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/input/ConstantInputReader.java
b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/input/ConstantInputReader.java
index cb065e74d0..2ca57083a4 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/input/ConstantInputReader.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/input/ConstantInputReader.java
@@ -46,8 +46,7 @@ public class ConstantInputReader implements LayerPointReader {
public ConstantInputReader(ConstantOperand expression) throws
QueryProcessException {
this.expression = Validate.notNull(expression);
- Object value =
- CommonUtils.parseValue(expression.getDataType(),
expression.getExpressionString());
+ Object value = CommonUtils.parseValue(expression.getDataType(),
expression.getValueString());
if (value == null) {
throw new QueryProcessException(
"Invalid constant operand: " + expression.getExpressionString());
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/util/TransformUtils.java
b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/util/TransformUtils.java
index ed95095cda..0b0cc0494a 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/util/TransformUtils.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/util/TransformUtils.java
@@ -68,8 +68,7 @@ public class TransformUtils {
try {
Object value =
- CommonUtils.parseValue(
- constantOperand.getDataType(),
constantOperand.getExpressionString());
+ CommonUtils.parseValue(constantOperand.getDataType(),
constantOperand.getValueString());
if (value == null) {
throw new UnsupportedOperationException(
"Invalid constant operand: " +
constantOperand.getExpressionString());
diff --git
a/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/NodeRefTest.java
b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/NodeRefTest.java
new file mode 100644
index 0000000000..e8f4278feb
--- /dev/null
+++
b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/NodeRefTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.mpp.common.schematree;
+
+import org.apache.iotdb.db.mpp.common.NodeRef;
+import org.apache.iotdb.db.mpp.plan.expression.Expression;
+import org.apache.iotdb.db.mpp.plan.expression.leaf.ConstantOperand;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class NodeRefTest {
+
+ @Test
+ public void testHashCode() {
+ ConstantOperand constantOperand1 = new ConstantOperand(TSDataType.INT64,
"2");
+ ConstantOperand constantOperand2 = new ConstantOperand(TSDataType.TEXT,
"2");
+ NodeRef<Expression> constant1 = NodeRef.of(constantOperand1);
+ NodeRef<Expression> constant2 = NodeRef.of(constantOperand2);
+ NodeRef<Expression> constant3 = NodeRef.of(constantOperand1);
+ Map<NodeRef<Expression>, String> map = new HashMap<>();
+ map.put(constant1, "test");
+ Assert.assertNull(map.get(constant2));
+ Assert.assertEquals("test", map.get(constant3));
+ }
+}