Copilot commented on code in PR #7625:
URL: https://github.com/apache/paimon/pull/7625#discussion_r3064578488
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/execution/PaimonViewExec.scala:
##########
@@ -70,6 +68,39 @@ case class CreatePaimonViewExec(
Nil
}
+ /**
+ * Apply column aliases and comments to the view schema. If columnAliases is
empty, the original
+ * column names are used. If columnComments is empty or a specific comment
is None, no comment is
+ * added.
+ */
+ private def applyColumnAliasesAndComments(
+ schema: StructType,
+ aliases: Seq[String],
+ comments: Seq[Option[String]]): StructType = {
+ if (aliases.isEmpty && comments.isEmpty) {
+ return schema
+ }
+
+ val fields = schema.fields.zipWithIndex.map {
+ case (field, index) =>
+ val newName = if (index < aliases.length) aliases(index) else
field.name
+ val newComment = if (index < comments.length) comments(index) else None
+
Review Comment:
`applyColumnAliasesAndComments` currently applies aliases/comments by index
but silently falls back to the original name/comment when the provided lists
are shorter than the schema, and silently ignores extra entries when they are
longer. Because Paimon rewrites `CREATE VIEW` in the parser (so Spark's native
validation won’t run), this should enforce Spark-like semantics: if the user
specified a column list (aliases and/or comments), its length must exactly
match `schema.fields.length`, and aliases should be validated for
duplicates/empties to avoid creating ambiguous view schemas.
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/execution/PaimonViewExec.scala:
##########
@@ -49,10 +49,8 @@ case class CreatePaimonViewExec(
override def output: Seq[Attribute] = Nil
override protected def run(): Seq[InternalRow] = {
- if (columnAliases.nonEmpty || columnComments.nonEmpty ||
queryColumnNames.nonEmpty) {
- throw new UnsupportedOperationException(
- "columnAliases, columnComments and queryColumnNames are not supported
now")
- }
+ // Apply column aliases and comments to the view schema
+ val finalSchema = applyColumnAliasesAndComments(viewSchema, columnAliases,
columnComments)
Review Comment:
`queryColumnNames` is still accepted by `CreatePaimonViewExec` but is now
silently ignored (previously it triggered an UnsupportedOperationException).
Since this rule runs in the parser and bypasses Spark's built-in `CREATE VIEW`
validation/semantics, this can lead to incorrect behavior for Spark
versions/paths that populate `queryColumnNames` (or future compatibility work).
Either implement the intended semantics for `queryColumnNames` or explicitly
reject non-empty values with a clear
`AnalysisException`/`UnsupportedOperationException` so we don't create views
with partially applied metadata.
--
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]