-
Notifications
You must be signed in to change notification settings - Fork 249
fix: Mark WindowExec as incompatible [WIP]
#2736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 30 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
6ee6def
filter
andygrove 3a80a1f
limit
andygrove 51e0aa2
hash join
andygrove 8c0338e
sort merge join
andygrove e30e776
save
andygrove d8934db
window exec
andygrove ac30640
agg
andygrove b515d8f
docs
andygrove fcab57e
refactor
andygrove 4cde286
refactor
andygrove 8afadf7
fix
andygrove ae2254e
scalastyle
andygrove 3dbb10d
remove map approach
andygrove 30360ab
scalastyle
andygrove a6e9023
revert config
andygrove c719eeb
revert docs
andygrove 812dd7f
revert a change
andygrove 0343323
refactor sink serde
andygrove 7aeea75
refactor
andygrove e811e7a
fix
andygrove 7c59a0c
map lookup
andygrove 83cc2c3
more refactoring
andygrove 5131395
more refactoring
andygrove 82da68f
comments
andygrove 54e9d17
fix
andygrove 266ff4d
fix
andygrove ff2b9ad
docs
andygrove 4acc0d8
upmerge
andygrove ba2ca5a
docs
andygrove 9140742
docs
andygrove 7216f3c
improve withInfo
andygrove 1a4807b
add operator incompat handling
andygrove 865274f
update 3.5 golden files
andygrove 74ee98e
3.4 golden files
andygrove 468ea56
4.0 golden files
andygrove 26d2480
update expected fallback reason in test
andygrove c997b95
hacky fix
andygrove 50b62b8
less hacky fix
andygrove de2c6fd
refine
andygrove 6183663
remove println
andygrove 3a59359
fix
andygrove 12ff805
scalastyle
andygrove fd4385a
update 4.0 golden files
andygrove 839f6c7
update 4.0 golden files
andygrove 5f1fbf4
update 3.5 golden files
andygrove 04899f2
update 3.4 golden files
andygrove File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
134 changes: 134 additions & 0 deletions
134
spark/src/main/scala/org/apache/comet/serde/CometSink.scala
This file contains hidden or 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,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.comet.serde | ||
|
|
||
| import scala.jdk.CollectionConverters._ | ||
|
|
||
| import org.apache.spark.sql.comet.{CometBroadcastExchangeExec, CometScanExec, CometSinkPlaceHolder, CometSparkToColumnarExec} | ||
| import org.apache.spark.sql.comet.execution.shuffle.CometShuffleExchangeExec | ||
| import org.apache.spark.sql.execution.{CoalesceExec, CollectLimitExec, SparkPlan, TakeOrderedAndProjectExec, UnionExec} | ||
| import org.apache.spark.sql.execution.adaptive.{BroadcastQueryStageExec, ShuffleQueryStageExec} | ||
| import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, ReusedExchangeExec, ShuffleExchangeExec} | ||
|
|
||
| import org.apache.comet.{CometConf, ConfigEntry} | ||
| import org.apache.comet.CometSparkSessionExtensions.{isCometScan, withInfo} | ||
| import org.apache.comet.serde.OperatorOuterClass.Operator | ||
| import org.apache.comet.serde.QueryPlanSerde.{serializeDataType, supportedDataType} | ||
|
|
||
| object CometSink extends CometOperatorSerde[SparkPlan] { | ||
|
|
||
| override def enabledConfig: Option[ConfigEntry[Boolean]] = None | ||
|
|
||
| override def convert( | ||
| op: SparkPlan, | ||
| builder: Operator.Builder, | ||
| childOp: OperatorOuterClass.Operator*): Option[OperatorOuterClass.Operator] = { | ||
| val supportedTypes = | ||
| op.output.forall(a => supportedDataType(a.dataType, allowComplex = true)) | ||
|
|
||
| if (!supportedTypes) { | ||
| withInfo(op, "Unsupported data type") | ||
| return None | ||
| } | ||
|
|
||
| // These operators are source of Comet native execution chain | ||
| val scanBuilder = OperatorOuterClass.Scan.newBuilder() | ||
| val source = op.simpleStringWithNodeId() | ||
| if (source.isEmpty) { | ||
| scanBuilder.setSource(op.getClass.getSimpleName) | ||
| } else { | ||
| scanBuilder.setSource(source) | ||
| } | ||
|
|
||
| val ffiSafe = op match { | ||
| case _ if isExchangeSink(op) => | ||
| // Source of broadcast exchange batches is ArrowStreamReader | ||
| // Source of shuffle exchange batches is NativeBatchDecoderIterator | ||
| true | ||
| case scan: CometScanExec if scan.scanImpl == CometConf.SCAN_NATIVE_COMET => | ||
| // native_comet scan reuses mutable buffers | ||
| false | ||
| case scan: CometScanExec if scan.scanImpl == CometConf.SCAN_NATIVE_ICEBERG_COMPAT => | ||
| // native_iceberg_compat scan reuses mutable buffers for constant columns | ||
| // https://github.com/apache/datafusion-comet/issues/2152 | ||
| false | ||
| case _ => | ||
| false | ||
| } | ||
| scanBuilder.setArrowFfiSafe(ffiSafe) | ||
|
|
||
| val scanTypes = op.output.flatten { attr => | ||
| serializeDataType(attr.dataType) | ||
| } | ||
|
|
||
| if (scanTypes.length == op.output.length) { | ||
| scanBuilder.addAllFields(scanTypes.asJava) | ||
|
|
||
| // Sink operators don't have children | ||
| builder.clearChildren() | ||
|
|
||
| Some(builder.setScan(scanBuilder).build()) | ||
| } else { | ||
| // There are unsupported scan type | ||
| withInfo( | ||
| op, | ||
| s"unsupported Comet operator: ${op.nodeName}, due to unsupported data types above") | ||
| None | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Whether the input Spark operator `op` can be considered as a Comet sink, i.e., the start of | ||
| * native execution. If it is true, we'll wrap `op` with `CometScanWrapper` or | ||
| * `CometSinkPlaceHolder` later in `CometSparkSessionExtensions` after `operator2proto` is | ||
| * called. | ||
| */ | ||
| def isCometSink(op: SparkPlan): Boolean = { | ||
| if (isExchangeSink(op)) { | ||
| return true | ||
| } | ||
| op match { | ||
| case s if isCometScan(s) => true | ||
| case _: CometSparkToColumnarExec => true | ||
| case _: CometSinkPlaceHolder => true | ||
| case _: CoalesceExec => true | ||
| case _: CollectLimitExec => true | ||
| case _: UnionExec => true | ||
| case _: TakeOrderedAndProjectExec => true | ||
| // https://github.com/apache/datafusion-comet/issues/2737 | ||
| // case _: WindowExec => true | ||
| case _ => false | ||
| } | ||
| } | ||
|
|
||
| private def isExchangeSink(op: SparkPlan): Boolean = { | ||
| op match { | ||
| case _: ShuffleExchangeExec => true | ||
| case ShuffleQueryStageExec(_, _: CometShuffleExchangeExec, _) => true | ||
| case ShuffleQueryStageExec(_, ReusedExchangeExec(_, _: CometShuffleExchangeExec), _) => true | ||
| case BroadcastQueryStageExec(_, _: CometBroadcastExchangeExec, _) => true | ||
| case BroadcastQueryStageExec(_, ReusedExchangeExec(_, _: CometBroadcastExchangeExec), _) => | ||
| true | ||
| case _: BroadcastExchangeExec => true | ||
| case _ => false | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for #2737