huaxingao commented on a change in pull request #32049:
URL: https://github.com/apache/spark/pull/32049#discussion_r607423668



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/parquet/ParquetPartitionReaderFactory.scala
##########
@@ -80,43 +88,135 @@ case class ParquetPartitionReaderFactory(
   private val datetimeRebaseModeInRead = 
parquetOptions.datetimeRebaseModeInRead
   private val int96RebaseModeInRead = parquetOptions.int96RebaseModeInRead
 
+  private def buildAggSchema: StructType = {
+    var aggSchema = new StructType()
+    for (i <- 0 until aggregation.aggregateExpressions.size) {
+      var index = 0
+      aggregation.aggregateExpressions(i) match {
+        case Max(col, _) =>
+          index = dataSchema.fieldNames.toList.indexOf(col)
+          val field = dataSchema.fields(index)
+          aggSchema = aggSchema.add(field.copy("max(" + field.name + ")"))
+        case Min(col, _) =>
+          index = dataSchema.fieldNames.toList.indexOf(col)
+          val field = dataSchema.fields(index)
+          aggSchema = aggSchema.add(field.copy("min(" + field.name + ")"))
+        case Count(col, _, _) =>
+          if (col.equals("1")) {
+            aggSchema = aggSchema.add(new StructField("count(*)", LongType))
+          } else {
+            aggSchema = aggSchema.add(new StructField("count(" + col + ")", 
LongType))
+          }
+        case _ =>
+      }
+    }
+    aggSchema
+  }
+
   override def supportColumnarReads(partition: InputPartition): Boolean = {
     sqlConf.parquetVectorizedReaderEnabled && sqlConf.wholeStageEnabled &&
       resultSchema.length <= sqlConf.wholeStageMaxNumFields &&
       resultSchema.forall(_.dataType.isInstanceOf[AtomicType])
   }
 
   override def buildReader(file: PartitionedFile): 
PartitionReader[InternalRow] = {
-    val reader = if (enableVectorizedReader) {
-      createVectorizedReader(file)
+    val fileReader = if (aggregation.aggregateExpressions.isEmpty) {
+
+      val reader = if (enableVectorizedReader) {
+        createVectorizedReader(file)

Review comment:
       I think it doesn't matter if the vectorized reader is enabled or not.  
Since we are reading the statistics information from the parquet footer, we 
don't really create a VectorizedReader. But if columnar reader is enabled, we 
return a `ColumnarBatch` instead of a `InternalRow`.




-- 
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.

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

Reply via email to