未验证 提交 848c908f 编写于 作者: C Chen YZ 提交者: GitHub

Fix duplicate tag/attribute check and alias check when altering view

上级 e5d4745c
......@@ -346,4 +346,58 @@ public class IoTDBAlterViewIT {
Assert.assertTrue(expectedResult.isEmpty());
}
}
@Test
public void testUpsertAliasException() throws Exception {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("create timeseries root.db.d1.s1 with datatype=INT32");
statement.execute("create view root.view.d1.s1 as root.db.d1.s1;");
try {
statement.execute("alter view root.view.d1.s1 upsert alias=a;");
Assert.fail("expect exception");
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("View doesn't support alias"));
}
}
}
@Test
public void testAlterViewTagAttributesException() throws Exception {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("create timeseries root.db.d1.s1 with datatype=INT32");
statement.execute("create view root.view.d1.s1 as root.db.d1.s1;");
try {
statement.execute("alter view root.view.d1.s1 add tags t1=a,t1=b;");
Assert.fail("expect exception");
} catch (Exception e) {
Assert.assertTrue(
e.getMessage().contains("There's duplicate [t1] in tag or attribute clause."));
}
statement.execute("alter view root.view.d1.s1 add tags t1=a,t2=b;");
try {
statement.execute("alter view root.view.d1.s1 set t1=a,t1=b;");
Assert.fail("expect exception");
} catch (Exception e) {
Assert.assertTrue(
e.getMessage().contains("There's duplicate [t1] in tag or attribute clause."));
}
try {
statement.execute("alter view root.view.d1.s1 upsert tags(t1=a,t1=b);");
Assert.fail("expect exception");
} catch (Exception e) {
Assert.assertTrue(
e.getMessage().contains("There's duplicate [t1] in tag or attribute clause."));
}
try {
statement.execute("alter view root.view.d1.s1 rename t2 to t1;");
Assert.fail("expect exception");
} catch (Exception e) {
Assert.assertTrue(
e.getMessage()
.contains("TimeSeries [root.view.d1.s1] already has a tag/attribute named [t1]"));
}
}
}
}
......@@ -1089,6 +1089,9 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
alterTimeSeriesStatement.setPath(parseFullPath(ctx.fullPath()));
parseAlterClause(ctx.alterClause(), alterTimeSeriesStatement);
alterTimeSeriesStatement.setAlterView(true);
if (alterTimeSeriesStatement.getAlias() != null) {
throw new SemanticException("View doesn't support alias.");
}
return alterTimeSeriesStatement;
}
}
......@@ -3002,11 +3005,17 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
/** Utils */
private void setMap(IoTDBSqlParser.AlterClauseContext ctx, Map<String, String> alterMap) {
List<IoTDBSqlParser.AttributePairContext> tagsList = ctx.attributePair();
String key;
if (ctx.attributePair(0) != null) {
for (IoTDBSqlParser.AttributePairContext attributePair : tagsList) {
String value;
value = parseAttributeValue(attributePair.attributeValue());
alterMap.put(parseAttributeKey(attributePair.attributeKey()), value);
key = parseAttributeKey(attributePair.attributeKey());
alterMap.computeIfPresent(
key,
(k, v) -> {
throw new SemanticException(
String.format("There's duplicate [%s] in tag or attribute clause.", k));
});
alterMap.put(key, parseAttributeValue(attributePair.attributeValue()));
}
}
}
......@@ -3016,10 +3025,16 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
IoTDBSqlParser.AttributePairContext attributePair3) {
Map<String, String> tags = new HashMap<>(attributePair2.size());
if (attributePair3 != null) {
String key;
for (IoTDBSqlParser.AttributePairContext attributePair : attributePair2) {
tags.put(
parseAttributeKey(attributePair.attributeKey()),
parseAttributeValue(attributePair.attributeValue()));
key = parseAttributeKey(attributePair.attributeKey());
tags.computeIfPresent(
key,
(k, v) -> {
throw new SemanticException(
String.format("There's duplicate [%s] in tag or attribute clause.", k));
});
tags.put(key, parseAttributeValue(attributePair.attributeValue()));
}
}
return tags;
......
......@@ -60,7 +60,7 @@ public class AlterTimeSeriesNode extends WritePlanNode {
private Map<String, String> tagsMap;
private Map<String, String> attributesMap;
private transient boolean isAlterView;
private boolean isAlterView;
private TRegionReplicaSet regionReplicaSet;
......@@ -80,6 +80,7 @@ public class AlterTimeSeriesNode extends WritePlanNode {
this.alias = alias;
this.tagsMap = tagsMap;
this.attributesMap = attributesMap;
this.isAlterView = isAlterView;
}
public PartialPath getPath() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册