You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "justaparth (via GitHub)" <gi...@apache.org> on 2023/05/09 17:15:23 UTC

[GitHub] [spark] justaparth commented on a diff in pull request #41108: [SPARK-43427] spark protobuf: modify deserialization behavior of unsigned integer types

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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org