@@ -28,13 +28,13 @@ import org.scalatest.PrivateMethodTester._
2828
2929import org .apache .logging .log4j .Level
3030import org .apache .spark .sql ._
31- import org .apache .spark .sql .catalyst .FunctionIdentifier
31+ import org .apache .spark .sql .catalyst .{ FunctionIdentifier , InternalRow }
3232import org .apache .spark .sql .catalyst .expressions .{Alias , Attribute , AttributeReference , Descending , Expression , ExpressionInfo , GreaterThan , In , InSet , KnownFloatingPointNormalized , Literal , Not , RuntimeReplaceable , SortOrder }
3333import org .apache .spark .sql .catalyst .expressions .aggregate .{AggregateExpression , BloomFilterAggregate , Final , Min , Partial , PartialMerge }
3434import org .apache .spark .sql .catalyst .expressions .objects .{Invoke , StaticInvoke }
3535import org .apache .spark .sql .catalyst .optimizer .NormalizeNaNAndZero
3636import org .apache .spark .sql .catalyst .plans .logical .{LocalRelation , LogicalPlan }
37- import org .apache .spark .sql .catalyst .plans .physical .{HashPartitioning , RoundRobinPartitioning }
37+ import org .apache .spark .sql .catalyst .plans .physical .{HashPartitioning , IdentityBroadcastMode , RoundRobinPartitioning }
3838import org .apache .spark .sql .catalyst .rules .Rule
3939import org .apache .spark .sql .comet ._
4040import org .apache .spark .sql .comet .CometExec .nativeLeaves
@@ -98,6 +98,31 @@ class CometExecRuleSuite extends CometTestBase {
9898 CometExecRule (spark).apply(stripAQEPlan(plan))
9999 }
100100
101+ test(" columnar-to-row identity broadcasts retain every build row" ) {
102+ for (direct <- Seq (false , true )) {
103+ withSQLConf(
104+ SQLConf .ADAPTIVE_EXECUTION_ENABLED .key -> " false" ,
105+ SQLConf .WHOLESTAGE_CODEGEN_ENABLED .key -> " false" ,
106+ CometConf .COMET_EXEC_RANGE_ENABLED .key -> " true" ,
107+ CometConf .COMET_DIRECT_COLUMNAR_TO_ROW_ENABLED .key -> direct.toString,
108+ CometConf .COMET_DIRECT_COLUMNAR_TO_ROW_MIN_BATCH_SIZE .key -> " 1" ) {
109+ val build = applyCometExecRule(
110+ createSparkPlan(spark, " SELECT CAST(id AS INT) AS y FROM range(2024, 2028, 1, 2)" ))
111+ assert(build.isInstanceOf [CometNativeExec ], build.treeString)
112+ val mode = IdentityBroadcastMode
113+ val original = BroadcastExchangeExec (mode, build)
114+ val exchange = CometBroadcastExchangeExec (original, build.output, mode, build)
115+ val rows = CometColumnarToRowExec (exchange)
116+ .executeBroadcast[Array [InternalRow ]]()
117+ .value
118+ // Two rows per partition expose row reuse in both JVM conversion paths.
119+ withClue(s " direct= $direct: " ) {
120+ assert(rows.map(_.getInt(0 )).sorted.toSeq == Seq (2024 , 2025 , 2026 , 2027 ))
121+ }
122+ }
123+ }
124+ }
125+
101126 /** Create a test data frame that is used in all tests */
102127 private def createTestDataFrame = {
103128 val testSchema = new StructType (
0 commit comments