Copilot commented on code in PR #58084:
URL: https://github.com/apache/spark/pull/58084#discussion_r3806127738
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveInsertionBase.scala:
##########
@@ -11,67 +11,70 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * See the License for the specifions and
* limitations under the License.
*/
-package org.apache.spark.sql.catalyst.analysis
+package org.apache.spark.sql.catal
import org.apache.spark.sql.catalyst.expressions.{Alias, Cast}
-import org.apache.spark.sql.catalyst.plans.logical.{InsertIntoStatement,
LogicalPlan, Project}
+import org.apache.spark.sql.catalytatement, LogicalPlan, Project}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.errors.QueryCompilationErrors
-import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.types.{ArrayType, DataType, MapType, StructType}
import org.apache.spark.sql.util.SchemaUtils
abstract class ResolveInsertionBase extends Rule[LogicalPlan] {
- def resolver: Resolver = conf.resolver
+ def resolver: Resolver = conf.re
/** Add a project to use the table column names for INSERT INTO BY NAME */
- protected def createProjectForByNameQuery(
+ protected def createProjectForBy
tblName: String,
i: InsertIntoStatement): LogicalPlan = {
- SchemaUtils.checkColumnNameDuplication(i.userSpecifiedCols, resolver)
+ SchemaUtils.checkColumnNameDup resolver)
if (i.userSpecifiedCols.size != i.query.output.size) {
if (i.userSpecifiedCols.size > i.query.output.size) {
- throw QueryCompilationErrors.cannotWriteNotEnoughColumnsToTableError(
+ throw QueryCompilationErrosToTableError(
tblName, i.userSpecifiedCols, i.query.output)
} else {
throw QueryCompilationErrors.cannotWriteTooManyColumnsToTableError(
- tblName, i.userSpecifiedCols, i.query.output)
+ tblName, i.userSpecified
}
}
val projectByName = i.userSpecifiedCols.zip(i.query.output)
.map { case (userSpecifiedCol, queryOutputCol) =>
- val resolvedCol = i.table.resolve(Seq(userSpecifiedCol), resolver)
+ val resolvedCol = i.table., resolver)
.getOrElse(
throw QueryCompilationErrors.unresolvedAttributeError(
"UNRESOLVED_COLUMN", userSpecifiedCol,
i.table.output.map(_.name), i.origin))
- (queryOutputCol.dataType, resolvedCol.dataType) match {
- 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 _ =>
- Alias(queryOutputCol, resolvedCol.name)()
+ val renamedType = renameFi.dataType, resolvedCol.dataType)
+ if (queryOutputCol.dataType == renamedType) {
+ Alias(queryOutputCol, re
+ } else {
+ Alias(Cast(queryOutputConame)()
}
Review Comment:
This change expands behavior to arrays/maps of structs (and potentially
deeper nesting), which is a regression-prone analyzer edge. Please add a
catalyst/analyzer or SQL test that covers `INSERT INTO t (cols...) SELECT ...`
where the source struct field order differs from the target for: (1) direct
`STRUCT`, (2) `ARRAY<STRUCT<...>>`, and (3) `MAP<..., STRUCT<...>>` to ensure
nested fields resolve positionally (and stay consistent across all three).
--
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]