gaborkaszab commented on code in PR #17134:
URL: https://github.com/apache/iceberg/pull/17134#discussion_r3605130844
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1833,6 +1836,30 @@ public void testDeleteFilesTableScanOnBranch() throws
IOException {
.isEqualTo(2);
}
+ @TestTemplate
+ public void testMetadataTablesTableScan() throws IOException {
+ Table metadataTablesTable = new MetadataTablesTable(table);
Review Comment:
Maybe creating the test table through `MetadataTableUtils` to add test
coverage for that too?
##########
core/src/main/java/org/apache/iceberg/MetadataTablesTable.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.types.Types;
+
+/** A {@link Table} implementation that exposes a table's metadata tables as
rows. */
+public class MetadataTablesTable extends BaseMetadataTable {
+
+ private static final Schema METADATA_TABLES_SCHEMA =
+ new Schema(Types.NestedField.required(1, "metadata_table_name",
Types.StringType.get()));
+
+ MetadataTablesTable(Table table) {
+ this(table, table.name() + ".metadata_tables");
+ }
+
+ MetadataTablesTable(Table table, String name) {
+ super(table, name);
+ }
+
+ @Override
+ public TableScan newScan() {
+ return new MetadataTablesScan(table());
+ }
+
+ @Override
+ public Schema schema() {
+ return METADATA_TABLES_SCHEMA;
+ }
+
+ @Override
+ MetadataTableType metadataTableType() {
+ return MetadataTableType.METADATA_TABLES;
+ }
+
+ private DataTask task(BaseTableScan scan) {
+ String location =
Review Comment:
I gave this some additional thought: Don't we always have a metadata file
location, even for empty tables? I believe we should.
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1833,6 +1836,30 @@ public void testDeleteFilesTableScanOnBranch() throws
IOException {
.isEqualTo(2);
}
+ @TestTemplate
+ public void testMetadataTablesTableScan() throws IOException {
+ Table metadataTablesTable = new MetadataTablesTable(table);
+
+ List<String> actualTables = Lists.newArrayList();
+ try (CloseableIterable<FileScanTask> tasks =
metadataTablesTable.newScan().planFiles()) {
+ for (FileScanTask task : tasks) {
+ try (CloseableIterable<StructLike> rows = task.asDataTask().rows()) {
+ for (StructLike row : rows) {
+ actualTables.add(row.get(0, String.class));
+ }
+ }
+ }
+ }
+
+ List<String> expectedTables =
+ Arrays.stream(MetadataTableType.values())
+ .map(metadataTableType ->
metadataTableType.name().toLowerCase(Locale.ROOT))
+ .sorted()
+ .collect(ImmutableList.toImmutableList());
+
+ assertThat(actualTables).containsExactlyElementsOf(expectedTables);
+ }
+
Review Comment:
I know there is a test suite where Spark SQL is used to query metadata
tables: `TestMetadataTables`. Have you considered adding a test there? Might be
an overkill, I just want to avoid adding coverage.
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1833,6 +1836,30 @@ public void testDeleteFilesTableScanOnBranch() throws
IOException {
.isEqualTo(2);
}
+ @TestTemplate
+ public void testMetadataTablesTableScan() throws IOException {
+ Table metadataTablesTable = new MetadataTablesTable(table);
+
+ List<String> actualTables = Lists.newArrayList();
Review Comment:
Maybe use something more simpler like this?
```
List<String> actualTables;
try (CloseableIterable<FileScanTask> tasks =
metadataTablesTable.newScan().planFiles()) {
actualTables =
StreamSupport.stream(tasks.spliterator(), false)
.flatMap(task -> Streams.stream(task.asDataTask().rows()))
.map(row -> row.get(0, String.class))
.collect(Collectors.toList());
}
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]