danny0405 commented on code in PR #11650:
URL: https://github.com/apache/hudi/pull/11650#discussion_r1689159522
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieSchemaUtils.scala:
##########
@@ -244,4 +245,24 @@ object HoodieSchemaUtils {
(newSchema, isSchemaCompatible(tableSchema, newSchema))
}
}
+
+ /**
+ * Check if the partition schema fields order matches the table schema
fields order.
+ *
+ * @param tableSchema The table schema
+ * @param partitionFields The partition fields
+ */
+ def checkPartitionSchemaOrder(tableSchema: StructType, partitionFields:
Seq[String]): Unit = {
+ val tableSchemaFields = tableSchema.fields.map(_.name)
+ // It is not allowed to specify partition columns when the table schema is
not defined.
+ //
https://spark.apache.org/docs/latest/sql-error-conditions.html#specify_partition_is_not_allowed
+ if (tableSchemaFields.isEmpty && partitionFields.nonEmpty) {
+ throw new IllegalArgumentException("It is not allowed to specify
partition columns when the table schema is not defined.")
+ }
+ // Filter the table schema fields to get the partition field names in order
+ val tableSchemaPartitionFields =
tableSchemaFields.filter(partitionFields.contains).toSeq
+ if (tableSchemaPartitionFields != partitionFields) {
+ throw new IllegalArgumentException("Partition schema fields order does
not match the table schema fields order.")
Review Comment:
It's great if we also print these two schemas in the log.
--
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]