Skip to content
Open
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
8 changes: 7 additions & 1 deletion native/shuffle/src/spark_unsafe/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use arrow::array::{
builder::{
ArrayBuilder, BinaryBuilder, BooleanBuilder, Date32Builder, Decimal128Builder,
Float32Builder, Float64Builder, Int16Builder, Int32Builder, Int64Builder, Int8Builder,
ListBuilder, StringBuilder, StructBuilder, TimestampMicrosecondBuilder,
ListBuilder, NullBuilder, StringBuilder, StructBuilder, TimestampMicrosecondBuilder,
},
MapBuilder,
};
Expand Down Expand Up @@ -393,6 +393,12 @@ pub fn append_to_builder<const NULLABLE: bool>(
let builder = downcast_builder_ref!(Date32Builder, builder);
array.append_dates_to_builder::<NULLABLE>(builder);
}
DataType::Null => {
let builder = downcast_builder_ref!(NullBuilder, builder);
for _ in 0..array.get_num_elements() {
builder.append_null();
}
}
DataType::Binary => {
add_values!(
BinaryBuilder,
Expand Down
15 changes: 13 additions & 2 deletions native/shuffle/src/spark_unsafe/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use arrow::array::{
builder::{
ArrayBuilder, BinaryBuilder, BinaryDictionaryBuilder, BooleanBuilder, Date32Builder,
Decimal128Builder, Float32Builder, Float64Builder, Int16Builder, Int32Builder,
Int64Builder, Int8Builder, ListBuilder, MapBuilder, StringBuilder, StringDictionaryBuilder,
StructBuilder, TimestampMicrosecondBuilder,
Int64Builder, Int8Builder, ListBuilder, MapBuilder, NullBuilder, StringBuilder,
StringDictionaryBuilder, StructBuilder, TimestampMicrosecondBuilder,
},
types::Int32Type,
Array, ArrayRef, RecordBatch, RecordBatchOptions,
Expand Down Expand Up @@ -267,6 +267,10 @@ pub(super) fn append_field(
append_field_to_builder!(Date32Builder, |builder: &mut Date32Builder| builder
.append_value(row.get_date(idx)));
}
DataType::Null => {
let field_builder = get_field_builder!(struct_builder, NullBuilder, idx);
field_builder.append_null();
}
DataType::Timestamp(TimeUnit::Microsecond, _) => {
append_field_to_builder!(
TimestampMicrosecondBuilder,
Expand Down Expand Up @@ -1148,6 +1152,12 @@ fn append_columns(
.append_value(row.get_date(idx))
);
}
DataType::Null => {
let null_builder = downcast_builder_ref!(NullBuilder, builder);
for _ in row_start..row_end {
null_builder.append_null();
}
}
DataType::Timestamp(TimeUnit::Microsecond, _) => {
append_column_to_builder!(
TimestampMicrosecondBuilder,
Expand Down Expand Up @@ -1252,6 +1262,7 @@ fn make_builders(
}
}
DataType::Date32 => Box::new(Date32Builder::with_capacity(row_num)),
DataType::Null => Box::new(NullBuilder::new()),
DataType::Timestamp(TimeUnit::Microsecond, _) => {
Box::new(TimestampMicrosecondBuilder::with_capacity(row_num).with_data_type(dt.clone()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.apache.spark.sql.execution.adaptive.ShuffleQueryStageExec
import org.apache.spark.sql.execution.exchange.{ENSURE_REQUIREMENTS, ShuffleExchangeExec, ShuffleExchangeLike, ShuffleOrigin}
import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics, SQLShuffleReadMetricsReporter, SQLShuffleWriteMetricsReporter}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{ArrayType, BinaryType, BooleanType, ByteType, DataType, DateType, DecimalType, DoubleType, FloatType, IntegerType, LongType, MapType, ShortType, StringType, StructType, TimestampNTZType, TimestampType}
import org.apache.spark.sql.types.{ArrayType, BinaryType, BooleanType, ByteType, DataType, DateType, DecimalType, DoubleType, FloatType, IntegerType, LongType, MapType, NullType, ShortType, StringType, StructType, TimestampNTZType, TimestampType}
import org.apache.spark.sql.vectorized.ColumnarBatch
import org.apache.spark.util.MutablePair
import org.apache.spark.util.collection.unsafe.sort.{PrefixComparators, RecordComparator}
Expand Down Expand Up @@ -364,7 +364,7 @@ object CometShuffleExchangeExec
def supportedSerializableDataType(dt: DataType): Boolean = dt match {
case _: BooleanType | _: ByteType | _: ShortType | _: IntegerType | _: LongType |
_: FloatType | _: DoubleType | _: StringType | _: BinaryType | _: TimestampType |
_: TimestampNTZType | _: DecimalType | _: DateType =>
_: TimestampNTZType | _: DecimalType | _: DateType | _: NullType =>
true
case StructType(fields) =>
fields.nonEmpty && fields.forall(f => supportedSerializableDataType(f.dataType))
Expand Down Expand Up @@ -487,7 +487,7 @@ object CometShuffleExchangeExec
def supportedSerializableDataType(dt: DataType): Boolean = dt match {
case _: BooleanType | _: ByteType | _: ShortType | _: IntegerType | _: LongType |
_: FloatType | _: DoubleType | _: StringType | _: BinaryType | _: TimestampType |
_: TimestampNTZType | _: DecimalType | _: DateType =>
_: TimestampNTZType | _: DecimalType | _: DateType | _: NullType =>
true
case StructType(fields) =>
fields.nonEmpty && fields.forall(f => supportedSerializableDataType(f.dataType)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ object Utils extends CometTypeShim with Logging {
}
case TimestampNTZType =>
new ArrowType.Timestamp(TimeUnit.MICROSECOND, null)
case NullType => ArrowType.Null.INSTANCE
case dt if isTimeType(dt) =>
new ArrowType.Time(TimeUnit.NANOSECOND, 64)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ package org.apache.comet.exec
import java.nio.file.{Files, Paths}

import scala.reflect.runtime.universe._
import scala.util.Random

import org.scalactic.source.Position
import org.scalatest.Tag

import org.apache.hadoop.fs.Path
import org.apache.spark.{Partitioner, SparkConf}
import org.apache.spark.sql.{CometTestBase, DataFrame, RandomDataGenerator, Row}
import org.apache.spark.sql.{CometTestBase, DataFrame, Row}
import org.apache.spark.sql.comet.execution.shuffle.{CometShuffleDependency, CometShuffleExchangeExec, CometShuffleManager}
import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanHelper, AQEShuffleReadExec, ShuffleQueryStageExec}
import org.apache.spark.sql.execution.exchange.ReusedExchangeExec
Expand Down Expand Up @@ -94,22 +93,16 @@ abstract class CometColumnarShuffleSuite extends CometTestBase with AdaptiveSpar
""".stripMargin))
}

test("Fallback to Spark for unsupported input besides ordering") {
val dataGenerator = RandomDataGenerator
.forType(
dataType = NullType,
nullable = true,
new Random(System.nanoTime()),
validJulianDatetime = false)
.get

val schema = new StructType()
.add("index", IntegerType, nullable = false)
.add("col", NullType, nullable = true)
val rdd =
spark.sparkContext.parallelize((1 to 20).map(i => Row(i, dataGenerator())))
val df = spark.createDataFrame(rdd, schema).orderBy("index").coalesce(1)
checkSparkAnswer(df)
test("columnar shuffle with NullType passthrough column") {
val df = sql("SELECT x, y FROM VALUES ('a', null), ('b', null), ('c', null) AS t(x, y)")
val shuffled = df.repartition(2, $"x")
checkShuffleAnswer(shuffled, 1)
}

test("columnar shuffle with Map[_, NullType] column") {
val df = sql("SELECT id, map(id, null) AS m FROM VALUES (1), (2), (3) AS t(id)")
val shuffled = df.repartition(2, $"id")
checkShuffleAnswer(shuffled, 1)
}

test("columnar shuffle on nested struct including nulls") {
Expand Down
15 changes: 15 additions & 0 deletions spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3925,6 +3925,21 @@ class CometExecSuite extends CometTestBase {
}
}

test("CometLocalTableScanExec handles NullType column") {
withSQLConf(CometConf.COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED.key -> "true") {
val df = spark.sql("SELECT * FROM VALUES ('a', null), ('b', null) AS t(x, y)")
checkSparkAnswerAndOperator(df)
}
}

test("CometLocalTableScanExec handles NullType nested in struct/array/map") {
withSQLConf(CometConf.COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED.key -> "true") {
checkSparkAnswerAndOperator(
spark.sql("SELECT named_struct('a', 1, 'b', null) AS s, array(null, null) AS a, " +
"map('k', null) AS m FROM VALUES (1), (2) AS t(id)"))
}
}

test("Native_datafusion reports correct files and bytes scanned") {
val inputFiles = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ class CometNativeShuffleSuite extends CometTestBase with AdaptiveSparkPlanHelper
}
}

test("native shuffle with NullType passthrough column") {
withSQLConf(CometConf.COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED.key -> "true") {
val df =
spark.sql("SELECT x, y FROM VALUES ('a', null), ('b', null), ('c', null) AS t(x, y)")
val shuffled = df.repartition(2, $"x")
checkShuffleAnswer(shuffled, 1)
}
}

test("native shuffle with Map[_, NullType] column") {
withSQLConf(CometConf.COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED.key -> "true") {
val df = spark.sql("SELECT id, map(id, null) AS m FROM VALUES (1), (2), (3) AS t(id)")
val shuffled = df.repartition(2, $"id")
println(shuffled.queryExecution.executedPlan)
checkShuffleAnswer(shuffled, 1)
}
}

test("fix: Comet native shuffle with binary data") {
withParquetTable((0 until 5).map(i => (i, (i + 1).toLong)), "tbl") {
val df = sql("SELECT cast(cast(_1 as STRING) as BINARY) as binary, _2 FROM tbl")
Expand Down
Loading