dongjoon-hyun commented on code in PR #60393:
URL: https://github.com/apache/spark/pull/60393#discussion_r4555290965


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/GeneratedColumn.scala:
##########
@@ -117,8 +117,10 @@ object GeneratedColumn {
   def supportsGeneratedColumnsOnWrite(
       table: Table,
       columns: Array[Column]): Boolean = {
-    supportsGeneratedColumnsOnWrite(table) &&
-      columns.exists(_.columnGenerationExpression() != null)
+    supportsGeneratedColumnsOnWrite(table) && columns.exists { col =>
+      // A connector can implement only the legacy SQL getter, which auto-fill 
reads as well.
+      col.columnGenerationExpression() != null || col.generationExpression() 
!= null

Review Comment:
   Thank you, @viirya. You're right that #60368 doesn't touch that line, so I 
included it in this PR. I added 
`GeneratedColumn.columnGenerationExpression(col)` as you suggested and used it 
in both `supportsGeneratedColumnsOnWrite` and 
`buildGeneratedColumnConstraints`. A new test checks that an INSERT with a 
mismatched value for a legacy SQL-only column fails with 
`CHECK_CONSTRAINT_VIOLATION`. I also updated the PR title and description.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/connector/GeneratedColumnWriteSuite.scala:
##########
@@ -1476,6 +1516,40 @@ class GeneratedColumnWriteSuite extends QueryTest with 
DatasourceV2SQLBase {
     }
   }
 
+  test("SPARK-61550: UPDATE and MERGE with a legacy SQL-only generated column 
are blocked") {

Review Comment:
   Thank you. I added the INSERT-by-name check at the end of this test. It runs 
after UPDATE and MERGE, because a write to this in-memory table rebuilds its 
columns from the schema, after which the column has 
`columnGenerationExpression()`. If the INSERT ran first, the UPDATE and MERGE 
checks would pass even without this fix.
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to