EamesTrinh commented on code in PR #58831:
URL: https://github.com/apache/spark/pull/58831#discussion_r4561841336
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveInsertionBase.scala:
##########
@@ -64,25 +65,27 @@ abstract class ResolveInsertionBase extends
Rule[LogicalPlan] {
}
private def renameFieldsInStruct(input: StructType, expected: StructType):
StructType = {
- if (input.length == expected.length) {
+ if (input.length == expected.length || resolveNestedFieldsByPosition) {
val newFields = input.zip(expected).map { case (f1, f2) =>
f1.copy(name = f2.name, dataType = renameFieldsInType(f1.dataType,
f2.dataType))
}
- StructType(newFields)
+ StructType(newFields ++ input.drop(expected.length))
Review Comment:
This is now covered by the rename-created collision regressions. The
implementation rejects the manufactured duplicate before schema evolution or
output resolution, and verifies the table schema remains unchanged.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveInsertionBase.scala:
##########
@@ -64,25 +65,27 @@ abstract class ResolveInsertionBase extends
Rule[LogicalPlan] {
}
private def renameFieldsInStruct(input: StructType, expected: StructType):
StructType = {
- if (input.length == expected.length) {
+ if (input.length == expected.length || resolveNestedFieldsByPosition) {
val newFields = input.zip(expected).map { case (f1, f2) =>
f1.copy(name = f2.name, dataType = renameFieldsInType(f1.dataType,
f2.dataType))
}
- StructType(newFields)
+ StructType(newFields ++ input.drop(expected.length))
Review Comment:
Implemented the targeted early check in `renameFieldsInStruct`. It rejects
only collisions introduced by positional renaming, uses the session resolver,
preserves user-written duplicates, and carries nested `element`, `key`,
`value`, and struct-field paths. Coverage includes schema non-mutation and
`ACCEPT_ANY_SCHEMA`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveInsertionBase.scala:
##########
@@ -52,9 +53,9 @@ abstract class ResolveInsertionBase extends Rule[LogicalPlan]
{
case (input: StructType, expected: StructType) =>
// Rename inner fields of the input column to pass the by-name
INSERT analysis.
Alias(Cast(queryOutputCol, renameFieldsInStruct(input, expected)),
resolvedCol.name)()
- case (input: ArrayType, expected: ArrayType) =>
+ case (input: ArrayType, expected: ArrayType) if
resolveNestedFieldsByPosition =>
Review Comment:
Updated the flag scope so array/map traversal remains unconditional. The
flag now gates only different-arity struct resolution, and the flag-off
regression verifies the SPARK-58816 equal-arity behavior remains positional.
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/InsertIntoTests.scala:
##########
@@ -736,6 +736,31 @@ trait InsertIntoSchemaEvolutionTests { this:
InsertIntoTests =>
}
}
+ Seq(
+ true -> Row(1, 2, 3),
+ false -> Row(2, 1, 3)
+ ).foreach { case (resolveNestedFieldsByPosition, expected) =>
+ test("Insert schema evolution: column list resolves nested fields by
position - " +
Review Comment:
Coverage now includes different-arity structs in direct, array, and
map-value positions under both flag states, plus equal-arity map keys and
values.
--
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]