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/13 11:22:31 UTC
[iotdb] branch master updated: [IOTDB-2882] Fixed display of unary expression (#5485)
This is an automated email from the ASF dual-hosted git repository.
rong 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 62365feb64 [IOTDB-2882] Fixed display of unary expression (#5485)
62365feb64 is described below
commit 62365feb646647b2da229b4ac3acb2174794cdf5
Author: flashzxi <39...@users.noreply.github.com>
AuthorDate: Wed Apr 13 19:22:25 2022 +0800
[IOTDB-2882] Fixed display of unary expression (#5485)
Fix: display of the unary expression for the query result may be wrong
---
.../iotdb/db/integration/IoTDBSelectSchemaIT.java | 111 +++++++++++++++++++++
.../query/expression/unary/LogicNotExpression.java | 8 +-
.../query/expression/unary/NegationExpression.java | 8 +-
3 files changed, 125 insertions(+), 2 deletions(-)
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSelectSchemaIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSelectSchemaIT.java
new file mode 100644
index 0000000000..5f9dcb96af
--- /dev/null
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSelectSchemaIT.java
@@ -0,0 +1,111 @@
+/*
+ * 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.integration;
+
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.itbase.category.ClusterTest;
+import org.apache.iotdb.itbase.category.LocalStandaloneTest;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+@Category({LocalStandaloneTest.class, ClusterTest.class})
+public class IoTDBSelectSchemaIT {
+ private static String INSERTION_SQLS =
+ "insert into root.sg.d1(time, s1, s2, s3) values (1, 1, 2, 3.0);";
+
+ private static void createTimeSeries() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("SET STORAGE GROUP TO root.sg");
+ statement.execute("CREATE TIMESERIES root.sg.d1.s1 with datatype=INT32,encoding=PLAIN");
+ statement.execute("CREATE TIMESERIES root.sg.d1.s2 with datatype=INT64,encoding=PLAIN");
+ statement.execute("CREATE TIMESERIES root.sg.d1.s3 with datatype=DOUBLE,encoding=PLAIN");
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().initBeforeClass();
+ createTimeSeries();
+ generateData();
+ }
+
+ private static void generateData() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute(INSERTION_SQLS);
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanAfterClass();
+ }
+
+ @Test
+ public void testSchemaExpression() {
+ String[] expressions = {"s1+s2", "-s1+s2", "-(s1+s3)", "!(s1>s2)", "-(-(s1))", "((s1+s2)*s3)"};
+ String[] completeExpressions = {
+ "root.sg.d1.s1+root.sg.d1.s2",
+ "-root.sg.d1.s1+root.sg.d1.s2",
+ "-(root.sg.d1.s1+root.sg.d1.s3)",
+ "!(root.sg.d1.s1>root.sg.d1.s2)",
+ "-(-root.sg.d1.s1)",
+ "(root.sg.d1.s1+root.sg.d1.s2)*root.sg.d1.s3"
+ };
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet =
+ statement.executeQuery(
+ String.format(
+ "select %s, %s, %s, %s, %s, %s from root.sg.d1",
+ expressions[0],
+ expressions[1],
+ expressions[2],
+ expressions[3],
+ expressions[4],
+ expressions[5]));
+ int columnCount = resultSet.getMetaData().getColumnCount();
+ assertEquals(1 + expressions.length, columnCount);
+
+ for (int i = 0; i < expressions.length; ++i) {
+ assertEquals(
+ completeExpressions[i], resultSet.getMetaData().getColumnName(i + 2).replace(" ", ""));
+ }
+ } catch (SQLException throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/LogicNotExpression.java b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/LogicNotExpression.java
index 3bb09b6d67..bdc4874307 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/LogicNotExpression.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/LogicNotExpression.java
@@ -177,7 +177,13 @@ public class LogicNotExpression extends Expression {
@Override
public String getExpressionStringInternal() {
- return "!" + expression.toString();
+ if (expression instanceof FunctionExpression
+ || expression instanceof ConstantOperand
+ || expression instanceof TimeSeriesOperand) {
+ return "!" + expression.toString();
+ } else {
+ return "!(" + expression.toString() + ")";
+ }
}
public static LogicNotExpression deserialize(ByteBuffer buffer) {
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java
index e4efb2bc45..5e3113bf67 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java
@@ -182,7 +182,13 @@ public class NegationExpression extends Expression {
@Override
public String getExpressionStringInternal() {
- return "-" + expression.toString();
+ if (expression instanceof FunctionExpression
+ || expression instanceof ConstantOperand
+ || expression instanceof TimeSeriesOperand) {
+ return "-" + expression.toString();
+ } else {
+ return "-(" + expression.toString() + ")";
+ }
}
public static NegationExpression deserialize(ByteBuffer buffer) {