HyukjinKwon commented on a change in pull request #28032:
URL: https://github.com/apache/spark/pull/28032#discussion_r646223698
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala
##########
@@ -221,6 +221,46 @@ object DataSourceAnalysis extends Rule[LogicalPlan] with
CastSupport {
}
}
+/**
+ * Add a repartition by dynamic partition columns before insert Datasource
table.
+ *
+ * Note that, this rule must be run after `DataSourceAnalysis`.
+ */
+object RepartitionBeforeInsertDataSourceTable extends Rule[LogicalPlan] {
+ override def apply(plan: LogicalPlan): LogicalPlan = {
+ if (conf.repartitionBeforeInsert) {
+ insertRepartition(plan)
+ } else {
+ plan
+ }
+ }
+
+ private def insertRepartition(plan: LogicalPlan): LogicalPlan = plan
resolveOperators {
+ case c @ CreateDataSourceTableAsSelectCommand(table, _, query, _)
+ if query.resolved && DDLUtils.isDatasourceTable(table) &&
table.bucketSpec.isEmpty
+ && table.partitionColumnNames.nonEmpty =>
+ val dynamicPartExps = table.partitionColumnNames.flatMap(n =>
query.output.find(_.name == n))
+ query match {
+ case RepartitionByExpression(partExpressions, _, _) if partExpressions
== dynamicPartExps =>
Review comment:
Can we avoid `, _, _)` style since we're referring one field
`partitionExpressions`
(https://github.com/databricks/scala-style-guide#pattern-matching)? We could do
`r: RepartitionByExpression if r. partExpressions == dynamicPartExps =>`
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]