gengliangwang commented on a change in pull request #33308:
URL: https://github.com/apache/spark/pull/33308#discussion_r672363796
##########
File path:
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroUtils.scala
##########
@@ -228,6 +236,38 @@ private[sql] object AvroUtils extends Logging {
.groupBy(_.name.toLowerCase(Locale.ROOT))
.mapValues(_.toSeq) // toSeq needed for scala 2.13
+ private[this] val fieldPairs = catalystSchema
+ .zipWithIndex
+ .map(fieldWithPos => (fieldWithPos, getAvroField(fieldWithPos._1.name,
fieldWithPos._2)))
+
+ /**
+ * Get the fields which have matching equivalents in both Avro and
Catalyst schemas.
+ *
+ * @return A sequence of `(catalystField, catalystPosition, avroField)`
tuples.
+ */
+ def getMatchedFields: Seq[(StructField, Int, Schema.Field)] =
fieldPairs.flatMap {
Review comment:
The result of this method is complicated.
##########
File path:
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroUtils.scala
##########
@@ -228,6 +236,38 @@ private[sql] object AvroUtils extends Logging {
.groupBy(_.name.toLowerCase(Locale.ROOT))
.mapValues(_.toSeq) // toSeq needed for scala 2.13
+ private[this] val fieldPairs = catalystSchema
+ .zipWithIndex
+ .map(fieldWithPos => (fieldWithPos, getAvroField(fieldWithPos._1.name,
fieldWithPos._2)))
+
+ /**
+ * Get the fields which have matching equivalents in both Avro and
Catalyst schemas.
+ *
+ * @return A sequence of `(catalystField, catalystPosition, avroField)`
tuples.
+ */
+ def getMatchedFields: Seq[(StructField, Int, Schema.Field)] =
fieldPairs.flatMap {
+ case ((sqlField, sqlPos), Some(avroField)) => Some((sqlField, sqlPos,
avroField))
+ case (_, None) => None
+ }
+
+ def assertNoExtraSqlFields(includeNullable: Boolean): Unit =
+ fieldPairs.filter(_._2.isEmpty).map(_._1).filter(includeNullable ||
!_._1.nullable) match {
Review comment:
TBH, this line is a bit hard to understand...
##########
File path:
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroUtils.scala
##########
@@ -228,6 +236,38 @@ private[sql] object AvroUtils extends Logging {
.groupBy(_.name.toLowerCase(Locale.ROOT))
.mapValues(_.toSeq) // toSeq needed for scala 2.13
+ private[this] val fieldPairs = catalystSchema
+ .zipWithIndex
+ .map(fieldWithPos => (fieldWithPos, getAvroField(fieldWithPos._1.name,
fieldWithPos._2)))
+
+ /**
+ * Get the fields which have matching equivalents in both Avro and
Catalyst schemas.
+ *
+ * @return A sequence of `(catalystField, catalystPosition, avroField)`
tuples.
+ */
+ def getMatchedFields: Seq[(StructField, Int, Schema.Field)] =
fieldPairs.flatMap {
Review comment:
Let's create a new case class for this:
```
case class AvroMatchedField(avroField Schema.Field, catalystField
StructField, catalystPosition int)
```
--
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]