XuQianJin-Stars commented on code in PR #2345: URL: https://github.com/apache/fluss/pull/2345#discussion_r2697157323
########## fluss-lake/fluss-lake-lance/src/main/java/org/apache/fluss/lake/lance/tiering/ShadedArrowBatchWriter.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.fluss.lake.lance.tiering; + +import org.apache.fluss.row.InternalRow; +import org.apache.fluss.row.arrow.writers.ArrowFieldWriter; +import org.apache.fluss.shaded.arrow.org.apache.arrow.memory.BufferAllocator; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.FieldVector; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.fluss.types.RowType; +import org.apache.fluss.utils.ArrowUtils; + +/** + * Batch writer using shaded Arrow and ArrowFieldWriter from fluss-common. + * + * <p>This class uses shaded Arrow vectors and ArrowFieldWriters to write Fluss InternalRows. It can + * later be converted to non-shaded Arrow format for Lance compatibility. + */ +public class ShadedArrowBatchWriter implements AutoCloseable { + private final VectorSchemaRoot shadedRoot; + private final ArrowFieldWriter[] fieldWriters; + private int recordsCount; + + public ShadedArrowBatchWriter(BufferAllocator shadedAllocator, RowType rowType) { + this.shadedRoot = + VectorSchemaRoot.create(ArrowUtils.toArrowSchema(rowType), shadedAllocator); + this.shadedRoot.allocateNew(); + this.fieldWriters = new ArrowFieldWriter[rowType.getFieldCount()]; + + for (int i = 0; i < fieldWriters.length; i++) { + FieldVector fieldVector = shadedRoot.getVector(i); + fieldWriters[i] = ArrowUtils.createArrowFieldWriter(fieldVector, rowType.getTypeAt(i)); Review Comment: <img width="1890" height="1004" alt="Clipboard_Screenshot_1768544374" src="https://github.com/user-attachments/assets/cfcfd40d-1a9b-47ad-a528-d01c4abd9b06" /> <img width="1846" height="750" alt="Clipboard_Screenshot_1768544419" src="https://github.com/user-attachments/assets/cc7488ac-7a21-438c-aa5c-a2150b8fd51f" /> Here, a `VectorSchemaRoot` constructed with non-shadowed arrows must be used. -- 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]
