yaooqinn commented on a change in pull request #33888:
URL: https://github.com/apache/spark/pull/33888#discussion_r702050323



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetReadSupport.scala
##########
@@ -323,15 +344,27 @@ object ParquetReadSupport {
    * @return A list of clipped [[GroupType]] fields, which can be empty.
    */
   private def clipParquetGroupFields(
-      parquetRecord: GroupType, structType: StructType, caseSensitive: 
Boolean): Seq[Type] = {
+      parquetRecord: GroupType,
+      structType: StructType,
+      caseSensitive: Boolean,
+      accessByColumnOrdinal: Boolean): Seq[Type] = {
     val toParquet = new SparkToParquetSchemaConverter(writeLegacyParquetFormat 
= false)
-    if (caseSensitive) {
+    if (accessByColumnOrdinal) {
+      structType.zipWithIndex.map { case (f, i) =>
+        if (i < parquetRecord.getFieldCount) {
+          clipParquetType(
+            parquetRecord.getType(i), f.dataType, caseSensitive, 
accessByColumnOrdinal)
+        } else {
+          toParquet.convertField(f)
+        }
+      }
+    } else if (caseSensitive) {
       val caseSensitiveParquetFieldMap =
         parquetRecord.getFields.asScala.map(f => f.getName -> f).toMap
       structType.map { f =>
         caseSensitiveParquetFieldMap
           .get(f.name)
-          .map(clipParquetType(_, f.dataType, caseSensitive))
+          .map(clipParquetType(_, f.dataType, caseSensitive, 
accessByColumnOrdinal))

Review comment:
       we support nesting, as you can see from the newly added 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: [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]

Reply via email to