rangadi commented on code in PR #38344: URL: https://github.com/apache/spark/pull/38344#discussion_r1003729392
########## connector/protobuf/src/main/scala/org/apache/spark/sql/protobuf/utils/ProtobufUtils.scala: ########## @@ -196,27 +194,31 @@ private[sql] object ProtobufUtils extends Logging { fileDescriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(dscFile) } catch { case ex: InvalidProtocolBufferException => - // TODO move all the exceptions to core/src/main/resources/error/error-classes.json - throw new RuntimeException("Error parsing descriptor byte[] into Descriptor object", ex) + throw QueryCompilationErrors.descrioptorParseError(ex) case ex: IOException => - throw new RuntimeException( - "Error reading Protobuf descriptor file at path: " + - descFilePath, - ex) + throw QueryCompilationErrors.cannotFindDescriptorFileError(descFilePath, ex) } - val descriptorProto: DescriptorProtos.FileDescriptorProto = fileDescriptorSet.getFile(0) + val descriptorProto: DescriptorProtos.FileDescriptorProto = Review Comment: could you some brief comments here? Is the last file the right file? ########## connector/protobuf/src/main/scala/org/apache/spark/sql/protobuf/utils/ProtobufUtils.scala: ########## @@ -196,27 +194,31 @@ private[sql] object ProtobufUtils extends Logging { fileDescriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(dscFile) } catch { case ex: InvalidProtocolBufferException => - // TODO move all the exceptions to core/src/main/resources/error/error-classes.json - throw new RuntimeException("Error parsing descriptor byte[] into Descriptor object", ex) + throw QueryCompilationErrors.descrioptorParseError(ex) case ex: IOException => - throw new RuntimeException( - "Error reading Protobuf descriptor file at path: " + - descFilePath, - ex) + throw QueryCompilationErrors.cannotFindDescriptorFileError(descFilePath, ex) } - val descriptorProto: DescriptorProtos.FileDescriptorProto = fileDescriptorSet.getFile(0) + val descriptorProto: DescriptorProtos.FileDescriptorProto = + fileDescriptorSet.getFileList.asScala.last + + var fileDescriptorList = List[Descriptors.FileDescriptor]() Review Comment: Is this the import file list? What happens when the imported file imports other files? i.e. A imports B and B imports C. ########## connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufSerdeSuite.scala: ########## @@ -163,18 +163,22 @@ class ProtobufSerdeSuite extends SharedSparkSession { fieldMatchType: MatchType, expectedCauseMessage: String, catalystSchema: StructType = CATALYST_STRUCT): Unit = { - val e = intercept[IncompatibleSchemaException] { + val e = intercept[Exception] { serdeFactory.create(catalystSchema, protoSchema, fieldMatchType) } val expectMsg = serdeFactory match { case Deserializer => - s"Cannot convert Protobuf type ${protoSchema.getName} to SQL type ${catalystSchema.sql}." + s"[PROTOBUF_TYPE_TO_CATALYST_TYPE_ERROR] Unable to convert" + + s" ${protoSchema.getName} of Protobuf to SQL type ${toSQLType(catalystSchema)}." case Serializer => - s"Cannot convert SQL type ${catalystSchema.sql} to Protobuf type ${protoSchema.getName}." + s"[UNABLE_TO_CONVERT_TO_PROTOBUF_TYPE] Unable to convert SQL type" + + s" ${toSQLType(catalystSchema)} to Protobuf type ${protoSchema.getName}." } assert(e.getMessage === expectMsg) - assert(e.getCause.getMessage === expectedCauseMessage) + if (e.getCause != null) { + assert(e.getCause.getMessage === expectedCauseMessage) Review Comment: What does it mean if `e.getCause` is null and `expectedCauseMessage` is not? ########## connector/protobuf/src/main/scala/org/apache/spark/sql/protobuf/utils/SchemaConverters.scala: ########## @@ -62,14 +63,18 @@ object SchemaConverters { case STRING => Some(StringType) case BYTE_STRING => Some(BinaryType) case ENUM => Some(StringType) - case MESSAGE if fd.getMessageType.getName == "Duration" => + case MESSAGE + if fd.getMessageType.getName == "Duration" && + fd.getMessageType.getFields.size() == 2 && + fd.getMessageType.getFields.get(0).getName.equals("seconds") && + fd.getMessageType.getFields.get(1).getName.equals("nanos") => Some(DayTimeIntervalType.defaultConcreteType) - case MESSAGE if fd.getMessageType.getName == "Timestamp" => - Some(TimestampType) - // FIXME: Is the above accurate? Users can have protos named "Timestamp" but are not - // expected to be TimestampType in Spark. How about verifying fields? - // Same for "Duration". Only the Timestamp & Duration protos defined in - // google.protobuf package should default to corresponding Catalylist types. + case MESSAGE + if fd.getMessageType.getName == "Timestamp" && + fd.getMessageType.getFields.size() == 2 && Review Comment: Could move all the conditions into braces (a & b & ...)? ########## connector/protobuf/src/test/resources/protobuf/timestamp.proto: ########## @@ -0,0 +1,26 @@ +/* + * 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 = "proto3"; + +package org.apache.spark.sql.protobuf.protos; + +option java_outer_classname = "TimestampProto"; + +message Timestamp { + int64 seconds = 1; + int32 nanos = 2; +} Review Comment: nit: Fix end-of-line. -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org