Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import org.apache.spark.sql.sources
import org.apache.spark.sql.types.StructType
import org.apache.spark.unsafe.types.UTF8String

import com.google.protobuf.CodedOutputStream

import org.apache.comet.parquet.SourceFilterSerde.{createBinaryExpr, createNameExpr, createUnaryExpr, createValueExpr}
import org.apache.comet.serde.ExprOuterClass
import org.apache.comet.serde.QueryPlanSerde.scalarFunctionExprToProto
Expand Down Expand Up @@ -885,10 +887,12 @@ class ParquetFilters(

def createNativeFilters(predicates: Seq[sources.Filter]): Option[Array[Byte]] = {
predicates.reduceOption(sources.And).flatMap(createNativeFilter).map { expr =>
val outputStream = new ByteArrayOutputStream()
expr.writeTo(outputStream)
outputStream.close()
outputStream.toByteArray
val size = expr.getSerializedSize
val bytes = new Array[Byte](size)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size of Int type, so I think we're safe here.

val codedOutput = CodedOutputStream.newInstance(bytes)
expr.writeTo(codedOutput)
codedOutput.checkNoSpaceLeft()
bytes
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
import org.apache.spark.sql.vectorized.ColumnarBatch
import org.apache.spark.util.Utils

import com.google.protobuf.CodedOutputStream

import org.apache.comet.CometExecIterator
import org.apache.comet.serde.OperatorOuterClass.Operator

Expand Down Expand Up @@ -75,10 +77,12 @@ case class CometNativeWriteExec(
sparkContext.collectionAccumulator[FileCommitProtocol.TaskCommitMessage]("taskCommitMessages")

override def serializedPlanOpt: SerializedPlan = {
val outputStream = new ByteArrayOutputStream()
nativeOp.writeTo(outputStream)
outputStream.close()
SerializedPlan(Some(outputStream.toByteArray))
val size = nativeOp.getSerializedSize
val bytes = new Array[Byte](size)
val codedOutput = CodedOutputStream.newInstance(bytes)
nativeOp.writeTo(codedOutput)
codedOutput.checkNoSpaceLeft()
SerializedPlan(Some(bytes))
}

override def withNewChildInternal(newChild: SparkPlan): SparkPlan =
Expand Down Expand Up @@ -196,10 +200,11 @@ case class CometNativeWriteExec(

val nativeMetrics = CometMetricNode.fromCometPlan(this)

val outputStream = new ByteArrayOutputStream()
modifiedNativeOp.writeTo(outputStream)
outputStream.close()
val planBytes = outputStream.toByteArray
val size = modifiedNativeOp.getSerializedSize
val planBytes = new Array[Byte](size)
val codedOutput = CodedOutputStream.newInstance(planBytes)
modifiedNativeOp.writeTo(codedOutput)
codedOutput.checkNoSpaceLeft()

val execIterator = new CometExecIterator(
CometExec.newIterId,
Expand Down
20 changes: 12 additions & 8 deletions spark/src/main/scala/org/apache/spark/sql/comet/operators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.apache.spark.util.SerializableConfiguration
import org.apache.spark.util.io.ChunkedByteBuffer

import com.google.common.base.Objects
import com.google.protobuf.CodedOutputStream

import org.apache.comet.{CometConf, CometExecIterator, CometRuntimeException, ConfigEntry}
import org.apache.comet.CometSparkSessionExtensions.{isCometShuffleEnabled, withInfo}
Expand Down Expand Up @@ -139,10 +140,11 @@ object CometExec {
partitionIdx: Int,
broadcastedHadoopConfForEncryption: Option[Broadcast[SerializableConfiguration]],
encryptedFilePaths: Seq[String]): CometExecIterator = {
val outputStream = new ByteArrayOutputStream()
nativePlan.writeTo(outputStream)
outputStream.close()
val bytes = outputStream.toByteArray
val size = nativePlan.getSerializedSize
val bytes = new Array[Byte](size)
val codedOutput = CodedOutputStream.newInstance(bytes)
nativePlan.writeTo(codedOutput)
codedOutput.checkNoSpaceLeft()
new CometExecIterator(
newIterId,
inputs,
Expand Down Expand Up @@ -414,10 +416,12 @@ abstract class CometNativeExec extends CometExec {
def convertBlock(): CometNativeExec = {
def transform(arg: Any): AnyRef = arg match {
case serializedPlan: SerializedPlan if serializedPlan.isEmpty =>
val out = new ByteArrayOutputStream()
nativeOp.writeTo(out)
out.close()
SerializedPlan(Some(out.toByteArray))
val size = nativeOp.getSerializedSize
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) We could extract some of the shared code to a utility method but not urgent.

val bytes = new Array[Byte](size)
val codedOutput = CodedOutputStream.newInstance(bytes)
nativeOp.writeTo(codedOutput)
codedOutput.checkNoSpaceLeft()
SerializedPlan(Some(bytes))
case other: AnyRef => other
case null => null
}
Expand Down
Loading