viirya commented on code in PR #60393:
URL: https://github.com/apache/spark/pull/60393#discussion_r4554446168


##########
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:
   Optional: an INSERT-by-name on this table asserting `doubled` is auto-filled 
would pin the premise of this fix (auto-fill reads the legacy getter while the 
block did not).



##########
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:
   With this, a legacy SQL-only column is auto-filled and blocked consistently, 
but an explicitly provided value on INSERT is still not validated. Could you 
link the follow-up JIRA here?
   
   One option for it: a helper in `GeneratedColumn` that returns 
`columnGenerationExpression()` or else `new 
GenerationExpression(col.generationExpression())`, shared by this predicate and 
`buildGeneratedColumnConstraints`. #60368 doesn't touch the 
`Option(col.columnGenerationExpression())` line, so it could also fit in this 
PR if you prefer.



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