beryllw commented on code in PR #1505: URL: https://github.com/apache/fluss/pull/1505#discussion_r2265735004
########## fluss-lake/fluss-lake-paimon/src/main/java/com/alibaba/fluss/lake/paimon/lakehouse/PaimonRecordReader.java: ########## @@ -0,0 +1,159 @@ +/* + * 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 com.alibaba.fluss.lake.paimon.lakehouse; + +import com.alibaba.fluss.lake.paimon.utils.PaimonRowAsFlussRow; +import com.alibaba.fluss.lake.source.RecordReader; +import com.alibaba.fluss.record.ChangeType; +import com.alibaba.fluss.record.GenericRecord; +import com.alibaba.fluss.record.LogRecord; +import com.alibaba.fluss.row.ProjectedRow; +import com.alibaba.fluss.utils.CloseableIterator; + +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.predicate.Predicate; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.source.ReadBuilder; +import org.apache.paimon.table.source.TableRead; +import org.apache.paimon.types.DataField; +import org.apache.paimon.types.RowType; + +import javax.annotation.Nullable; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.IntStream; + +import static com.alibaba.fluss.lake.paimon.utils.PaimonConversions.toChangeType; +import static com.alibaba.fluss.metadata.TableDescriptor.OFFSET_COLUMN_NAME; +import static com.alibaba.fluss.metadata.TableDescriptor.TIMESTAMP_COLUMN_NAME; + +/** Record reader for paimon table. */ +public class PaimonRecordReader implements RecordReader { + + protected PaimonRowAsFlussRecordIterator iterator; + protected @Nullable int[][] project; + protected @Nullable Predicate predicate; + protected RowType paimonRowType; + + public PaimonRecordReader( + FileStoreTable fileStoreTable, + PaimonSplit split, + @Nullable int[][] project, + @Nullable Predicate predicate) + throws IOException { + + ReadBuilder readBuilder = fileStoreTable.newReadBuilder(); + int fieldCount = fileStoreTable.rowType().getFieldCount(); + List<DataField> pkFields = fileStoreTable.schema().primaryKeysFields(); + if (project != null) { + readBuilder = applyProject(readBuilder, project, fieldCount, pkFields); + } + + if (predicate != null) { + readBuilder.withFilter(predicate); + } + + TableRead tableRead = readBuilder.newRead(); + paimonRowType = readBuilder.readType(); + + org.apache.paimon.reader.RecordReader<InternalRow> recordReader = + tableRead.createReader(split.dataSplit()); + iterator = + new PaimonRecordReader.PaimonRowAsFlussRecordIterator( + recordReader.toCloseableIterator(), paimonRowType); + } + + @Override + public CloseableIterator<LogRecord> read() throws IOException { + return iterator; + } + + // TODO: Support primary key projection and obtain primary key index for merging. Review Comment: If upper caller handles it, this todo is not required. -- 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]
