-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Core: Add metadata table for discovering metadata tables #17134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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 org.apache.iceberg.types.Types; | ||
|
|
||
| /** A {@link Table} implementation that exposes a table's metadata tables as rows. */ | ||
| public class MetadataTables extends BaseMetadataTable { | ||
| MetadataTables(Table table) { | ||
| this(table, table.name() + "." + MetadataTableType.METADATA_TABLES.tableName()); | ||
| } | ||
|
|
||
| MetadataTables(Table table, String name) { | ||
| super(table, name); | ||
| } | ||
|
|
||
| private static final Schema METADATA_TABLES_SCHEMA = | ||
| new Schema(Types.NestedField.required(1, "metadata_table_name", Types.StringType.get())); | ||
|
|
||
| @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) { | ||
| StaticDataTask.Row[] rows = | ||
| Arrays.stream(MetadataTableType.values()) | ||
| .map(metadataType -> StaticDataTask.Row.of(metadataType.tableName())) | ||
| .toArray(StaticDataTask.Row[]::new); | ||
|
|
||
| DataFile metadataFile = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I randomly checked other metadata tables and they seem to use the following InputFile:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s a good point. For listing the available metadata tables, at least at this stage, we don’t actually need to read any physical file. Using a directly constructed empty DataFile has a couple of benefits here:
So I think using an empty DataFile is more explicit for this particular metadata table. |
||
| DataFiles.builder(PartitionSpec.unpartitioned()) | ||
| .withPath(table().location() + "#" + MetadataTableType.METADATA_TABLES.tableName()) | ||
| .withFormat(FileFormat.METADATA) | ||
| .withRecordCount(MetadataTableType.values().length) | ||
| .withFileSizeInBytes(0) | ||
| .build(); | ||
|
|
||
| return new StaticDataTask(metadataFile, schema(), scan.schema(), rows); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other metadata tables use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same reason as the above one |
||
| } | ||
|
|
||
| private class MetadataTablesScan extends StaticTableScan { | ||
| MetadataTablesScan(Table table) { | ||
| super( | ||
| table, | ||
| METADATA_TABLES_SCHEMA, | ||
| MetadataTableType.METADATA_TABLES, | ||
| MetadataTables.this::task); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reding this Scan class and comparing to others can't we simply do what
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense, fixed |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,7 +194,11 @@ public void testSerializableMetadataTablesPlanning(boolean fromSerialized) throw | |
| Set<CharSequence> newFiles = getFiles(getMetaDataTable(table, type)); | ||
|
|
||
| // Expect that the new data is changed in the meantime | ||
| assertThat(deserializedFiles).isNotEqualTo(newFiles); | ||
| if (type == MetadataTableType.METADATA_TABLES) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not entirely sure why the new table is any different than the other in this test.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since reading the metadata tables does not require reading any actual files, the file path would remain unchanged regardless of how many commits are made. Therefore, this case needs to be handled separately. |
||
| assertThat(deserializedFiles).isEqualTo(newFiles); | ||
| } else { | ||
| assertThat(deserializedFiles).isNotEqualTo(newFiles); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking
RefsTableinstead of constructingStaticDataTask.Row[]', we can simply useCollectionwith a transform function to convert it to row viaStaticDataTask.Row.of()`There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gaborkaszab same reason with the usage of empty Datafile, as constructor accept parameter Row[]