Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi committed Nov 29, 2024
1 parent 05bc4fd commit 100ce18
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,21 @@ public void testDevice() throws SQLException {
TestUtils.assertResultSetSize(
statement.executeQuery("show devices from table0 offset 1 limit 1"), 1);

// Test delete devices
statement.execute("delete devices from table0 where region_id = '1' and plant_id = '5'");
TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 1);
// TODO: Reopen
if (false) {
// Test delete devices
statement.execute("delete devices from table0 where region_id = '1' and plant_id = '5'");
TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 1);

// Test successfully invalidate cache
statement.execute(
"insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '5', '3', 'A', 37.6, 111.1)");
TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 2);
// Test successfully invalidate cache
statement.execute(
"insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '5', '3', 'A', 37.6, 111.1)");
TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 2);

// Test successfully delete data
TestUtils.assertResultSetSize(
statement.executeQuery("select * from table0 where region_id = '1'"), 1);
// Test successfully delete data
TestUtils.assertResultSetSize(
statement.executeQuery("select * from table0 where region_id = '1'"), 1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,66 +385,69 @@ public void testManageTable() {
statement.execute(
"insert into table2(region_id, plant_id, color, temperature, speed) values(1, 1, 1, 1, 1)");

// Test drop column
statement.execute("alter table table2 drop column color");

columnNames = new String[] {"time", "region_id", "plant_id", "temperature", "speed"};
dataTypes = new String[] {"TIMESTAMP", "STRING", "STRING", "FLOAT", "DOUBLE"};
categories = new String[] {"TIME", "ID", "ID", "MEASUREMENT", "MEASUREMENT"};
final String[] statuses = new String[] {"USING", "USING", "USING", "USING", "USING"};
try (final ResultSet resultSet = statement.executeQuery("describe table2 details")) {
int cnt = 0;
ResultSetMetaData metaData = resultSet.getMetaData();
assertEquals(describeTableDetailsColumnHeaders.size(), metaData.getColumnCount());
for (int i = 0; i < describeTableDetailsColumnHeaders.size(); i++) {
assertEquals(
describeTableDetailsColumnHeaders.get(i).getColumnName(),
metaData.getColumnName(i + 1));
}
while (resultSet.next()) {
assertEquals(columnNames[cnt], resultSet.getString(1));
assertEquals(dataTypes[cnt], resultSet.getString(2));
assertEquals(categories[cnt], resultSet.getString(3));
assertEquals(statuses[cnt], resultSet.getString(4));
cnt++;
// TODO: Reopen
if (false) {
// Test drop column
statement.execute("alter table table2 drop column color");

columnNames = new String[] {"time", "region_id", "plant_id", "temperature", "speed"};
dataTypes = new String[] {"TIMESTAMP", "STRING", "STRING", "FLOAT", "DOUBLE"};
categories = new String[] {"TIME", "ID", "ID", "MEASUREMENT", "MEASUREMENT"};
final String[] statuses = new String[] {"USING", "USING", "USING", "USING", "USING"};
try (final ResultSet resultSet = statement.executeQuery("describe table2 details")) {
int cnt = 0;
ResultSetMetaData metaData = resultSet.getMetaData();
assertEquals(describeTableDetailsColumnHeaders.size(), metaData.getColumnCount());
for (int i = 0; i < describeTableDetailsColumnHeaders.size(); i++) {
assertEquals(
describeTableDetailsColumnHeaders.get(i).getColumnName(),
metaData.getColumnName(i + 1));
}
while (resultSet.next()) {
assertEquals(columnNames[cnt], resultSet.getString(1));
assertEquals(dataTypes[cnt], resultSet.getString(2));
assertEquals(categories[cnt], resultSet.getString(3));
assertEquals(statuses[cnt], resultSet.getString(4));
cnt++;
}
assertEquals(columnNames.length, cnt);
}
assertEquals(columnNames.length, cnt);
}

statement.execute("alter table table2 drop column speed");
statement.execute("alter table table2 drop column speed");

try {
statement.executeQuery("select color from table2");
fail();
} catch (final SQLException e) {
assertEquals("701: Column 'color' cannot be resolved", e.getMessage());
}
try {
statement.executeQuery("select color from table2");
fail();
} catch (final SQLException e) {
assertEquals("701: Column 'color' cannot be resolved", e.getMessage());
}

try {
statement.executeQuery("select speed from table2");
fail();
} catch (final SQLException e) {
assertEquals("701: Column 'speed' cannot be resolved", e.getMessage());
}
try {
statement.executeQuery("select speed from table2");
fail();
} catch (final SQLException e) {
assertEquals("701: Column 'speed' cannot be resolved", e.getMessage());
}

try {
statement.execute("alter table table2 drop column speed");
} catch (final SQLException e) {
assertEquals("616: Column speed in table 'test2.table2' does not exist.", e.getMessage());
}
try {
statement.execute("alter table table2 drop column speed");
} catch (final SQLException e) {
assertEquals("616: Column speed in table 'test2.table2' does not exist.", e.getMessage());
}

try {
statement.execute("alter table table2 drop column time");
} catch (final SQLException e) {
assertEquals("701: Dropping id or time column is not supported.", e.getMessage());
}
try {
statement.execute("alter table table2 drop column time");
} catch (final SQLException e) {
assertEquals("701: Dropping id or time column is not supported.", e.getMessage());
}

// test data deletion by drop column
statement.execute("alter table table2 add column speed double");
TestUtils.assertResultSetEqual(
statement.executeQuery("select speed from table2"),
"speed,",
Collections.singleton("null,"));
// test data deletion by drop column
statement.execute("alter table table2 add column speed double");
TestUtils.assertResultSetEqual(
statement.executeQuery("select speed from table2"),
"speed,",
Collections.singleton("null,"));
}

statement.execute("drop table table2");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class DeleteDevice extends AbstractTraverseDevice {

public DeleteDevice(final NodeLocation location, final Table table, final Expression where) {
super(location, table, where);
throw new UnsupportedOperationException("Delete device is unsupported yet.");
}

public void parseModEntries(final TsTable table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public class DropColumn extends Statement {
private final boolean tableIfExists;
private final boolean columnIfExists;

public DropColumn(
final QualifiedName table,
final Identifier field,
final boolean tableIfExists,
final boolean columnIfExists) {
super(null);
this.table = requireNonNull(table, "table is null");
this.field = requireNonNull(field, "field is null");
this.tableIfExists = tableIfExists;
this.columnIfExists = columnIfExists;
}

public DropColumn(
final NodeLocation location,
final QualifiedName table,
Expand All @@ -58,6 +46,7 @@ public DropColumn(
this.field = requireNonNull(field, "field is null");
this.tableIfExists = tableIfExists;
this.columnIfExists = columnIfExists;
throw new UnsupportedOperationException("Drop column is unsupported yet.");
}

public QualifiedName getTable() {
Expand Down

0 comments on commit 100ce18

Please sign in to comment.