JingsongLi commented on code in PR #480: URL: https://github.com/apache/flink-table-store/pull/480#discussion_r1094294121
########## flink-table-store-core/src/main/java/org/apache/flink/table/store/file/casting/CastedRow.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.flink.table.store.file.casting; + +import org.apache.flink.table.store.data.BinaryString; +import org.apache.flink.table.store.data.Decimal; +import org.apache.flink.table.store.data.InternalArray; +import org.apache.flink.table.store.data.InternalMap; +import org.apache.flink.table.store.data.InternalRow; +import org.apache.flink.table.store.data.Timestamp; +import org.apache.flink.table.store.types.RowKind; + +/** + * An implementation of {@link InternalRow} which provides a casted view of the underlying {@link + * InternalRow}. + * + * <p>It reads data from underlying {@link InternalRow} according to source logical type and casts + * it with specific {@link CastExecutor}. + * + * <p>Note: This class supports only top-level castings, not nested castings. + */ +public class CastedRow implements InternalRow { + + private final CastFieldGetter[] castMapping; + + private InternalRow row; + + protected CastedRow(CastFieldGetter[] castMapping) { + this.castMapping = castMapping; + } + + /** + * Replaces the underlying {@link InternalRow} backing this {@link CastedRow}. + * + * <p>This method replaces the row data in place and does not return a new object. This is done + * for performance reasons. + */ + public CastedRow replaceRow(InternalRow row) { + this.row = row; + return this; + } + + @Override + public int getFieldCount() { + return row.getFieldCount(); + } + + @Override + public RowKind getRowKind() { + return row.getRowKind(); + } + + @Override + public void setRowKind(RowKind kind) { + row.setRowKind(kind); + } + + @Override + public boolean isNullAt(int pos) { + return row.isNullAt(pos); + } + + @Override + public boolean getBoolean(int pos) { + return castMapping == null ? row.getBoolean(pos) : castMapping[pos].getFieldOrNull(row); Review Comment: Do we need to create a `CastedRow` when `castMapping` is null? I see `AbstractFileRecordIterator`, it does not create a `CastedRow`. So castMapping should be not null? -- 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]
