rangadi commented on code in PR #38286:
URL: https://github.com/apache/spark/pull/38286#discussion_r997524177
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufCatalystDataConversionSuite.scala:
##########
@@ -99,26 +115,32 @@ class ProtobufCatalystDataConversionSuite
StructType(StructField("bytes_type", BinaryType, nullable = true) :: Nil),
StructType(StructField("string_type", StringType, nullable = true) :: Nil))
- private val catalystTypesToProtoMessages: Map[DataType, String] = Map(
- IntegerType -> "IntegerMsg",
- DoubleType -> "DoubleMsg",
- FloatType -> "FloatMsg",
- BinaryType -> "BytesMsg",
- StringType -> "StringMsg")
+ private val catalystTypesToProtoMessages: Map[DataType, (String, Any)] = Map(
+ IntegerType -> ("IntegerMsg", 0),
+ DoubleType -> ("DoubleMsg", 0.0d),
+ FloatType -> ("FloatMsg", 0.0f),
+ BinaryType -> ("BytesMsg", ByteString.empty().toByteArray),
+ StringType -> ("StringMsg", ""))
testingTypes.foreach { dt =>
val seed = 1 + scala.util.Random.nextInt((1024 - 1) + 1)
- val filePath = testFile("protobuf/catalyst_types.desc").replace("file:/",
"/")
test(s"single $dt with seed $seed") {
+
+ val (messageName, defaultValue) =
catalystTypesToProtoMessages(dt.fields(0).dataType)
+
val rand = new scala.util.Random(seed)
- val data = RandomDataGenerator.forType(dt, rand = rand).get.apply()
+ val generator = RandomDataGenerator.forType(dt, rand = rand).get
+ var data = generator()
+ while (data.asInstanceOf[Row].get(0) == defaultValue) // Do not use
default values, since
Review Comment:
Yes, `record.hasField(field)` is false when the value is default. We can
repro every time with in current master with the following change:
```
---
a/connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufCatalystDataConversionSuite.scala
+++
b/connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufCatalystDataConversionSuite.scala
@@ -106,12 +106,11 @@ class ProtobufCatalystDataConversionSuite
BinaryType -> "BytesMsg",
StringType -> "StringMsg")
- testingTypes.foreach { dt =>
+ testingTypes.take(1).foreach { dt =>
val seed = 1 + scala.util.Random.nextInt((1024 - 1) + 1)
val filePath =
testFile("protobuf/catalyst_types.desc").replace("file:/", "/")
test(s"single $dt with seed $seed") {
- val rand = new scala.util.Random(seed)
- val data = RandomDataGenerator.forType(dt, rand = rand).get.apply()
+ val data = Row.fromSeq(Seq(0))
val converter = CatalystTypeConverters.createToCatalystConverter(dt)
val input = Literal.create(converter(data), dt)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]