Skip to content

Commit

Permalink
Optimized the error log of devices related operations when where spec…
Browse files Browse the repository at this point in the history
…ifies time/measurement columns
  • Loading branch information
Caideyipi authored Dec 5, 2024
1 parent e46d34a commit 9b04df7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public void testDevice() throws SQLException {
statement.executeQuery("show devices from table0 where temperature = 37.6");
fail("Show devices shall fail for measurement predicate");
} catch (final Exception e) {
assertEquals("701: Column 'temperature' cannot be resolved", e.getMessage());
assertEquals(
"701: The TIME/MEASUREMENT columns are currently not allowed in devices related operations",
e.getMessage());
}

try {
Expand Down Expand Up @@ -217,7 +219,7 @@ public void testDevice() throws SQLException {

try {
statement.execute("update table0 set model = cast(device_id as int32)");
fail("Update shall fail for non-exist column");
fail("Update shall fail when result type mismatch");
} catch (final Exception e) {
assertEquals(
"507: Result type mismatch for attribute 'model', expected class org.apache.tsfile.utils.Binary, actual class java.lang.Integer",
Expand Down Expand Up @@ -261,6 +263,15 @@ public void testDevice() throws SQLException {
// 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 id column");
} catch (final Exception e) {
assertEquals(
"701: The TIME/MEASUREMENT 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 @@ -3003,15 +3003,7 @@ private TranslationMap analyzeTraverseDevice(
analyzeTableOutputFields(
node.getTable(),
name,
new TableSchema(
originalSchema.getTableName(),
originalSchema.getColumns().stream()
.filter(
columnSchema ->
columnSchema.getColumnCategory() == TsTableColumnCategory.ID
|| columnSchema.getColumnCategory()
== TsTableColumnCategory.ATTRIBUTE)
.collect(Collectors.toList()))));
new TableSchema(originalSchema.getTableName(), originalSchema.getColumns())));
final List<Field> fieldList = fields.build();
final Scope scope = createAndAssignScope(node, context, fieldList);
translationMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.iotdb.commons.schema.table.TsTable;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.AstVisitor;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.BetweenPredicate;
Expand Down Expand Up @@ -102,8 +103,15 @@ private boolean processColumn(final Expression node, final Context context) {
final TsTableColumnSchema schema =
context.table.getColumnSchema(
node.accept(ExtractPredicateColumnNameVisitor.getInstance(), null));
return Objects.isNull(schema)
|| schema.getColumnCategory().equals(TsTableColumnCategory.ATTRIBUTE);
if (Objects.isNull(schema)) {
return true;
}
if (schema.getColumnCategory() == TsTableColumnCategory.TIME
|| schema.getColumnCategory() == TsTableColumnCategory.MEASUREMENT) {
throw new SemanticException(
"The TIME/MEASUREMENT columns are currently not allowed in devices related operations");
}
return schema.getColumnCategory().equals(TsTableColumnCategory.ATTRIBUTE);
}

public static class Context {
Expand Down

0 comments on commit 9b04df7

Please sign in to comment.