malinjawi commented on code in PR #13595: URL: https://github.com/apache/gluten/pull/13595#discussion_r4647850083
########## backends-velox/src-lance/main/scala/org/apache/gluten/connector/write/LanceColumnarBatchDataWriter.scala: ########## @@ -0,0 +1,443 @@ +/* + * 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.gluten.connector.write + +import org.apache.gluten.backendsapi.BackendsApiManager +import org.apache.gluten.columnarbatch.{ColumnarBatches, ColumnarBatchJniWrapper} +import org.apache.gluten.memory.arrow.alloc.ArrowBufferAllocators +import org.apache.gluten.metrics.BatchWriteMetrics + +import org.apache.spark.internal.Logging +import org.apache.spark.sql.connector.metric.CustomTaskMetric +import org.apache.spark.sql.connector.write.{DataWriter, WriterCommitMessage} +import org.apache.spark.sql.execution.metric.CustomMetrics +import org.apache.spark.sql.vectorized.ColumnarBatch + +import org.apache.arrow.c.{ArrowArray, ArrowArrayStream, ArrowSchema, CDataDictionaryProvider, Data} +import org.apache.arrow.memory.BufferAllocator +import org.apache.arrow.vector.VectorSchemaRoot +import org.apache.arrow.vector.ipc.ArrowReader +import org.apache.arrow.vector.types.pojo.{ArrowType, Field, Schema} +import org.lance.{Fragment, FragmentMetadata} +import org.lance.spark.write.{FragmentWriteSpec, LanceBatchWrite} +import org.lance.spark.write.metric.LanceWriteMetrics + +import java.io.IOException +import java.util.{Collections, List => JList} +import java.util.concurrent.{ArrayBlockingQueue, TimeUnit} +import java.util.concurrent.atomic.AtomicLong + +import scala.collection.JavaConverters._ + +/** + * Writes one task's Velox batches into uncommitted Lance fragments. + * + * Spark pushes batches through [[write]], while Lance pulls batches from an Arrow C stream until it + * ends. A background thread bridges the two, as lance-spark's own row writer does: each batch is + * exported to Arrow C structs on the task thread and queued, and the thread writes fragments with + * the parameters of the [[FragmentWriteSpec]] from a stream that drains the queue. + * + * The stream advertises the commit schema, so its names, nullability and timestamp zone are the + * ones `LanceBatchWrite.commit` uses. Every exported batch is checked against it, so a type Velox + * exports differently fails the task instead of writing a corrupt table. Fixed-size list columns + * arrive as plain lists and are converted by [[LanceFixedSizeLists]], and the values Velox leaves + * under nulls are zeroed by [[LanceNullSlots]] so that Lance encodes as compactly as it does for + * the row writer. + * + * The writer thread imports the batches with the task's Arrow allocator, so they count as task Review Comment: Right, now says Lance pulls the batches on its own Tokio threads, where they're imported and reserve task memory. -- 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]
