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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetUtils.scala
##########
@@ -127,4 +147,328 @@ object ParquetUtils {
     file.getName == ParquetFileWriter.PARQUET_COMMON_METADATA_FILE ||
       file.getName == ParquetFileWriter.PARQUET_METADATA_FILE
   }
+
+  private[sql] def aggResultToSparkInternalRows(
+      footer: ParquetMetadata,
+      parquetTypes: Seq[PrimitiveType.PrimitiveTypeName],
+      values: Seq[Any],
+      dataSchema: StructType,
+      datetimeRebaseModeInRead: String,
+      int96RebaseModeInRead: String,
+      convertTz: Option[ZoneId]): InternalRow = {
+    val mutableRow = new SpecificInternalRow(dataSchema.fields.map(x => 
x.dataType))
+    val footerFileMetaData = footer.getFileMetaData
+    val datetimeRebaseMode = DataSourceUtils.datetimeRebaseMode(
+      footerFileMetaData.getKeyValueMetaData.get,
+      datetimeRebaseModeInRead)
+    val int96RebaseMode = DataSourceUtils.int96RebaseMode(
+      footerFileMetaData.getKeyValueMetaData.get,
+      int96RebaseModeInRead)
+    parquetTypes.zipWithIndex.map {
+      case (PrimitiveType.PrimitiveTypeName.INT32, i) =>
+        if (values(i) == null) {
+          mutableRow.setNullAt(i)
+        } else {
+          dataSchema.fields(i).dataType match {
+            case b: ByteType =>
+              mutableRow.setByte(i, values(i).asInstanceOf[Integer].toByte)
+            case s: ShortType =>
+              mutableRow.setShort(i, values(i).asInstanceOf[Integer].toShort)
+            case int: IntegerType =>
+              mutableRow.setInt(i, values(i).asInstanceOf[Integer])
+            case d: DateType =>
+              val dateRebaseFunc = DataSourceUtils.creteDateRebaseFuncInRead(
+                datetimeRebaseMode, "Parquet")
+              mutableRow.update(i, 
dateRebaseFunc(values(i).asInstanceOf[Integer]))
+            case d: DecimalType =>
+              val decimal = Decimal(values(i).asInstanceOf[Integer].toLong, 
d.precision, d.scale)
+              mutableRow.setDecimal(i, decimal, d.precision)
+            case _ => throw new IllegalArgumentException("Unexpected type for 
INT32")
+          }
+        }
+      case (PrimitiveType.PrimitiveTypeName.INT64, i) =>
+        if (values(i) == null) {
+          mutableRow.setNullAt(i)
+        } else {
+          dataSchema.fields(i).dataType match {
+            case long: LongType =>
+              mutableRow.setLong(i, values(i).asInstanceOf[Long])
+            case d: DecimalType =>
+              val decimal = Decimal(values(i).asInstanceOf[Integer].toLong, 
d.precision, d.scale)

Review comment:
       should be `values(i).asInstanceOf[Long]`. Fixed.




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to