justaparth commented on code in PR #41108:
URL: https://github.com/apache/spark/pull/41108#discussion_r1188906519
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufFunctionsSuite.scala:
##########
@@ -1465,6 +1465,49 @@ class ProtobufFunctionsSuite extends QueryTest with
SharedSparkSession with Prot
}
}
+ test("test unsigned integer types") {
+ // The java type for uint32 and uint64 is signed integer and long
respectively.
+ // Let's check that we're converting correctly
+ val sample = spark.range(1).select(
+ lit(
+ UnsignedTypes
+ .newBuilder()
+ .setUint32Value(Integer.MIN_VALUE)
+ .setUint64Value(Long.MinValue)
+ .build()
+ .toByteArray
+ ).as("raw_proto"))
+
+ val expected = spark.range(1).select(
+ struct(
+
lit(Integer.toUnsignedLong(Integer.MIN_VALUE).longValue).as("uint32_value"),
+
lit(BigDecimal(java.lang.Long.toUnsignedString(Long.MinValue))).as("uint64_value")
+ ).as("proto")
+ )
+
+ val expectedWithLegacy = spark.range(1).select(
+ struct(
+ lit(Integer.MIN_VALUE).as("uint32_value"),
Review Comment:
using `MIN_VALUE` as its all `1`s in binary and is the largest possible
number if its "unsigned"
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufFunctionsSuite.scala:
##########
@@ -1465,6 +1465,49 @@ class ProtobufFunctionsSuite extends QueryTest with
SharedSparkSession with Prot
}
}
+ test("test unsigned integer types") {
+ // The java type for uint32 and uint64 is signed integer and long
respectively.
+ // Let's check that we're converting correctly
+ val sample = spark.range(1).select(
+ lit(
+ UnsignedTypes
+ .newBuilder()
+ .setUint32Value(Integer.MIN_VALUE)
+ .setUint64Value(Long.MinValue)
+ .build()
+ .toByteArray
+ ).as("raw_proto"))
+
+ val expected = spark.range(1).select(
+ struct(
+
lit(Integer.toUnsignedLong(Integer.MIN_VALUE).longValue).as("uint32_value"),
+
lit(BigDecimal(java.lang.Long.toUnsignedString(Long.MinValue))).as("uint64_value")
+ ).as("proto")
+ )
+
+ val expectedWithLegacy = spark.range(1).select(
+ struct(
+ lit(Integer.MIN_VALUE).as("uint32_value"),
Review Comment:
using `MIN_VALUE` as its all `1`s in binary and is the largest possible
number if its interpreted as "unsigned"
--
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]