-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into consistent-hash
- Loading branch information
Showing
233 changed files
with
1,680 additions
and
1,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...se/src-delta-32/main/scala/org/apache/spark/sql/execution/datasources/DeltaV1Writes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.gluten.backendsapi.BackendsApiManager | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.catalog.BucketSpec | ||
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder} | ||
import org.apache.spark.sql.catalyst.plans.logical.LocalRelation | ||
import org.apache.spark.sql.execution.{QueryExecution, SortExec, SparkPlan} | ||
import org.apache.spark.sql.execution.datasources.V1WritesUtils.isOrderingMatched | ||
|
||
case class DeltaV1Writes( | ||
spark: SparkSession, | ||
query: SparkPlan, | ||
fileFormat: FileFormat, | ||
partitionColumns: Seq[Attribute], | ||
bucketSpec: Option[BucketSpec], | ||
options: Map[String, String], | ||
staticPartitions: TablePartitionSpec = Map.empty) { | ||
|
||
require(fileFormat != null, "FileFormat is required to write files.") | ||
require(BackendsApiManager.getSettings.enableNativeWriteFiles()) | ||
|
||
private lazy val requiredOrdering: Seq[SortOrder] = | ||
V1WritesUtils.getSortOrder( | ||
query.output, | ||
partitionColumns, | ||
bucketSpec, | ||
options, | ||
staticPartitions.size) | ||
|
||
lazy val sortPlan: SparkPlan = { | ||
val outputOrdering = query.outputOrdering | ||
val orderingMatched = isOrderingMatched(requiredOrdering.map(_.child), outputOrdering) | ||
if (orderingMatched) { | ||
query | ||
} else { | ||
SortExec(requiredOrdering, global = false, query) | ||
} | ||
} | ||
|
||
lazy val writePlan: SparkPlan = | ||
WriteFilesExec( | ||
sortPlan, | ||
fileFormat = fileFormat, | ||
partitionColumns = partitionColumns, | ||
bucketSpec = bucketSpec, | ||
options = options, | ||
staticPartitions = staticPartitions) | ||
|
||
lazy val executedPlan: SparkPlan = | ||
CallTransformer(spark, writePlan).executedPlan | ||
} | ||
|
||
case class CallTransformer(spark: SparkSession, physicalPlan: SparkPlan) | ||
extends QueryExecution(spark, LocalRelation()) { | ||
override lazy val sparkPlan: SparkPlan = physicalPlan | ||
} |
100 changes: 100 additions & 0 deletions
100
...c-delta-32/test/scala/org/apache/spark/sql/execution/datasources/DeltaV1WritesSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.gluten.GlutenConfig | ||
import org.apache.gluten.execution.{GlutenClickHouseWholeStageTransformerSuite, GlutenPlan, SortExecTransformer} | ||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat | ||
import org.apache.spark.sql.execution.{SortExec, SparkPlan} | ||
|
||
class DeltaV1WritesSuite extends GlutenClickHouseWholeStageTransformerSuite { | ||
|
||
import testImplicits._ | ||
|
||
override protected def sparkConf: SparkConf = { | ||
super.sparkConf | ||
.set(GlutenConfig.NATIVE_WRITER_ENABLED.key, "true") | ||
} | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
(0 to 20) | ||
.map(i => (i, i % 5, (i % 10).toString)) | ||
.toDF("i", "j", "k") | ||
.write | ||
.saveAsTable("t0") | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
sql("drop table if exists t0") | ||
super.afterAll() | ||
} | ||
|
||
val format = new ParquetFileFormat | ||
def getSort(child: SparkPlan): Option[SortExecTransformer] = { | ||
child.collectFirst { case w: SortExecTransformer => w } | ||
} | ||
test("don't add sort when the required ordering is empty") { | ||
val df = sql("select * from t0") | ||
val plan = df.queryExecution.sparkPlan | ||
val writes = DeltaV1Writes(spark, plan, format, Nil, None, Map.empty) | ||
assert(writes.sortPlan === plan) | ||
assert(writes.writePlan != null) | ||
assert(writes.executedPlan.isInstanceOf[GlutenPlan]) | ||
val writeFilesOpt = V1WritesUtils.getWriteFilesOpt(writes.executedPlan) | ||
assert(writeFilesOpt.isDefined) | ||
val sortExec = getSort(writes.executedPlan) | ||
assert(sortExec.isEmpty) | ||
} | ||
|
||
test("don't add sort when the required ordering is already satisfied") { | ||
val df = sql("select * from t0") | ||
def check(plan: SparkPlan): Unit = { | ||
val partitionColumns = plan.output.find(_.name == "k").toSeq | ||
val writes = DeltaV1Writes(spark, plan, format, partitionColumns, None, Map.empty) | ||
assert(writes.sortPlan === plan) | ||
assert(writes.writePlan != null) | ||
assert(writes.executedPlan.isInstanceOf[GlutenPlan]) | ||
val writeFilesOpt = V1WritesUtils.getWriteFilesOpt(writes.executedPlan) | ||
assert(writeFilesOpt.isDefined) | ||
val sortExec = getSort(writes.executedPlan) | ||
assert(sortExec.isDefined) | ||
} | ||
check(df.orderBy("k").queryExecution.sparkPlan) | ||
check(df.orderBy("k", "j").queryExecution.sparkPlan) | ||
} | ||
|
||
test("add sort when the required ordering is not satisfied") { | ||
val df = sql("select * from t0") | ||
def check(plan: SparkPlan): Unit = { | ||
val partitionColumns = plan.output.find(_.name == "k").toSeq | ||
val writes = DeltaV1Writes(spark, plan, format, partitionColumns, None, Map.empty) | ||
val sort = writes.sortPlan.asInstanceOf[SortExec] | ||
assert(sort.child === plan) | ||
assert(writes.writePlan != null) | ||
assert(writes.executedPlan.isInstanceOf[GlutenPlan]) | ||
val writeFilesOpt = V1WritesUtils.getWriteFilesOpt(writes.executedPlan) | ||
assert(writeFilesOpt.isDefined) | ||
val sortExec = getSort(writes.executedPlan) | ||
assert(sortExec.isDefined, s"writes.executedPlan: ${writes.executedPlan}") | ||
} | ||
check(df.queryExecution.sparkPlan) | ||
check(df.orderBy("j", "k").queryExecution.sparkPlan) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.