-
Notifications
You must be signed in to change notification settings - Fork 464
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
[GLUTEN-4170][VL] Decouple partitions from plan to avoid driver stalled #4177
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
48b9c05
fix
Yohahaha 3ee1e75
fix comments and build.
Yohahaha 2346f23
rebase and fix
Yohahaha a031781
rebase and fix
Yohahaha 626d149
fix compile and ut.
Yohahaha c091242
fix compile and ut.
Yohahaha f1e6db9
fix ut
Yohahaha 95c301b
fix comments
Yohahaha ebac5aa
fix comments
Yohahaha c899630
fix comments
Yohahaha 9e56777
fix format
Yohahaha 4894e7e
update docs
Yohahaha 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import io.glutenproject.backendsapi.IteratorApi | |
import io.glutenproject.execution._ | ||
import io.glutenproject.metrics.IMetrics | ||
import io.glutenproject.substrait.plan.PlanNode | ||
import io.glutenproject.substrait.rel.{LocalFilesBuilder, SplitInfo} | ||
import io.glutenproject.substrait.rel.{LocalFilesBuilder, LocalFilesNode, SplitInfo} | ||
import io.glutenproject.substrait.rel.LocalFilesNode.ReadFileFormat | ||
import io.glutenproject.utils.Iterators | ||
import io.glutenproject.vectorized._ | ||
|
@@ -47,16 +47,12 @@ import java.net.URLDecoder | |
import java.nio.charset.StandardCharsets | ||
import java.time.ZoneOffset | ||
import java.util.{ArrayList => JArrayList, HashMap => JHashMap, Map => JMap} | ||
import java.util.concurrent.TimeUnit | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
class IteratorApiImpl extends IteratorApi with Logging { | ||
|
||
/** | ||
* Generate native row partition. | ||
* | ||
* @return | ||
*/ | ||
override def genSplitInfo( | ||
partition: InputPartition, | ||
partitionSchema: StructType, | ||
|
@@ -80,6 +76,24 @@ class IteratorApiImpl extends IteratorApi with Logging { | |
} | ||
} | ||
|
||
/** Generate native row partition. */ | ||
override def genPartitions( | ||
wsCtx: WholeStageTransformContext, | ||
splitInfos: Seq[Seq[SplitInfo]]): Seq[BaseGlutenPartition] = { | ||
// Only serialize plan once, save lots time when plan is complex. | ||
val planByteArray = wsCtx.root.toProtobuf.toByteArray | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the plan binary size is big enough, e.g, bigger than |
||
|
||
splitInfos.zipWithIndex.map { | ||
case (splitInfos, index) => | ||
GlutenPartition( | ||
index, | ||
planByteArray, | ||
splitInfos.map(_.asInstanceOf[LocalFilesNode].toProtobuf.toByteArray).toArray, | ||
Yohahaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
splitInfos.flatMap(_.preferredLocations().asScala).toArray | ||
) | ||
} | ||
} | ||
|
||
private def constructSplitInfo(schema: StructType, files: Array[PartitionedFile]) = { | ||
val paths = new JArrayList[String]() | ||
val starts = new JArrayList[JLong] | ||
|
@@ -121,25 +135,34 @@ class IteratorApiImpl extends IteratorApi with Logging { | |
transKernel.injectWriteFilesTempPath(path) | ||
} | ||
|
||
/** | ||
* Generate Iterator[ColumnarBatch] for first stage. | ||
* | ||
* @return | ||
*/ | ||
/** Generate Iterator[ColumnarBatch] for first stage. */ | ||
override def genFirstStageIterator( | ||
inputPartition: BaseGlutenPartition, | ||
context: TaskContext, | ||
pipelineTime: SQLMetric, | ||
updateInputMetrics: (InputMetricsWrapper) => Unit, | ||
updateNativeMetrics: IMetrics => Unit, | ||
inputIterators: Seq[Iterator[ColumnarBatch]] = Seq()): Iterator[ColumnarBatch] = { | ||
assert( | ||
inputPartition.isInstanceOf[GlutenPartition], | ||
"Velox backend only accept GlutenPartition.") | ||
|
||
val beforeBuild = System.nanoTime() | ||
val columnarNativeIterators = | ||
new JArrayList[GeneralInIterator](inputIterators.map { | ||
iter => new ColumnarBatchInIterator(iter.asJava) | ||
}.asJava) | ||
val transKernel = NativePlanEvaluator.create() | ||
|
||
val splitInfoByteArray = inputPartition | ||
.asInstanceOf[GlutenPartition] | ||
.splitInfosByteArray | ||
val resIter: GeneralOutIterator = | ||
transKernel.createKernelWithBatchIterator(inputPartition.plan, columnarNativeIterators) | ||
transKernel.createKernelWithBatchIterator( | ||
inputPartition.plan, | ||
splitInfoByteArray, | ||
columnarNativeIterators) | ||
pipelineTime += TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - beforeBuild) | ||
|
||
Iterators | ||
.wrap(resIter.asScala) | ||
|
@@ -157,11 +180,7 @@ class IteratorApiImpl extends IteratorApi with Logging { | |
|
||
// scalastyle:off argcount | ||
|
||
/** | ||
* Generate Iterator[ColumnarBatch] for final stage. | ||
* | ||
* @return | ||
*/ | ||
/** Generate Iterator[ColumnarBatch] for final stage. */ | ||
override def genFinalStageIterator( | ||
context: TaskContext, | ||
inputIterators: Seq[Iterator[ColumnarBatch]], | ||
|
@@ -183,7 +202,10 @@ class IteratorApiImpl extends IteratorApi with Logging { | |
val nativeResultIterator = | ||
transKernel.createKernelWithBatchIterator( | ||
rootNode.toProtobuf.toByteArray, | ||
columnarNativeIterator) | ||
// Final iterator does not contain scan split, so pass empty split info to native here. | ||
new Array[Array[Byte]](0), | ||
Yohahaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
columnarNativeIterator | ||
) | ||
|
||
Iterators | ||
.wrap(nativeResultIterator.asScala) | ||
|
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
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.
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.
I'm assuming the proposed optimization can also be applied for CH backend. If so, it will need some follow-up work from CH engineer. @baibaichen