gaborkaszab commented on code in PR #17134:
URL: https://github.com/apache/iceberg/pull/17134#discussion_r3594825593
##########
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).containsExactlyInAnyOrderElementsOf(expectedTables);
Review Comment:
You order both expected and actual values. `InAnyOrder` part is not needed
for the assertion
##########
core/src/main/java/org/apache/iceberg/MetadataTablesTable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.Comparator;
+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 = table().operations().current().metadataFileLocation();
Review Comment:
I'd move the ternary here from the `newInputFile()` actual parameter
##########
core/src/main/java/org/apache/iceberg/MetadataTablesTable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.Comparator;
+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 = table().operations().current().metadataFileLocation();
+
+ List<MetadataTableType> sortedMetadataTableTypes =
+ Arrays.stream(MetadataTableType.values())
+ .sorted(Comparator.comparing(type ->
type.name().toLowerCase(Locale.ROOT)))
+ .collect(ImmutableList.toImmutableList());
+
+ return StaticDataTask.of(
+ table().io().newInputFile(location != null ? location :
scan.table().location()),
+ schema(),
+ scan.schema(),
+ sortedMetadataTableTypes,
+ metadataType ->
StaticDataTask.Row.of(metadataType.name().toLowerCase(Locale.ROOT)));
Review Comment:
Can we do the conversion to lower case when we produce the sorted list? I
see there is also a similar conversion there.
--
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]