From 9b04df7d7b445aee41deaabb20b638847cba04e1 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:49:26 +0800 Subject: [PATCH] Optimized the error log of devices related operations when where specifies time/measurement columns --- .../iotdb/relational/it/schema/IoTDBDeviceIT.java | 15 +++++++++++++-- .../relational/analyzer/StatementAnalyzer.java | 10 +--------- .../schema/CheckSchemaPredicateVisitor.java | 12 ++++++++++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java index e7ac5eef74cb..95fb1a0fede1 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java @@ -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 { @@ -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", @@ -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()); + } } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java index fdf9c032742f..8fdc1d2ae89b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java @@ -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 fieldList = fields.build(); final Scope scope = createAndAssignScope(node, context, fieldList); translationMap = diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/CheckSchemaPredicateVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/CheckSchemaPredicateVisitor.java index a7b6cec08212..9bcc6f869e32 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/CheckSchemaPredicateVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/CheckSchemaPredicateVisitor.java @@ -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; @@ -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 {