aokolnychyi commented on a change in pull request #805: Add all_data_files, 
all_manifests, and all_entries metadata tables
URL: https://github.com/apache/incubator-iceberg/pull/805#discussion_r382696530
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/AllDataFilesTable.java
 ##########
 @@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.util.ParallelIterable;
+import org.apache.iceberg.util.ThreadPools;
+
+/**
+ * A {@link Table} implementation that exposes a table's valid data files as 
rows.
+ * <p>
+ * A valid data file is one that is readable from any snapshot currently 
tracked by the table.
+ * <p>
+ * This table may return duplicate rows.
+ */
+public class AllDataFilesTable extends BaseMetadataTable {
+  private final TableOperations ops;
+  private final Table table;
+
+  public AllDataFilesTable(TableOperations ops, Table table) {
+    this.ops = ops;
+    this.table = table;
+  }
+
+  @Override
+  Table table() {
+    return table;
+  }
+
+  @Override
+  String metadataTableName() {
+    return "all_data_files";
+  }
+
+  @Override
+  public TableScan newScan() {
+    return new AllDataFilesTableScan(ops, table, schema());
+  }
+
+  @Override
+  public Schema schema() {
+    Schema schema = new 
Schema(DataFile.getType(table.spec().partitionType()).fields());
+    if (table.spec().fields().size() < 1) {
+      // avoid returning an empty struct, which is not always supported. 
instead, drop the partition field (id 102)
+      return TypeUtil.selectNot(schema, Sets.newHashSet(102));
+    } else {
+      return schema;
+    }
+  }
+
+  @Override
+  public String location() {
+    return table.currentSnapshot().manifestListLocation();
+  }
+
+  public static class AllDataFilesTableScan extends BaseTableScan {
+    private static final long TARGET_SPLIT_SIZE = 32 * 1024 * 1024; // 32 MB
+    private final Schema fileSchema;
+
+    AllDataFilesTableScan(TableOperations ops, Table table, Schema fileSchema) 
{
+      super(ops, table, fileSchema);
+      this.fileSchema = fileSchema;
+    }
+
+    private AllDataFilesTableScan(
+        TableOperations ops, Table table, Long snapshotId, Schema schema, 
Expression rowFilter,
+        boolean caseSensitive, boolean colStats, Collection<String> 
selectedColumns, Schema fileSchema,
+        ImmutableMap<String, String> options) {
+      super(ops, table, snapshotId, schema, rowFilter, caseSensitive, 
colStats, selectedColumns, options);
+      this.fileSchema = fileSchema;
+    }
+
+    @Override
+    protected TableScan newRefinedScan(
+        TableOperations ops, Table table, Long snapshotId, Schema schema, 
Expression rowFilter,
+        boolean caseSensitive, boolean colStats, Collection<String> 
selectedColumns,
+        ImmutableMap<String, String> options) {
+      return new AllDataFilesTableScan(
+          ops, table, snapshotId, schema, rowFilter, caseSensitive, colStats, 
selectedColumns, fileSchema, options);
+    }
+
+    @Override
+    public TableScan useSnapshot(long scanSnapshotId) {
+      throw new UnsupportedOperationException("Cannot select snapshot: 
all_data_files is for all snapshots");
+    }
+
+    @Override
+    public TableScan asOfTime(long timestampMillis) {
+      throw new UnsupportedOperationException("Cannot select snapshot: 
all_data_files is for all snapshots");
+    }
+
+    @Override
+    protected long targetSplitSize(TableOperations ops) {
+      return TARGET_SPLIT_SIZE;
 
 Review comment:
   I believe it generally makes sense to configure the split size for metadata 
tables. In our tables, it is not uncommon to see 4-6 MB manifest files. If we 
have a reasonable cluster and allow split sizes to be 16 MB, metadata queries 
can be 2 times faster.
   
   I've created #817 so that we can discuss it.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to