This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 8dcb19e7d0f [To dev/1.3] Fix select time in TreeModel (#14990)
8dcb19e7d0f is described below
commit 8dcb19e7d0f7dba922eddd095e04485e5f297a9e
Author: Weihao Li <[email protected]>
AuthorDate: Fri Feb 28 19:27:26 2025 +0800
[To dev/1.3] Fix select time in TreeModel (#14990)
---
.../apache/iotdb/db/it/query/IoTDBQueryDemoIT.java | 25 ++++++++++++++++++++++
.../db/queryengine/plan/parser/ASTVisitor.java | 8 ++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBQueryDemoIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBQueryDemoIT.java
index cb074e324a9..b9e3ca7b6db 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBQueryDemoIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBQueryDemoIT.java
@@ -18,11 +18,13 @@
*/
package org.apache.iotdb.db.it.query;
+import org.apache.iotdb.isession.ISession;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import com.google.common.collect.ImmutableList;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -41,6 +43,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static org.apache.iotdb.db.it.utils.TestUtils.assertTestFail;
import static org.junit.Assert.fail;
@RunWith(IoTDBTestRunner.class)
@@ -661,4 +664,26 @@ public class IoTDBQueryDemoIT {
fail(e.getMessage());
}
}
+
+ @Test
+ public void selectWithTimeTest() {
+ try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+ session.executeRawDataQuery(
+ ImmutableList.of("root.ln.wf01.wt01.time",
"root.ln.wf01.wt01.temperature"), 0, 100);
+
+ fail();
+ } catch (Exception e) {
+ e.getMessage().contains("509: root.ln.wf01.wt01.time is not a legal
path");
+ }
+
+ String expectedErrMsg =
+ "701: Time column is no need to appear in SELECT Clause explicitly, it
will always be returned if possible";
+ assertTestFail("select time from root.ln.wf01.wt01", expectedErrMsg);
+ assertTestFail("select time, temperature from root.ln.wf01.wt01",
expectedErrMsg);
+ assertTestFail("select time from root.ln.wf01.wt01 where temperature > 1",
expectedErrMsg);
+ // parse error when process 'wt01.time'
+ assertTestFail(
+ "select wt01.time, wt01.temperature from root.ln.wf01",
+ "700: Error occurred while parsing SQL to physical plan");
+ }
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index a7a00ac5eac..68a6b32ea09 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -1514,11 +1514,17 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
Map<String, Expression> aliasToColumnMap = new HashMap<>();
for (IoTDBSqlParser.ResultColumnContext resultColumnContext :
ctx.resultColumn()) {
ResultColumn resultColumn = parseResultColumn(resultColumnContext);
+ String columnName = resultColumn.getExpression().getExpressionString();
// __endTime shouldn't be included in resultColumns
- if
(resultColumn.getExpression().getExpressionString().equals(ColumnHeaderConstant.ENDTIME))
{
+ if (columnName.equals(ColumnHeaderConstant.ENDTIME)) {
queryStatement.setOutputEndTime(true);
continue;
}
+ // don't support pure time in select
+ if (columnName.equals(ColumnHeaderConstant.TIME)) {
+ throw new SemanticException(
+ "Time column is no need to appear in SELECT Clause explicitly, it
will always be returned if possible");
+ }
if (resultColumn.hasAlias()) {
String alias = resultColumn.getAlias();
if (aliasToColumnMap.containsKey(alias)) {