Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,38 @@ private[sql] object SparkSqlSerializer2 {

/**
* Check if rows with the given schema can be serialized with ShuffleSerializer.
* Right now, we do not support a schema having complex types or UDTs, or all data types
* of fields are NullTypes.
*/
def support(schema: Array[DataType]): Boolean = {
if (schema == null) return true

var allNullTypes = true
var i = 0
while (i < schema.length) {
schema(i) match {
case udt: UserDefinedType[_] => return false
case array: ArrayType => return false
case map: MapType => return false
case struct: StructType => return false
case NullType => // Do nothing
case udt: UserDefinedType[_] =>
allNullTypes = false
return false
case array: ArrayType =>
allNullTypes = false
return false
case map: MapType =>
allNullTypes = false
return false
case struct: StructType =>
allNullTypes = false
return false
case _ =>
allNullTypes = false
}
i += 1
}

return true
// If types of fields are all NullTypes, we return false.
// Otherwise, we return true.
return !allNullTypes
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class SparkSqlSerializer2DataTypeSuite extends SparkFunSuite {
}

checkSupported(null, isSupported = true)
checkSupported(NullType, isSupported = true)
checkSupported(BooleanType, isSupported = true)
checkSupported(ByteType, isSupported = true)
checkSupported(ShortType, isSupported = true)
Expand All @@ -57,6 +56,8 @@ class SparkSqlSerializer2DataTypeSuite extends SparkFunSuite {
checkSupported(DecimalType(10, 5), isSupported = true)
checkSupported(DecimalType.Unlimited, isSupported = true)

// If NullType is the only data type in the schema, we do not support it.
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, do we need a test to check that schemas that contain a NullType column and a column of some other supported type are supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, we have that test. The table shuffle used in SparkSqlSerializer2Suite contains all supported types and NullType.

checkSupported(NullType, isSupported = false)
// For now, ArrayType, MapType, and StructType are not supported.
checkSupported(ArrayType(DoubleType, true), isSupported = false)
checkSupported(ArrayType(StringType, false), isSupported = false)
Expand Down Expand Up @@ -170,6 +171,23 @@ abstract class SparkSqlSerializer2Suite extends QueryTest with BeforeAndAfterAll
val df = ctx.sql(s"SELECT 1 + 1 FROM shuffle")
checkSerializer(df.queryExecution.executedPlan, classOf[SparkSqlSerializer])
}

test("types of fields are all NullTypes") {
// Test range partitioning code path.
val nulls = ctx.sql(s"SELECT null as a, null as b, null as c")
val df = nulls.unionAll(nulls).sort("a")
checkSerializer(df.queryExecution.executedPlan, classOf[SparkSqlSerializer])
checkAnswer(
df,
Row(null, null, null) :: Row(null, null, null) :: Nil)

// Test hash partitioning code path.
val oneRow = ctx.sql(s"SELECT DISTINCT null, null, null FROM shuffle")
checkSerializer(oneRow.queryExecution.executedPlan, classOf[SparkSqlSerializer])
checkAnswer(
oneRow,
Row(null, null, null))
}
}

/** Tests SparkSqlSerializer2 with sort based shuffle without sort merge. */
Expand Down