This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch rel/1.2
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.2 by this push:
new a73bc08ece2 [To rel/1.2] Support tag/attribute on view (#10080)
a73bc08ece2 is described below
commit a73bc08ece2dc9f84248653efa62f13677ef31c3
Author: Marcos_Zyk <[email protected]>
AuthorDate: Sat Jun 10 00:26:33 2023 +0800
[To rel/1.2] Support tag/attribute on view (#10080)
---
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 3 +-
.../it/schema/view/IoTDBCreateAndShowViewIT.java | 116 +++++++++++----------
.../metadata/mnode/mem/info/LogicalViewInfo.java | 10 +-
.../execution/executor/RegionWriteExecutor.java | 28 +++++
.../iotdb/db/mpp/plan/parser/ASTVisitor.java | 46 ++++----
.../db/mpp/plan/planner/LogicalPlanVisitor.java | 3 +-
.../node/metedata/write/AlterTimeSeriesNode.java | 33 +++++-
.../metadata/AlterTimeSeriesStatement.java | 10 ++
8 files changed, 165 insertions(+), 84 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 b44f9268cd3..3446a1039a7 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
@@ -572,11 +572,12 @@ dropLogicalView
;
renameLogicalView
- : ALTER VIEW prefixPath RENAME TO prefixPath
+ : ALTER VIEW fullPath RENAME TO fullPath
;
alterLogicalView
: ALTER VIEW viewTargetPaths AS viewSourcePaths
+ | ALTER VIEW fullPath alterClause
;
viewSuffixPaths
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBCreateAndShowViewIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBCreateAndShowViewIT.java
index 5ab968aaf8f..ef838404ed4 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBCreateAndShowViewIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBCreateAndShowViewIT.java
@@ -51,34 +51,36 @@ public class IoTDBCreateAndShowViewIT {
private static final String[] SQLs =
new String[] {
"CREATE DATABASE root.db;",
- "CREATE DATABASE root.myview;",
- "CREATE DATABASE root.cal_view;",
+ "CREATE DATABASE root.view;",
"CREATE TIMESERIES root.db.d01.s01 INT32 encoding=RLE
compression=SNAPPY;",
"CREATE TIMESERIES root.db.d01.s02 INT32 encoding=RLE
compression=SNAPPY;",
"CREATE TIMESERIES root.db.d02.s01 INT32 encoding=RLE
compression=SNAPPY;",
"CREATE TIMESERIES root.db.d02.s02 INT32 encoding=RLE
compression=SNAPPY;",
- "CREATE VIEW root.myview.d01.s01 AS root.db.d01.s01;",
- "CREATE VIEW root.myview.d01.s02 AS SELECT s02 FROM root.db.d01;",
- "CREATE VIEW root.myview.d02(s01, s02) AS SELECT s01, s02 FROM
root.db.d02;",
- "CREATE VIEW root.cal_view.avg AS SELECT (s01+s02)/2 FROM
root.db.d01;",
- "CREATE VIEW root.cal_view(multiple, divide) AS SELECT s01*s02,
s01/s02 FROM root.db.d02;",
- "CREATE VIEW root.cal_view.cast_view AS SELECT CAST(s01 as TEXT) FROM
root.db.d01;",
- "CREATE VIEW root.multi_view.all_in_one(${2}_${3}) AS SELECT * FROM
root.db.**;",
- "CREATE VIEW root.copy_view.${2}(${3}) AS SELECT * FROM root.db.**;"
+ "CREATE VIEW root.view.myview.d01.s01 AS root.db.d01.s01;",
+ "CREATE VIEW root.view.myview.d01.s02 AS SELECT s02 FROM root.db.d01;",
+ "CREATE VIEW root.view.myview.d02(s01, s02) AS SELECT s01, s02 FROM
root.db.d02;",
+ "CREATE VIEW root.view.cal_view.avg AS SELECT (s01+s02)/2 FROM
root.db.d01;",
+ "CREATE VIEW root.view.cal_view(multiple, divide) AS SELECT s01*s02,
s01/s02 FROM root.db.d02;",
+ "CREATE VIEW root.view.cal_view.cast_view AS SELECT CAST(s01 as TEXT)
FROM root.db.d01;",
+ "CREATE VIEW root.view.multi_view.all_in_one(${2}_${3}) AS SELECT *
FROM root.db.**;",
+ "CREATE VIEW root.view.copy_view.${2}(${3}) AS SELECT * FROM
root.db.**;",
+ "ALTER VIEW root.view.myview.d01.s01 UPSERT TAGS(tag1=value1,
tag2=value2) ATTRIBUTES(attribute1=value1)",
+ "ALTER VIEW root.view.myview.d02.s01 UPSERT TAGS(tag1=value2,
tag2=value3) ATTRIBUTES(attribute1=value1)"
};
private static final String[] unsupportedSQLs =
new String[] {
- "CREATE VIEW root.myview.nested_view AS root.myview.d01.s01;",
- "CREATE VIEW root.agg_view(agg_avg1, agg_avg2) AS SELECT AVG(s01)+1
FROM root.db.d01, root.db.d02;",
- "CREATE VIEW root.agg_view(agg_max1, agg_max2) AS SELECT
MAX_VALUE(s01) FROM root.db.d01, root.db.d02;",
- "CREATE VIEW root.myview.illegal_view AS root.myview.d01.s01 + 1;",
- "CREATE VIEW root.multi_view($illegal_name) AS root.db.d01.s01;",
- "CREATE VIEW root.multi_view.multi_nodes(${3}.${2}) AS SELECT * FROM
root.db.**;",
- "CREATE VIEW root.copy_view.$illegal_char(${3}) AS SELECT * FROM
root.db.**;",
- "CREATE VIEW root.copy_view.mismatched_count(${3}) AS SELECT * FROM
root.db.**;",
- "CREATE VIEW root.repeated_view(a, a) AS SELECT s01, s02 FROM
root.db.d01;",
- "CREATE VIEW root.repeated_view.abc, root.repeated_view.abc AS SELECT
s01, s02 FROM root.db.d01;",
+ "CREATE VIEW root.view.myview.nested_view AS
root.view.myview.d01.s01;",
+ "CREATE VIEW root.view.agg_view(agg_avg1, agg_avg2) AS SELECT
AVG(s01)+1 FROM root.db.d01, root.db.d02;",
+ "CREATE VIEW root.view.agg_view(agg_max1, agg_max2) AS SELECT
MAX_VALUE(s01) FROM root.db.d01, root.db.d02;",
+ "CREATE VIEW root.view.myview.illegal_view AS root.view.myview.d01.s01
+ 1;",
+ "CREATE VIEW root.view.multi_view($illegal_name) AS root.db.d01.s01;",
+ "CREATE VIEW root.view.multi_view.multi_nodes(${3}.${2}) AS SELECT *
FROM root.db.**;",
+ "CREATE VIEW root.view.copy_view.$illegal_char(${3}) AS SELECT * FROM
root.db.**;",
+ "CREATE VIEW root.view.copy_view.mismatched_count(${3}) AS SELECT *
FROM root.db.**;",
+ "CREATE VIEW root.view.repeated_view(a, a) AS SELECT s01, s02 FROM
root.db.d01;",
+ "CREATE VIEW root.view.repeated_view.abc, root.view.repeated_view.abc
AS SELECT s01, s02 FROM root.db.d01;",
+ "ALTER VIW root.db.d01.s01 UPSERT TAGS(tag1=value1, tag2=value2)
ATTRIBUTES(attribute1=value1)"
};
@BeforeClass
@@ -108,7 +110,7 @@ public class IoTDBCreateAndShowViewIT {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("SHOW TiMESERIES
root.db.**;");
+ ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES
root.db.**;");
int count = 0;
while (resultSet.next()) {
String ans =
@@ -149,15 +151,15 @@ public class IoTDBCreateAndShowViewIT {
Set<String> retSet =
new HashSet<>(
Arrays.asList(
-
"root.myview.d01.s01,null,root.myview,INT32,null,null,null,null,logical;",
-
"root.myview.d01.s02,null,root.myview,INT32,null,null,null,null,logical;",
-
"root.myview.d02.s01,null,root.myview,INT32,null,null,null,null,logical;",
-
"root.myview.d02.s02,null,root.myview,INT32,null,null,null,null,logical;"));
+
"root.view.myview.d01.s01,null,root.view,INT32,null,null,{\"tag1\":\"value1\",\"tag2\":\"value2\"},{\"attribute1\":\"value1\"},logical;",
+
"root.view.myview.d01.s02,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.myview.d02.s01,null,root.view,INT32,null,null,{\"tag1\":\"value2\",\"tag2\":\"value3\"},{\"attribute1\":\"value1\"},logical;",
+
"root.view.myview.d02.s02,null,root.view,INT32,null,null,null,null,logical;"));
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("SHOW TiMESERIES
root.myview.**;");
+ ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES
root.view.myview.**;");
int count = 0;
while (resultSet.next()) {
String ans =
@@ -198,15 +200,15 @@ public class IoTDBCreateAndShowViewIT {
Set<String> retSet =
new HashSet<>(
Arrays.asList(
-
"root.cal_view.avg,null,root.cal_view,DOUBLE,null,null,null,null,logical;",
-
"root.cal_view.multiple,null,root.cal_view,DOUBLE,null,null,null,null,logical;",
-
"root.cal_view.divide,null,root.cal_view,DOUBLE,null,null,null,null,logical;",
-
"root.cal_view.cast_view,null,root.cal_view,TEXT,null,null,null,null,logical;"));
+
"root.view.cal_view.avg,null,root.view,DOUBLE,null,null,null,null,logical;",
+
"root.view.cal_view.multiple,null,root.view,DOUBLE,null,null,null,null,logical;",
+
"root.view.cal_view.divide,null,root.view,DOUBLE,null,null,null,null,logical;",
+
"root.view.cal_view.cast_view,null,root.view,TEXT,null,null,null,null,logical;"));
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("SHOW TiMESERIES
root.cal_view.**;");
+ ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES
root.view.cal_view.**;");
int count = 0;
while (resultSet.next()) {
String ans =
@@ -247,15 +249,15 @@ public class IoTDBCreateAndShowViewIT {
Set<String> retSet =
new HashSet<>(
Arrays.asList(
-
"root.multi_view.all_in_one.d01_s01,null,root.multi_view,INT32,null,null,null,null,logical;",
-
"root.multi_view.all_in_one.d01_s02,null,root.multi_view,INT32,null,null,null,null,logical;",
-
"root.multi_view.all_in_one.d02_s01,null,root.multi_view,INT32,null,null,null,null,logical;",
-
"root.multi_view.all_in_one.d02_s02,null,root.multi_view,INT32,null,null,null,null,logical;"));
+
"root.view.multi_view.all_in_one.d01_s01,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.multi_view.all_in_one.d01_s02,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.multi_view.all_in_one.d02_s01,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.multi_view.all_in_one.d02_s02,null,root.view,INT32,null,null,null,null,logical;"));
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("SHOW TiMESERIES
root.multi_view.**;");
+ ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES
root.view.multi_view.**;");
int count = 0;
while (resultSet.next()) {
String ans =
@@ -296,15 +298,15 @@ public class IoTDBCreateAndShowViewIT {
Set<String> retSet =
new HashSet<>(
Arrays.asList(
-
"root.copy_view.d01.s01,null,root.copy_view,INT32,null,null,null,null,logical;",
-
"root.copy_view.d01.s02,null,root.copy_view,INT32,null,null,null,null,logical;",
-
"root.copy_view.d02.s01,null,root.copy_view,INT32,null,null,null,null,logical;",
-
"root.copy_view.d02.s02,null,root.copy_view,INT32,null,null,null,null,logical;"));
+
"root.view.copy_view.d01.s01,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.copy_view.d01.s02,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.copy_view.d02.s01,null,root.view,INT32,null,null,null,null,logical;",
+
"root.view.copy_view.d02.s02,null,root.view,INT32,null,null,null,null,logical;"));
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("SHOW TiMESERIES
root.copy_view.**;");
+ ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES
root.view.copy_view.**;");
int count = 0;
while (resultSet.next()) {
String ans =
@@ -347,22 +349,22 @@ public class IoTDBCreateAndShowViewIT {
Set<String> retSet =
new HashSet<>(
Arrays.asList(
-
"root.myview.d01.s01,root.myview,INT32,null,null,logical,root.db.d01.s01;",
-
"root.myview.d01.s02,root.myview,INT32,null,null,logical,root.db.d01.s02;",
-
"root.myview.d02.s01,root.myview,INT32,null,null,logical,root.db.d02.s01;",
-
"root.myview.d02.s02,root.myview,INT32,null,null,logical,root.db.d02.s02;",
-
"root.cal_view.avg,root.cal_view,DOUBLE,null,null,logical,(root.db.d01.s01 +
root.db.d01.s02) / 2;",
-
"root.cal_view.multiple,root.cal_view,DOUBLE,null,null,logical,root.db.d02.s01
* root.db.d02.s02;",
-
"root.cal_view.divide,root.cal_view,DOUBLE,null,null,logical,root.db.d02.s01 /
root.db.d02.s02;",
-
"root.cal_view.cast_view,root.cal_view,TEXT,null,null,logical,cast(type=TEXT)(root.db.d01.s01);",
-
"root.multi_view.all_in_one.d01_s01,root.multi_view,INT32,null,null,logical,root.db.d01.s01;",
-
"root.multi_view.all_in_one.d01_s02,root.multi_view,INT32,null,null,logical,root.db.d01.s02;",
-
"root.multi_view.all_in_one.d02_s01,root.multi_view,INT32,null,null,logical,root.db.d02.s01;",
-
"root.multi_view.all_in_one.d02_s02,root.multi_view,INT32,null,null,logical,root.db.d02.s02;",
-
"root.copy_view.d01.s01,root.copy_view,INT32,null,null,logical,root.db.d01.s01;",
-
"root.copy_view.d01.s02,root.copy_view,INT32,null,null,logical,root.db.d01.s02;",
-
"root.copy_view.d02.s01,root.copy_view,INT32,null,null,logical,root.db.d02.s01;",
-
"root.copy_view.d02.s02,root.copy_view,INT32,null,null,logical,root.db.d02.s02;"));
+
"root.view.myview.d01.s01,root.view,INT32,{\"tag1\":\"value1\",\"tag2\":\"value2\"},{\"attribute1\":\"value1\"},logical,root.db.d01.s01;",
+
"root.view.myview.d01.s02,root.view,INT32,null,null,logical,root.db.d01.s02;",
+
"root.view.myview.d02.s01,root.view,INT32,{\"tag1\":\"value2\",\"tag2\":\"value3\"},{\"attribute1\":\"value1\"},logical,root.db.d02.s01;",
+
"root.view.myview.d02.s02,root.view,INT32,null,null,logical,root.db.d02.s02;",
+
"root.view.cal_view.avg,root.view,DOUBLE,null,null,logical,(root.db.d01.s01 +
root.db.d01.s02) / 2;",
+
"root.view.cal_view.multiple,root.view,DOUBLE,null,null,logical,root.db.d02.s01
* root.db.d02.s02;",
+
"root.view.cal_view.divide,root.view,DOUBLE,null,null,logical,root.db.d02.s01 /
root.db.d02.s02;",
+
"root.view.cal_view.cast_view,root.view,TEXT,null,null,logical,cast(type=TEXT)(root.db.d01.s01);",
+
"root.view.multi_view.all_in_one.d01_s01,root.view,INT32,null,null,logical,root.db.d01.s01;",
+
"root.view.multi_view.all_in_one.d01_s02,root.view,INT32,null,null,logical,root.db.d01.s02;",
+
"root.view.multi_view.all_in_one.d02_s01,root.view,INT32,null,null,logical,root.db.d02.s01;",
+
"root.view.multi_view.all_in_one.d02_s02,root.view,INT32,null,null,logical,root.db.d02.s02;",
+
"root.view.copy_view.d01.s01,root.view,INT32,null,null,logical,root.db.d01.s01;",
+
"root.view.copy_view.d01.s02,root.view,INT32,null,null,logical,root.db.d01.s02;",
+
"root.view.copy_view.d02.s01,root.view,INT32,null,null,logical,root.db.d02.s01;",
+
"root.view.copy_view.d02.s02,root.view,INT32,null,null,logical,root.db.d02.s02;"));
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/mem/info/LogicalViewInfo.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/mem/info/LogicalViewInfo.java
index 12495012772..5ed17ff7893 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/mem/info/LogicalViewInfo.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/mem/info/LogicalViewInfo.java
@@ -37,6 +37,8 @@ import
org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
*/
public class LogicalViewInfo implements IMeasurementInfo {
+ /** tag/attribute's start offset in tag file */
+ private long offset = -1;
/** whether this measurement is pre deleted and considered in black list */
private boolean preDeleted = false;
@@ -107,17 +109,18 @@ public class LogicalViewInfo implements IMeasurementInfo {
@Override
public void setAlias(String alias) {
// can not set alias for a logical view
+ throw new UnsupportedOperationException("View doesn't support alias");
}
@Override
public long getOffset() {
// tag/attribute's start offset in tag file
- return -1;
+ return offset;
}
@Override
public void setOffset(long offset) {
- // can not set offset for a logical view
+ this.offset = offset;
}
@Override
@@ -135,6 +138,7 @@ public class LogicalViewInfo implements IMeasurementInfo {
*
* <ol>
* <li>object header, 8B
+ * <li>offset, 8B
* <li>boolean preDeleted, 1B
* <li>estimated schema size, 32B
* <li>viewExpression
@@ -142,7 +146,7 @@ public class LogicalViewInfo implements IMeasurementInfo {
*/
@Override
public int estimateSize() {
- return 8 + 1 + 32 + 64;
+ return 8 + 8 + 1 + 32 + 64;
}
@Override
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/executor/RegionWriteExecutor.java
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/executor/RegionWriteExecutor.java
index 327b23862c5..8c8793d64b4 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/executor/RegionWriteExecutor.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/executor/RegionWriteExecutor.java
@@ -35,6 +35,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.consensus.DataRegionConsensusImpl;
import org.apache.iotdb.db.consensus.SchemaRegionConsensusImpl;
import org.apache.iotdb.db.exception.metadata.MeasurementAlreadyExistException;
+import org.apache.iotdb.db.exception.metadata.PathNotExistException;
import org.apache.iotdb.db.exception.metadata.SchemaQuotaExceededException;
import org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
import org.apache.iotdb.db.metadata.schemaregion.SchemaEngine;
@@ -43,6 +44,7 @@ import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanVisitor;
import
org.apache.iotdb.db.mpp.plan.planner.plan.node.metedata.write.ActivateTemplateNode;
+import
org.apache.iotdb.db.mpp.plan.planner.plan.node.metedata.write.AlterTimeSeriesNode;
import
org.apache.iotdb.db.mpp.plan.planner.plan.node.metedata.write.BatchActivateTemplateNode;
import
org.apache.iotdb.db.mpp.plan.planner.plan.node.metedata.write.CreateAlignedTimeSeriesNode;
import
org.apache.iotdb.db.mpp.plan.planner.plan.node.metedata.write.CreateMultiTimeSeriesNode;
@@ -616,6 +618,32 @@ public class RegionWriteExecutor {
return result;
}
+ @Override
+ public RegionExecutionResult visitAlterTimeSeries(
+ AlterTimeSeriesNode node, WritePlanNodeExecutionContext context) {
+ ISchemaRegion schemaRegion =
+ SchemaEngine.getInstance().getSchemaRegion((SchemaRegionId)
context.getRegionId());
+ try {
+ List<MeasurementPath> measurementPathList =
+ schemaRegion.fetchSchema(node.getPath(), Collections.emptyMap(),
false);
+ if (node.isAlterView()) {
+ if (measurementPathList.isEmpty()) {
+ throw new PathNotExistException(node.getPath().getFullPath());
+ } else if
(!measurementPathList.get(0).getMeasurementSchema().isLogicalView()) {
+ throw new MetadataException(
+ String.format("%s is not view.",
measurementPathList.get(0).getFullPath()));
+ }
+ }
+ return super.visitAlterTimeSeries(node, context);
+ } catch (MetadataException e) {
+ RegionExecutionResult result = new RegionExecutionResult();
+ result.setAccepted(true);
+ result.setMessage(e.getMessage());
+ result.setStatus(RpcUtils.getStatus(e.getErrorCode(), e.getMessage()));
+ return result;
+ }
+ }
+
@Override
public RegionExecutionResult visitActivateTemplate(
ActivateTemplateNode node, WritePlanNodeExecutionContext context) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index 12d7f31d7c4..69c0b704059 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -1058,31 +1058,39 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
@Override
public Statement
visitRenameLogicalView(IoTDBSqlParser.RenameLogicalViewContext ctx) {
RenameLogicalViewStatement renameLogicalViewStatement = new
RenameLogicalViewStatement();
- renameLogicalViewStatement.setOldName(parsePrefixPath(ctx.prefixPath(0)));
- renameLogicalViewStatement.setNewName(parsePrefixPath(ctx.prefixPath(1)));
+ renameLogicalViewStatement.setOldName(parseFullPath(ctx.fullPath(0)));
+ renameLogicalViewStatement.setNewName(parseFullPath(ctx.fullPath(1)));
return renameLogicalViewStatement;
}
@Override
public Statement
visitAlterLogicalView(IoTDBSqlParser.AlterLogicalViewContext ctx) {
- AlterLogicalViewStatement alterLogicalViewStatement = new
AlterLogicalViewStatement();
- // parse target
- parseViewTargetPaths(
- ctx.viewTargetPaths(),
- alterLogicalViewStatement::setTargetFullPaths,
- alterLogicalViewStatement::setTargetPathsGroup,
- alterLogicalViewStatement::setTargetIntoItem);
- if (alterLogicalViewStatement.getIntoItem() != null) {
- throw new SemanticException("Can not use char '$' or into item in alter
view statement.");
+ if (ctx.alterClause() == null) {
+ AlterLogicalViewStatement alterLogicalViewStatement = new
AlterLogicalViewStatement();
+ // parse target
+ parseViewTargetPaths(
+ ctx.viewTargetPaths(),
+ alterLogicalViewStatement::setTargetFullPaths,
+ alterLogicalViewStatement::setTargetPathsGroup,
+ alterLogicalViewStatement::setTargetIntoItem);
+ if (alterLogicalViewStatement.getIntoItem() != null) {
+ throw new SemanticException("Can not use char '$' or into item in
alter view statement.");
+ }
+ // parse source
+ parseViewSourcePaths(
+ ctx.viewSourcePaths(),
+ alterLogicalViewStatement::setSourceFullPaths,
+ alterLogicalViewStatement::setSourcePathsGroup,
+ alterLogicalViewStatement::setSourceQueryStatement);
+
+ return alterLogicalViewStatement;
+ } else {
+ AlterTimeSeriesStatement alterTimeSeriesStatement = new
AlterTimeSeriesStatement();
+ alterTimeSeriesStatement.setPath(parseFullPath(ctx.fullPath()));
+ parseAlterClause(ctx.alterClause(), alterTimeSeriesStatement);
+ alterTimeSeriesStatement.setAlterView(true);
+ return alterTimeSeriesStatement;
}
- // parse source
- parseViewSourcePaths(
- ctx.viewSourcePaths(),
- alterLogicalViewStatement::setSourceFullPaths,
- alterLogicalViewStatement::setSourcePathsGroup,
- alterLogicalViewStatement::setSourceQueryStatement);
-
- return alterLogicalViewStatement;
}
// parse suffix paths in logical view with into item
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanVisitor.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanVisitor.java
index 14a49611613..ecda02923eb 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanVisitor.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanVisitor.java
@@ -443,7 +443,8 @@ public class LogicalPlanVisitor extends
StatementVisitor<PlanNode, MPPQueryConte
alterTimeSeriesStatement.getAlterMap(),
alterTimeSeriesStatement.getAlias(),
alterTimeSeriesStatement.getTagsMap(),
- alterTimeSeriesStatement.getAttributesMap());
+ alterTimeSeriesStatement.getAttributesMap(),
+ alterTimeSeriesStatement.isAlterView());
}
@Override
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/metedata/write/AlterTimeSeriesNode.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/metedata/write/AlterTimeSeriesNode.java
index 838147968a2..1d413676e49 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/metedata/write/AlterTimeSeriesNode.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/metedata/write/AlterTimeSeriesNode.java
@@ -60,6 +60,8 @@ public class AlterTimeSeriesNode extends WritePlanNode {
private Map<String, String> tagsMap;
private Map<String, String> attributesMap;
+ private transient boolean isAlterView;
+
private TRegionReplicaSet regionReplicaSet;
public AlterTimeSeriesNode(
@@ -69,7 +71,8 @@ public class AlterTimeSeriesNode extends WritePlanNode {
Map<String, String> alterMap,
String alias,
Map<String, String> tagsMap,
- Map<String, String> attributesMap) {
+ Map<String, String> attributesMap,
+ boolean isAlterView) {
super(id);
this.path = path;
this.alterType = alterType;
@@ -127,6 +130,14 @@ public class AlterTimeSeriesNode extends WritePlanNode {
this.attributesMap = attributesMap;
}
+ public boolean isAlterView() {
+ return isAlterView;
+ }
+
+ public void setAlterView(boolean alterView) {
+ isAlterView = alterView;
+ }
+
@Override
public List<PlanNode> getChildren() {
return null;
@@ -167,7 +178,15 @@ public class AlterTimeSeriesNode extends WritePlanNode {
} catch (IllegalPathException e) {
throw new IllegalArgumentException("Can not deserialize
AlterTimeSeriesNode", e);
}
- alterType = AlterType.values()[byteBuffer.get()];
+
+ boolean isAlterView = false;
+ int alterTypeOrdinal = byteBuffer.get();
+ if (alterTypeOrdinal == -1) {
+ isAlterView = true;
+ alterTypeOrdinal = byteBuffer.get();
+ }
+
+ alterType = AlterType.values()[alterTypeOrdinal];
// alias
if (byteBuffer.get() == 1) {
@@ -200,7 +219,7 @@ public class AlterTimeSeriesNode extends WritePlanNode {
id = ReadWriteIOUtils.readString(byteBuffer);
return new AlterTimeSeriesNode(
- new PlanNodeId(id), path, alterType, alterMap, alias, tagsMap,
attributesMap);
+ new PlanNodeId(id), path, alterType, alterMap, alias, tagsMap,
attributesMap, isAlterView);
}
@Override
@@ -214,6 +233,10 @@ public class AlterTimeSeriesNode extends WritePlanNode {
byte[] bytes = path.getFullPath().getBytes();
ReadWriteIOUtils.write(bytes.length, byteBuffer);
byteBuffer.put(bytes);
+
+ if (isAlterView) {
+ byteBuffer.put((byte) -1);
+ }
byteBuffer.put((byte) alterType.ordinal());
// alias
@@ -261,6 +284,10 @@ public class AlterTimeSeriesNode extends WritePlanNode {
byte[] bytes = path.getFullPath().getBytes();
ReadWriteIOUtils.write(bytes.length, stream);
stream.write(bytes);
+
+ if (isAlterView) {
+ stream.write((byte) -1);
+ }
stream.write((byte) alterType.ordinal());
// alias
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/AlterTimeSeriesStatement.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/AlterTimeSeriesStatement.java
index 87487711609..16841670181 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/AlterTimeSeriesStatement.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/metadata/AlterTimeSeriesStatement.java
@@ -53,6 +53,8 @@ public class AlterTimeSeriesStatement extends Statement {
private Map<String, String> tagsMap;
private Map<String, String> attributesMap;
+ private boolean isAlterView = false;
+
public AlterTimeSeriesStatement() {
super();
statementType = StatementType.ALTER_TIMESERIES;
@@ -111,6 +113,14 @@ public class AlterTimeSeriesStatement extends Statement {
this.attributesMap = attributesMap;
}
+ public boolean isAlterView() {
+ return isAlterView;
+ }
+
+ public void setAlterView(boolean alterView) {
+ isAlterView = alterView;
+ }
+
@Override
public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
return visitor.visitAlterTimeseries(this, context);