Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 3 additions & 7 deletions spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -855,14 +855,10 @@ object QueryPlanSerde extends Logging with CometExprShim with CometTypeShim {
}

private def liftCoverageTags(from: Expression, to: Expression): Unit = {
val native = mutable.Set.empty[String]
val dispatched = mutable.Set.empty[String]
from.foreach { e =>
e.getTagValue(CometExplainInfo.NATIVE_EXPRS).foreach(native ++= _)
e.getTagValue(CometExplainInfo.CODEGEN_DISPATCH_EXPRS).foreach(dispatched ++= _)
val exprs = from.collect { case e: Expression => e }
Seq(CometExplainInfo.NATIVE_EXPRS, CometExplainInfo.CODEGEN_DISPATCH_EXPRS).foreach { tag =>
appendTagValues(to, tag, CometExplainInfo.collectExprTagValues(exprs, tag))
}
appendTagValues(to, CometExplainInfo.NATIVE_EXPRS, native.toSet)
appendTagValues(to, CometExplainInfo.CODEGEN_DISPATCH_EXPRS, dispatched.toSet)
}

/**
Expand Down
18 changes: 17 additions & 1 deletion spark/src/test/scala/org/apache/comet/CometCodegenSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.apache.arrow.vector._
import org.apache.spark.{SparkConf, SparkEnv, TaskContext}
import org.apache.spark.sql.CometTestBase
import org.apache.spark.sql.api.java.UDF1
import org.apache.spark.sql.catalyst.expressions.{BoundReference, CreateArray, CreateMap, CreateNamedStruct, Expression, Literal, MapConcat}
import org.apache.spark.sql.catalyst.expressions.{Add, Alias, AttributeReference, BoundReference, CreateArray, CreateMap, CreateNamedStruct, Expression, Literal, MapConcat}
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
Expand All @@ -34,6 +34,7 @@ import org.apache.spark.unsafe.types.UTF8String
import org.apache.comet.CometSparkSessionExtensions.isSpark41Plus
import org.apache.comet.codegen.CometBatchKernelCodegen
import org.apache.comet.codegen.CometBatchKernelCodegen.ArrowColumnSpec
import org.apache.comet.serde.QueryPlanSerde
import org.apache.comet.udf.codegen.CometScalaUDFCodegen
import org.apache.comet.vector.CometVector

Expand Down Expand Up @@ -278,7 +279,20 @@ class CometCodegenSuite
val planted = Literal.TrueLiteral
planted.setTagValue(CometExplainInfo.EXTENSION_INFO, Set("PLANTED_INFO"))
planted.setTagValue(CometExplainInfo.NATIVE_EXPRS, Set("plantedexpr"))
planted.setTagValue(CometExplainInfo.CODEGEN_DISPATCH_EXPRS, Set("planteddispatch"))
try {
// Decimal promotion rebuilds this projection. Its coverage lift must not copy the
// singleton's stale tags onto the Alias, which is a legitimate coverage owner.
val decimal = AttributeReference("amount", DecimalType(10, 2), nullable = false)()
val projection = Alias(
CreateNamedStruct(Seq(Literal("flag"), planted, Literal("sum"), Add(decimal, decimal))),
"value")()
assert(QueryPlanSerde.exprToProto(projection, Seq(decimal)).isDefined)
val native = projection.getTagValue(CometExplainInfo.NATIVE_EXPRS).getOrElse(Set.empty)
assert(native.contains("checkoverflow"), s"expected lifted decimal coverage, got: $native")
assert(!native.contains("plantedexpr"))
assert(projection.getTagValue(CometExplainInfo.CODEGEN_DISPATCH_EXPRS).isEmpty)

withSQLConf(
CometConf.COMET_EXTENDED_EXPLAIN_FORMAT.key ->
CometConf.COMET_EXTENDED_EXPLAIN_FORMAT_VERBOSE,
Expand All @@ -301,13 +315,15 @@ class CometCodegenSuite

val info = new ExtendedExplainInfo()
assert(!info.getNativeExpressions(plan).contains("plantedexpr"))
assert(!info.getCodegenDispatchExpressions(plan).contains("planteddispatch"))
val explain = info.generateExtendedInfo(plan)
assert(!explain.contains("PLANTED_INFO"), s"tag leaked into:\n$explain")
}
}
} finally {
planted.unsetTagValue(CometExplainInfo.EXTENSION_INFO)
planted.unsetTagValue(CometExplainInfo.NATIVE_EXPRS)
planted.unsetTagValue(CometExplainInfo.CODEGEN_DISPATCH_EXPRS)
}
}

Expand Down
Loading