Caideyipi commented on code in PR #18705:
URL: https://github.com/apache/iotdb/pull/18705#discussion_r4094120567
##########
integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java:
##########
@@ -209,6 +209,21 @@ public void testDevice() throws SQLException {
assertEquals("616: Column 'col' cannot be resolved", e.getMessage());
}
+ try {
+ statement.execute("update table0 set temperature = '1'");
+ fail("Update shall fail for field column");
+ } catch (final Exception e) {
+ assertEquals("616: Column 'temperature' cannot be resolved",
e.getMessage());
Review Comment:
Addressed in 50b85808c56. UPDATE target validation now distinguishes FIELD,
TAG, and TIME columns and reports the specific category; for example: Cannot
update FIELD column 'temperature'. UPDATE can only specify ATTRIBUTE columns.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java:
##########
@@ -1040,10 +1014,50 @@ public Scope visitUpdate(final Update node, final
Optional<Scope> context) {
return new UpdateAssignment(parsedColumn,
expressionPair.getRight());
})
.collect(Collectors.toList()));
+ } else {
+ final Set<String> attributeNames = new HashSet<>();
+ node.getAssignments()
+ .forEach(
+ assignment ->
+ validateUpdateAttributeColumn(assignment.getName(), table,
attributeNames));
+ }
+
+ if (!node.parseWhere(
+ null,
+ table,
+ table.getColumnList().stream()
+ .filter(
+ columnSchema ->
+
columnSchema.getColumnCategory().equals(TsTableColumnCategory.ATTRIBUTE))
+ .map(TsTableColumnSchema::getColumnName)
+ .collect(Collectors.toList()),
+ queryContext)) {
+ analysis.setFinishQueryAfterAnalyze();
+ return null;
}
return null;
}
+ private void validateUpdateAttributeColumn(
+ final Expression column, final TsTable table, final Set<String>
attributeNames) {
+ if (!(column instanceof SymbolReference)) {
+ throw new SemanticException(
+ DataNodeQueryMessages.UPDATE_CAN_ONLY_SPECIFY_ATTRIBUTE_COLUMNS);
+ }
+
+ final String columnName = ((SymbolReference) column).getName();
+ final TsTableColumnSchema columnSchema =
table.getColumnSchema(columnName);
+ if (Objects.isNull(columnSchema)
+ || columnSchema.getColumnCategory() !=
TsTableColumnCategory.ATTRIBUTE) {
+ throw new SemanticException(
+ DataNodeQueryMessages.UPDATE_CAN_ONLY_SPECIFY_ATTRIBUTE_COLUMNS);
+ }
Review Comment:
Addressed in 1a2fc646037. Unknown target columns are now separated from
known non-ATTRIBUTE columns: an unknown target keeps the Column cannot be
resolved error, while FIELD, TAG, and TIME targets use the category-specific
UPDATE error. I also added coverage for a pipe-transferred update with an
unknown target column.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]