This is an automated email from the ASF dual-hosted git repository.
jt2594838 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 673434b3335 Fix quoted tree path parsing in table views (#18884)
673434b3335 is described below
commit 673434b3335f68f0e4ef00de7323472a3121e136
Author: Caideyipi <[email protected]>
AuthorDate: Thu Oct 15 15:27:55 2026 +0800
Fix quoted tree path parsing in table views (#18884)
---
.../iotdb/relational/it/schema/IoTDBTableIT.java | 27 +++++++++++++
.../plan/relational/sql/parser/AstBuilder.java | 18 +++++----
.../sql/parser/CreateViewPrefixPathTest.java | 47 ++++++++++++++++++++++
3 files changed, 84 insertions(+), 8 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
index 2b9b2d8ecce..34bd61d03d5 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
@@ -886,6 +886,33 @@ public class IoTDBTableIT {
}
}
+ @Test
+ public void testCreateViewFromTreePathWithSpaces() throws Exception {
+ try (final Connection connection = EnvFactory.getEnv().getConnection();
+ final Statement statement = connection.createStatement()) {
+ statement.execute("CREATE DATABASE root.tv143_cmp_3");
+ statement.execute("CREATE TIMESERIES root.`tv143_cmp_3`.`a b`.`d1`.s1
INT32");
+ statement.execute("INSERT INTO root.`tv143_cmp_3`.`a b`.`d1`(time,s1)
VALUES (1,10)");
+ }
+
+ try (final Connection connection =
+ EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ final Statement statement = connection.createStatement()) {
+ statement.execute("CREATE DATABASE tv143_cmp_3");
+ statement.execute("USE tv143_cmp_3");
+ statement.execute(
+ "CREATE VIEW v (device STRING TAG, value INT32 FIELD FROM s1) WITH
(ttl='INF') "
+ + "AS root.\"`tv143_cmp_3`\".\"`a b`\".**");
+
+ try (final ResultSet resultSet =
+ statement.executeQuery("SELECT value FROM v ORDER BY time")) {
+ assertTrue(resultSet.next());
+ assertEquals(10, resultSet.getInt("value"));
+ assertFalse(resultSet.next());
+ }
+ }
+ }
+
@Test
public void testTreeViewTable() throws Exception {
try (final Connection connection = EnvFactory.getEnv().getConnection();
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 4bfaf6f9a3b..4e502e7d3bd 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -769,14 +769,16 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
final StringBuilder builder = new StringBuilder("root.");
for (int i = 0; i < nodeNames.size(); i++) {
if (nodeNames.get(i).nodeNameWithoutWildcard() != null) {
- builder
- .append("`")
- .append(
- parseNodeString(
- ((Identifier)
visit(nodeNames.get(i).nodeNameWithoutWildcard().identifier()))
- .getValue()))
- .append("`")
- .append(i == nodeNames.size() - 1 ? "" : ".");
+ final String nodeName =
+ parseNodeString(
+ ((Identifier)
visit(nodeNames.get(i).nodeNameWithoutWildcard().identifier()))
+ .getValue());
+ if (nodeName.startsWith("`") && nodeName.endsWith("`")) {
+ builder.append(nodeName);
+ } else {
+ builder.append("`").append(nodeName).append("`");
+ }
+ builder.append(i == nodeNames.size() - 1 ? "" : ".");
} else {
builder.append(nodeNames.get(i).getText());
}
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/CreateViewPrefixPathTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/CreateViewPrefixPathTest.java
new file mode 100644
index 00000000000..5f04b044eab
--- /dev/null
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/CreateViewPrefixPathTest.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.queryengine.plan.relational.sql.parser;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CreateView;
+
+import org.junit.Test;
+
+import java.time.ZoneId;
+
+import static org.junit.Assert.assertEquals;
+
+public class CreateViewPrefixPathTest {
+
+ @Test
+ public void testQuotedTreePathSegment() throws Exception {
+ final Statement statement =
+ new SqlParser()
+ .createStatement(
+ "CREATE VIEW tv143_cmp_3.v (device STRING TAG, value INT32
FIELD FROM s1) "
+ + "WITH (ttl='INF') AS root.\"`tv143_cmp_3`\".\"`a
b`\".**",
+ ZoneId.systemDefault(),
+ null);
+
+ assertEquals(
+ new PartialPath("root.tv143_cmp_3.`a b`.**"), ((CreateView)
statement).getPrefixPath());
+ }
+}