Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reopen drop column and delete devices operations #14645

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,26 @@ public void testDevice() throws SQLException {
TestUtils.assertResultSetSize(
statement.executeQuery("show devices from table0 offset 1 limit 1"), 1);

// TODO: Reopen
if (false) {
// Test delete devices
statement.execute("delete devices from table0 where region_id = '1' and plant_id = '木兰'");
TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 1);
// Test delete devices
statement.execute("delete devices from table0 where region_id = '1' and plant_id = '木兰'");
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', '木兰', '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', '木兰', '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);

try {
statement.executeQuery("delete devices from table0 where time = 1");
fail("Delete devices shall fail when specifies non tag column");
} catch (final Exception e) {
assertEquals(
"701: The TIME/FIELD columns are currently not allowed in devices related operations",
e.getMessage());
}
try {
statement.executeQuery("delete devices from table0 where time = 1");
fail("Delete devices shall fail when specifies non tag column");
} catch (final Exception e) {
assertEquals(
"701: The TIME/FIELD columns are currently not allowed in devices related operations",
e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,70 +390,67 @@ public void testManageTable() {
statement.execute(
"insert into table2(region_id, plant_id, color, temperature, speed) values(1, 1, 1, 1, 1)");

// 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", "TAG", "TAG", "FIELD", "FIELD"};
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);
// 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", "TAG", "TAG", "FIELD", "FIELD"};
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));
}

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

try {
statement.executeQuery("select color from table2");
fail();
} catch (final SQLException e) {
assertEquals("616: Column 'color' cannot be resolved", e.getMessage());
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);
}

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

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.executeQuery("select color from table2");
fail();
} catch (final SQLException e) {
assertEquals("616: Column 'color' cannot be resolved", e.getMessage());
}

try {
statement.execute("alter table table2 drop column time");
} catch (final SQLException e) {
assertEquals("701: Dropping tag or time column is not supported.", e.getMessage());
}
try {
statement.executeQuery("select speed from table2");
fail();
} catch (final SQLException e) {
assertEquals("616: Column 'speed' cannot be resolved", 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,"));
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 tag 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,"));

statement.execute("drop table table2");
try {
statement.executeQuery("describe table2");
Expand Down Expand Up @@ -504,14 +501,11 @@ public void testManageTable() {
assertEquals("500: Unknown database test1", e.getMessage());
}

// TODO: Reopen
if (false) {
try {
statement.execute("alter table test1.test drop column a");
fail();
} catch (final SQLException e) {
assertEquals("500: Unknown database test1", e.getMessage());
}
try {
statement.execute("alter table test1.test drop column a");
fail();
} catch (final SQLException e) {
assertEquals("500: Unknown database test1", e.getMessage());
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public boolean preDeleteColumn(
}
if (columnSchema.getColumnCategory() == TsTableColumnCategory.TAG
|| columnSchema.getColumnCategory() == TsTableColumnCategory.TIME) {
throw new SemanticException("Dropping id or time column is not supported.");
throw new SemanticException("Dropping tag or time column is not supported.");
}

node.addPreDeletedColumn(columnName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.iotdb.commons.schema.column.ColumnHeader;
import org.apache.iotdb.commons.schema.filter.SchemaFilter;
import org.apache.iotdb.commons.schema.table.TsTable;
import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.queryengine.common.SessionInfo;
import org.apache.iotdb.db.queryengine.execution.operator.schema.source.DeviceBlackListConstructor;
import org.apache.iotdb.db.queryengine.execution.operator.schema.source.TableDeviceQuerySource;
Expand Down Expand Up @@ -68,7 +67,6 @@ public class DeleteDevice extends AbstractTraverseDevice {

public DeleteDevice(final NodeLocation location, final Table table, final Expression where) {
super(location, table, where);
throw new SemanticException("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 @@ -19,8 +19,6 @@

package org.apache.iotdb.db.queryengine.plan.relational.sql.ast;

import org.apache.iotdb.db.exception.sql.SemanticException;

import com.google.common.collect.ImmutableList;

import java.util.List;
Expand Down Expand Up @@ -48,7 +46,6 @@ public DropColumn(
this.field = requireNonNull(field, "field is null");
this.tableIfExists = tableIfExists;
this.columnIfExists = columnIfExists;
throw new SemanticException("Drop column is unsupported yet.");
}

public QualifiedName getTable() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<thrift.version>0.14.1</thrift.version>
<xz.version>1.9</xz.version>
<zstd-jni.version>1.5.6-3</zstd-jni.version>
<tsfile.version>1.2.0-241224-SNAPSHOT</tsfile.version>
<tsfile.version>2.0.0-250109-SNAPSHOT</tsfile.version>
</properties>
<!--
if we claim dependencies in dependencyManagement, then we do not claim
Expand Down
Loading