You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "rangadi (via GitHub)" <gi...@apache.org> on 2023/02/19 05:14:35 UTC
[GitHub] [spark] rangadi opened a new pull request, #40080: [SPARK-42406] Fix check for missing required fields.
rangadi opened a new pull request, #40080:
URL: https://github.com/apache/spark/pull/40080
Protobuf serializer (used in `to_protobuf()`) should error if non-nullable fields (i.e. protobuf `required` fields) are present in the schema of the catalyst record being converted to a protobuf.
But `isNullable()` method used for this check returns opposite (see PR comment in the diff). As a result, Serializer incorrectly requires the fields that are optional. This PR fixes this check (see PR comment in the diff).
This also requires corresponding fix for couple of unit tests. In order use a Protobuf message with a `required` field, Protobuf version 2 file `proto2_messages.proto` is added.
Two tests are updated to verify missing required fields results in an error.
### How was this patch tested?
- Updated unit tests
--
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
[GitHub] [spark] dongjoon-hyun commented on pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1436363361
Thank you for updates, @rangadi .
cc @hvanhovell
--
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
[GitHub] [spark] gengliangwang commented on pull request #40080: [SPARK-42406][SQL] Fix check for missing required fields of to_protobuf
Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1439312954
Thanks, merging to master/3.4
--
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
[GitHub] [spark] rangadi commented on pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1436361799
@dongjoon-hyun, done. Remove 3.4 in the summary.
> @rangadi with this change, we can conclude that spark-protobuf supports proto2 and proto3 versions right?
Yes. And we always supported Proto2.
--
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
[GitHub] [spark] gengliangwang closed pull request #40080: [SPARK-42406][SQL] Fix check for missing required fields of to_protobuf
Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang closed pull request #40080: [SPARK-42406][SQL] Fix check for missing required fields of to_protobuf
URL: https://github.com/apache/spark/pull/40080
--
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
[GitHub] [spark] rangadi commented on a diff in pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on code in PR #40080:
URL: https://github.com/apache/spark/pull/40080#discussion_r1113478499
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufSerdeSuite.scala:
##########
@@ -144,44 +146,52 @@ class ProtobufSerdeSuite extends SharedSparkSession with ProtobufTestBase {
test("Fail to convert with missing Catalyst fields") {
val protoFile = ProtobufUtils.buildDescriptor(testFileDesc, "FieldMissingInSQLRoot")
- // serializing with extra fails if extra field is missing in SQL Schema
+ val foobarSQLType = DataType.fromDDL(
+ "struct<foo string>" // "bar" is missing.
Review Comment:
Could you describe a bit more?
Do we want to test not having 'foo' field which is optional?
--
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
[GitHub] [spark] rangadi commented on pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1438905661
@gengliangwang could you take a quick look and merge in to master and 3.4.
Currently, it looks like you are the only one who can merge Protobuf patches. Please suggest someone else also for next time.
--
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
[GitHub] [spark] gengliangwang commented on a diff in pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #40080:
URL: https://github.com/apache/spark/pull/40080#discussion_r1113508808
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufSerdeSuite.scala:
##########
@@ -144,44 +146,52 @@ class ProtobufSerdeSuite extends SharedSparkSession with ProtobufTestBase {
test("Fail to convert with missing Catalyst fields") {
val protoFile = ProtobufUtils.buildDescriptor(testFileDesc, "FieldMissingInSQLRoot")
- // serializing with extra fails if extra field is missing in SQL Schema
+ val foobarSQLType = DataType.fromDDL(
+ "struct<foo string>" // "bar" is missing.
Review Comment:
Yes
--
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
[GitHub] [spark] gengliangwang commented on pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1438952601
@rangadi can you update the PR description to follow the PR template?
--
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
[GitHub] [spark] rangadi commented on pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1439031344
> @rangadi can you update the PR description to follow the PR template?
@gengliangwang update the summary to follow the template. Sorry about that.
Also added a new test. PTAL.
--
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
[GitHub] [spark] rangadi commented on pull request #40080: [SPARK-42406] Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1435872911
cc: @gengliangwang, @HeartSaVioR, @SandishKumarHN
--
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
[GitHub] [spark] rangadi commented on a diff in pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on code in PR #40080:
URL: https://github.com/apache/spark/pull/40080#discussion_r1113516603
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufSerdeSuite.scala:
##########
@@ -144,44 +146,52 @@ class ProtobufSerdeSuite extends SharedSparkSession with ProtobufTestBase {
test("Fail to convert with missing Catalyst fields") {
val protoFile = ProtobufUtils.buildDescriptor(testFileDesc, "FieldMissingInSQLRoot")
- // serializing with extra fails if extra field is missing in SQL Schema
+ val foobarSQLType = DataType.fromDDL(
+ "struct<foo string>" // "bar" is missing.
Review Comment:
Added a new test at line #69. PTAL.
--
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
[GitHub] [spark] gengliangwang commented on a diff in pull request #40080: [SPARK-42406]Fix check for missing required fields.
Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #40080:
URL: https://github.com/apache/spark/pull/40080#discussion_r1113456047
##########
connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufSerdeSuite.scala:
##########
@@ -144,44 +146,52 @@ class ProtobufSerdeSuite extends SharedSparkSession with ProtobufTestBase {
test("Fail to convert with missing Catalyst fields") {
val protoFile = ProtobufUtils.buildDescriptor(testFileDesc, "FieldMissingInSQLRoot")
- // serializing with extra fails if extra field is missing in SQL Schema
+ val foobarSQLType = DataType.fromDDL(
+ "struct<foo string>" // "bar" is missing.
Review Comment:
Shall we test catalyst schema which contains `bar` only and there is a result returned?
--
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
[GitHub] [spark] rangadi commented on a diff in pull request #40080: [SPARK-42406] Fix check for missing required fields.
Posted by "rangadi (via GitHub)" <gi...@apache.org>.
rangadi commented on code in PR #40080:
URL: https://github.com/apache/spark/pull/40080#discussion_r1111162264
##########
connector/protobuf/src/test/resources/protobuf/serde_suite.proto:
##########
@@ -59,17 +59,6 @@ message TypeMiss {
int64 bar = 1;
}
-/* Field boo missing from SQL root, but available in Protobuf root*/
Review Comment:
These two are moved to `proto2_messages.proto` (and renamed)
##########
connector/protobuf/src/main/scala/org/apache/spark/sql/protobuf/utils/ProtobufUtils.scala:
##########
@@ -283,9 +283,4 @@ private[sql] object ProtobufUtils extends Logging {
case Seq() => "top-level record"
case n => s"field '${n.mkString(".")}'"
}
-
- /** Return true if `fieldDescriptor` is optional. */
- private[protobuf] def isNullable(fieldDescriptor: FieldDescriptor): Boolean =
- !fieldDescriptor.isOptional
Review Comment:
This is the bug. extra `!` returns false for `optional` field. But optional fields are nullable. This is fixed at line #103 above.
##########
connector/protobuf/src/test/resources/protobuf/proto2_messages.proto:
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
Review Comment:
Protobuf v2 file is added to test required fields.
##########
connector/protobuf/src/test/resources/protobuf/proto2_messages.desc:
##########
@@ -0,0 +1,8 @@
+
Review Comment:
This a descriptor file for `proto2_messages.proto`
--
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
[GitHub] [spark] SandishKumarHN commented on pull request #40080: [SPARK-42406] Fix check for missing required fields.
Posted by "SandishKumarHN (via GitHub)" <gi...@apache.org>.
SandishKumarHN commented on PR #40080:
URL: https://github.com/apache/spark/pull/40080#issuecomment-1435873432
@rangadi with this change, we can conclude that spark-protobuf supports proto2 and proto3 versions right?
--
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