c21 commented on code in PR #37099:
URL: https://github.com/apache/spark/pull/37099#discussion_r915528870
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/createDataSourceTables.scala:
##########
@@ -141,7 +143,19 @@ case class CreateDataSourceTableAsSelectCommand(
mode: SaveMode,
query: LogicalPlan,
outputColumnNames: Seq[String])
- extends DataWritingCommand {
+ extends V1WriteCommand {
+
+ override def requiredOrdering: Seq[SortOrder] = {
+ val unresolvedPartitionColumns =
table.partitionColumnNames.map(UnresolvedAttribute.quoted)
+ val partitionColumns = DataSource.resolvePartitionColumns(
+ unresolvedPartitionColumns,
+ outputColumns,
+ query,
+ SparkSession.active.sessionState.conf.resolver)
+ // We do not need the path option from the table location to get writer
bucket spec.
Review Comment:
sorry why we need the comment here?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/V1Writes.scala:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.datasources
+
+import org.apache.spark.sql.catalyst.SQLConfHelper
+import org.apache.spark.sql.catalyst.catalog.BucketSpec
+import org.apache.spark.sql.catalyst.expressions.{Ascending, Attribute,
AttributeSet, BitwiseAnd, HiveHash, Literal, Pmod, SortOrder}
+import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Sort}
+import org.apache.spark.sql.catalyst.plans.physical.HashPartitioning
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.execution.command.DataWritingCommand
+import org.apache.spark.sql.internal.SQLConf
+
+trait V1WriteCommand extends DataWritingCommand {
+ // Specify the required ordering for the V1 write command.
`FileFormatWriter` will
+ // add SortExec if necessary when the requiredOrdering is empty.
+ def requiredOrdering: Seq[SortOrder]
Review Comment:
Just brainstorming here, if we plan to add a requirement for partitioning,
e.g. support shuffle before writing bucket table. Do we want to add a similar
`RequiresDistributionAndOrdering` as
[v2](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/java/org/apache/spark/sql/connector/write/RequiresDistributionAndOrdering.java)
now or not?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala:
##########
@@ -211,6 +180,7 @@ object FileFormatWriter extends Logging {
try {
val (rdd, concurrentOutputWriterSpec) = if (orderingMatched) {
+ logInfo(s"Output ordering is matched for write job
${description.uuid}")
Review Comment:
Is it just for debugging?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3781,6 +3781,14 @@ object SQLConf {
.intConf
.createWithDefault(0)
+ val PLANNED_WRITE_ENABLED = buildConf("spark.sql.plannedWrite.enabled")
+ .internal()
+ .doc("When set to true, Spark adds logical sorts to V1 write commands if
needed so that " +
+ "`FileFormatWriter` does not need to insert physical sorts.")
+ .version("3.2.0")
Review Comment:
nit: `3.4.0`?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3781,6 +3781,14 @@ object SQLConf {
.intConf
.createWithDefault(0)
+ val PLANNED_WRITE_ENABLED = buildConf("spark.sql.plannedWrite.enabled")
+ .internal()
+ .doc("When set to true, Spark adds logical sorts to V1 write commands if
needed so that " +
Review Comment:
`Spark` -> `Spark optimizer` could be clearer that sort is added during
query planning.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3781,6 +3781,14 @@ object SQLConf {
.intConf
.createWithDefault(0)
+ val PLANNED_WRITE_ENABLED = buildConf("spark.sql.plannedWrite.enabled")
Review Comment:
nit: feeling the config name is a little bit obscure. could it be
`spark.sql.requireOrderingForV1Writers` or something similar?
--
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]