viirya commented on code in PR #53232: URL: https://github.com/apache/spark/pull/53232#discussion_r2566621669
########## sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowFileReadWrite.scala: ########## @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.arrow + +import java.io.{ByteArrayOutputStream, FileOutputStream} +import java.nio.channels.Channels +import java.nio.file.Files +import java.nio.file.Paths + +import scala.jdk.CollectionConverters._ + +import org.apache.arrow.vector._ +import org.apache.arrow.vector.ipc.{ArrowFileReader, ArrowFileWriter, WriteChannel} +import org.apache.arrow.vector.ipc.message.MessageSerializer +import org.apache.arrow.vector.types.pojo.Schema + +import org.apache.spark.sql.classic.{DataFrame, SparkSession} +import org.apache.spark.sql.util.ArrowUtils + +private[sql] class SparkArrowFileWriter( + arrowSchema: Schema, + path: String) extends AutoCloseable { + private val allocator = + ArrowUtils.rootAllocator.newChildAllocator( + s"to${this.getClass.getSimpleName}", 0, Long.MaxValue) + + protected val root = VectorSchemaRoot.create(arrowSchema, allocator) + protected val loader = new VectorLoader(root) + protected val arrowWriter = ArrowWriter.create(root) Review Comment: Where is `arrowWriter` used? ########## sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowFileReadWrite.scala: ########## @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.arrow + +import java.io.{ByteArrayOutputStream, FileOutputStream} +import java.nio.channels.Channels +import java.nio.file.Files +import java.nio.file.Paths + +import scala.jdk.CollectionConverters._ + +import org.apache.arrow.vector._ +import org.apache.arrow.vector.ipc.{ArrowFileReader, ArrowFileWriter, WriteChannel} +import org.apache.arrow.vector.ipc.message.MessageSerializer +import org.apache.arrow.vector.types.pojo.Schema + +import org.apache.spark.sql.classic.{DataFrame, SparkSession} +import org.apache.spark.sql.util.ArrowUtils + +private[sql] class SparkArrowFileWriter( + arrowSchema: Schema, + path: String) extends AutoCloseable { + private val allocator = + ArrowUtils.rootAllocator.newChildAllocator( + s"to${this.getClass.getSimpleName}", 0, Long.MaxValue) + + protected val root = VectorSchemaRoot.create(arrowSchema, allocator) + protected val loader = new VectorLoader(root) + protected val arrowWriter = ArrowWriter.create(root) + + protected val fileWriter = + new ArrowFileWriter(root, null, Channels.newChannel(new FileOutputStream(path))) + + override def close(): Unit = { + root.close() + allocator.close() + fileWriter.close() + } + + def write(batchBytesIter: Iterator[Array[Byte]]): Unit = { Review Comment: This looks like do such thing: Dataset -> Arrow batches -> Bytes -> Arrow batches -> Write Arrow batches by ArrowFileWriter Looks like the intermediate Bytes could be skipped? -- 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]
