JingsongLi commented on code in PR #202:
URL: https://github.com/apache/flink-table-store/pull/202#discussion_r915498253
##########
flink-table-store-hive/flink-table-store-hive-connector/src/main/java/org/apache/flink/table/store/mapred/TableStoreRecordReader.java:
##########
@@ -36,24 +41,44 @@ public class TableStoreRecordReader implements
RecordReader<Void, RowDataContain
private final RecordReaderIterator<RowData> iterator;
private final long splitLength;
+ @Nullable private final ProjectedRowData reusedProjectedRow;
+
private float progress;
public TableStoreRecordReader(
- org.apache.flink.table.store.file.utils.RecordReader<RowData>
wrapped,
- long splitLength) {
- this.iterator = new RecordReaderIterator<>(wrapped);
- this.splitLength = splitLength;
+ TableRead read,
+ TableStoreInputSplit split,
+ List<String> columnNames,
+ List<String> selectedColumns)
Review Comment:
Add documentation here: Still output the original schema of the Row, the
role of `selectedColumns` is to read out the required fields, other fields to
fill Nulls.
##########
flink-table-store-hive/flink-table-store-hive-connector/src/main/java/org/apache/flink/table/store/mapred/TableStoreRecordReader.java:
##########
@@ -36,24 +41,44 @@ public class TableStoreRecordReader implements
RecordReader<Void, RowDataContain
private final RecordReaderIterator<RowData> iterator;
private final long splitLength;
+ @Nullable private final ProjectedRowData reusedProjectedRow;
+
private float progress;
public TableStoreRecordReader(
- org.apache.flink.table.store.file.utils.RecordReader<RowData>
wrapped,
- long splitLength) {
- this.iterator = new RecordReaderIterator<>(wrapped);
- this.splitLength = splitLength;
+ TableRead read,
+ TableStoreInputSplit split,
+ List<String> columnNames,
+ List<String> selectedColumns)
+ throws IOException {
+ if (columnNames.equals(selectedColumns)) {
+ reusedProjectedRow = null;
+ } else {
+
read.withProjection(selectedColumns.stream().mapToInt(columnNames::indexOf).toArray());
+ reusedProjectedRow =
+ ProjectedRowData.from(
+
columnNames.stream().mapToInt(selectedColumns::indexOf).toArray());
+ }
+
+ this.iterator = new
RecordReaderIterator<>(read.createReader(split.split()));
+ this.splitLength = split.getLength();
this.progress = 0;
}
@Override
public boolean next(Void key, RowDataContainer value) throws IOException {
RowData rowData = iterator.next();
+
if (rowData == null) {
progress = 1;
return false;
} else {
- value.set(rowData);
+ if (reusedProjectedRow != null) {
+ reusedProjectedRow.replaceRow(rowData);
+ value.set(reusedProjectedRow);
Review Comment:
`value.set(reusedProjectedRow.replaceRow(rowData));`
--
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]