Skip to content

Commit c357f2b

Browse files
committed
add it
1 parent ade34e0 commit c357f2b

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.relational.it.query.view.recent;
21+
22+
import org.apache.iotdb.isession.ISession;
23+
import org.apache.iotdb.isession.SessionDataSet;
24+
import org.apache.iotdb.it.env.EnvFactory;
25+
import org.apache.iotdb.rpc.IoTDBConnectionException;
26+
import org.apache.iotdb.rpc.StatementExecutionException;
27+
28+
import org.junit.AfterClass;
29+
import org.junit.Assert;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
33+
public class IoTDBTableViewAddColumnTest {
34+
35+
@BeforeClass
36+
public static void setUp() throws Exception {
37+
EnvFactory.getEnv().initClusterEnvironment();
38+
}
39+
40+
@AfterClass
41+
public static void tearDown() {
42+
EnvFactory.getEnv().cleanClusterEnvironment();
43+
}
44+
45+
@Test
46+
public void testAddColumn() throws IoTDBConnectionException, StatementExecutionException {
47+
String[] sqls = {
48+
"set sql_dialect=tree",
49+
"create database root.db",
50+
"insert into root.db.风机组.风机号1(time,电压,current) aligned values(10000,99.09,88.07)",
51+
"insert into root.db.风机组.风机号2(time,电压,电流) values(20000,99.09,88.07)",
52+
"set sql_dialect=table",
53+
"create database db",
54+
"use db",
55+
"CREATE OR REPLACE VIEW \"风机表\""
56+
+ "(\"风机组\" TAG, "
57+
+ "\"风机号\" TAG, "
58+
+ "\"电压\" DOUBLE FIELD, "
59+
+ "\"电流\" DOUBLE FIELD) "
60+
+ "with (ttl='INF') "
61+
+ "AS root.db.**",
62+
"ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN IF NOT EXISTS \"风机组\" TAG",
63+
"ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN IF NOT EXISTS \"风机组\" string",
64+
"ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists \"风机组\" field",
65+
"ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists \"电流\" DOUBLE FIELD from current",
66+
"show create view \"风机表\"",
67+
};
68+
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
69+
for (String sql : sqls) {
70+
session.executeNonQueryStatement(sql);
71+
}
72+
73+
session.executeNonQueryStatement(
74+
"ALTER VIEW IF EXISTS \"风机表\" ADD COLUMN if not exists current field");
75+
SessionDataSet sessionDataSet = session.executeQueryStatement("desc \"风机表\"");
76+
int rowNum = 0;
77+
while (sessionDataSet.hasNext()) {
78+
sessionDataSet.next();
79+
rowNum++;
80+
}
81+
Assert.assertEquals(6, rowNum);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)