HyukjinKwon commented on code in PR #36683: URL: https://github.com/apache/spark/pull/36683#discussion_r882521849
########## sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowConverters.scala: ########## @@ -190,32 +191,30 @@ private[sql] object ArrowConverters { } /** - * Create a DataFrame from an RDD of serialized ArrowRecordBatches. + * Create a DataFrame from an iterator of serialized ArrowRecordBatches. */ - private[sql] def toDataFrame( - arrowBatchRDD: JavaRDD[Array[Byte]], + def toDataFrame( + arrowBatches: Iterator[Array[Byte]], schemaString: String, session: SparkSession): DataFrame = { - val schema = DataType.fromJson(schemaString).asInstanceOf[StructType] - val timeZoneId = session.sessionState.conf.sessionLocalTimeZone - val rdd = arrowBatchRDD.rdd.mapPartitions { iter => - val context = TaskContext.get() - ArrowConverters.fromBatchIterator(iter, schema, timeZoneId, context) - } - session.internalCreateDataFrame(rdd.setName("arrow"), schema) + val attrs = DataType.fromJson(schemaString).asInstanceOf[StructType].toAttributes + val data = ArrowConverters.fromBatchIterator( + arrowBatches, + DataType.fromJson(schemaString).asInstanceOf[StructType], + session.sessionState.conf.sessionLocalTimeZone, + TaskContext.get()) + // Project it. Otherwise, the Arrow column vectors will be closed and released out. + val proj = UnsafeProjection.create(attrs, attrs) + Dataset.ofRows(session, LocalRelation(attrs, data.map(r => proj(r).copy()).toArray)) Review Comment: One downside of this approach is that, now the `data` will live in driver side. If the pandas DataFrame is too big, it can easily throw an exception from the driver side. However, I think this is the same as the Scala side so I suspect this is fine. Maybe we can add a configuration to turn on and off but I don't feel strongly on that. -- 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