pvary commented on code in PR #13302:
URL: https://github.com/apache/iceberg/pull/13302#discussion_r2161082199


##########
flink/v2.0/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/TableReader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.iceberg.flink.maintenance.operator;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.functions.OpenContext;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.metrics.Counter;
+import org.apache.flink.streaming.api.functions.ProcessFunction;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.util.Collector;
+import org.apache.iceberg.MetadataTableType;
+import org.apache.iceberg.MetadataTableUtils;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.TableLoader;
+import org.apache.iceberg.flink.maintenance.api.DeleteOrphanFiles;
+import org.apache.iceberg.flink.source.DataIterator;
+import org.apache.iceberg.flink.source.reader.MetaDataReaderFunction;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplitSerializer;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Reads the records from the metadata table splits. */
+@Internal
+public class TableReader extends ProcessFunction<TablePlanner.SplitInfo, 
String> {
+  private static final Logger LOG = LoggerFactory.getLogger(TableReader.class);
+
+  private final TableLoader tableLoader;
+  private final String taskName;
+  private final int taskIndex;
+  private final Schema projectedSchema;
+  private final boolean caseSensitive;
+  private IcebergSourceSplitSerializer splitSerializer;
+
+  private transient MetaDataReaderFunction rowDataReaderFunction;
+  private transient Counter errorCounter;
+
+  public TableReader(
+      String taskName,
+      int taskIndex,
+      TableLoader tableLoader,
+      Schema projectedSchema,
+      boolean caseSensitive) {
+    Preconditions.checkNotNull(taskName, "Task name should no be null");
+    Preconditions.checkNotNull(tableLoader, "Table should no be null");
+    Preconditions.checkNotNull(projectedSchema, "The projected schema should 
no be null");
+
+    this.tableLoader = tableLoader;
+    this.taskName = taskName;
+    this.taskIndex = taskIndex;
+    this.projectedSchema = projectedSchema;
+    this.caseSensitive = caseSensitive;
+  }
+
+  @Override
+  public void open(OpenContext openContext) throws Exception {
+    tableLoader.open();
+    Table table = tableLoader.loadTable();
+    Table metaTable =
+        MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.ALL_FILES);
+    this.errorCounter =
+        TableMaintenanceMetrics.groupFor(getRuntimeContext(), table.name(), 
taskName, taskIndex)
+            .counter(TableMaintenanceMetrics.ERROR_COUNTER);
+    this.rowDataReaderFunction =
+        new MetaDataReaderFunction(
+            new Configuration(),
+            metaTable.schema(),
+            projectedSchema,
+            metaTable.io(),
+            metaTable.encryption());
+    this.splitSerializer = new IcebergSourceSplitSerializer(caseSensitive);
+  }
+
+  @Override
+  public void processElement(TablePlanner.SplitInfo splitInfo, Context ctx, 
Collector<String> out)
+      throws Exception {
+    IcebergSourceSplit split =
+        splitSerializer.deserialize(splitInfo.getVersion(), 
splitInfo.getSplit());
+    try (DataIterator<RowData> iterator = 
rowDataReaderFunction.createDataIterator(split)) {
+      iterator.forEachRemaining(
+          rowData -> {
+            if (rowData != null && rowData.getString(0) != null) {
+              out.collect(rowData.getString(0).toString());
+            }
+          });

Review Comment:
   What is `Plan One` in this case? 😄 



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to