jt2594838 commented on code in PR #18705:
URL: https://github.com/apache/iotdb/pull/18705#discussion_r4091485637


##########
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:
   The message is not proper.



##########
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:
   May distinguish the two kind.



-- 
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]

Reply via email to