-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce42133
commit 3d9316f
Showing
8 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/RefsTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.iceberg; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.trino.plugin.iceberg.util.PageListBuilder; | ||
import io.trino.spi.Page; | ||
import io.trino.spi.connector.ColumnMetadata; | ||
import io.trino.spi.connector.ConnectorPageSource; | ||
import io.trino.spi.connector.ConnectorSession; | ||
import io.trino.spi.connector.ConnectorTableMetadata; | ||
import io.trino.spi.connector.ConnectorTransactionHandle; | ||
import io.trino.spi.connector.FixedPageSource; | ||
import io.trino.spi.connector.SchemaTableName; | ||
import io.trino.spi.connector.SystemTable; | ||
import io.trino.spi.predicate.TupleDomain; | ||
import org.apache.iceberg.Table; | ||
|
||
import java.util.List; | ||
|
||
import static io.trino.spi.type.BigintType.BIGINT; | ||
import static io.trino.spi.type.IntegerType.INTEGER; | ||
import static io.trino.spi.type.VarcharType.VARCHAR; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class RefsTable | ||
implements SystemTable | ||
{ | ||
private final ConnectorTableMetadata tableMetadata; | ||
private final Table icebergTable; | ||
|
||
public RefsTable(SchemaTableName tableName, Table icebergTable) | ||
{ | ||
this.icebergTable = requireNonNull(icebergTable, "icebergTable is null"); | ||
|
||
this.tableMetadata = new ConnectorTableMetadata(requireNonNull(tableName, "tableName is null"), | ||
ImmutableList.<ColumnMetadata>builder() | ||
.add(new ColumnMetadata("name", VARCHAR)) | ||
.add(new ColumnMetadata("type", VARCHAR)) | ||
.add(new ColumnMetadata("snapshot_id", BIGINT)) | ||
.add(new ColumnMetadata("max_reference_age_in_ms", BIGINT)) | ||
.add(new ColumnMetadata("min_snapshots_to_keep", INTEGER)) | ||
.add(new ColumnMetadata("max_snapshot_age_in_ms", BIGINT)) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public Distribution getDistribution() | ||
{ | ||
return Distribution.SINGLE_COORDINATOR; | ||
} | ||
|
||
@Override | ||
public ConnectorTableMetadata getTableMetadata() | ||
{ | ||
return tableMetadata; | ||
} | ||
|
||
@Override | ||
public ConnectorPageSource pageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) | ||
{ | ||
return new FixedPageSource(buildPages(tableMetadata, icebergTable)); | ||
} | ||
|
||
private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, Table icebergTable) | ||
{ | ||
PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata); | ||
|
||
icebergTable.refs().forEach((refName, ref) -> { | ||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(refName); | ||
pagesBuilder.appendVarchar(ref.isBranch() ? "BRANCH" : "TAG"); | ||
pagesBuilder.appendBigint(ref.snapshotId()); | ||
pagesBuilder.appendBigint(ref.maxRefAgeMs()); | ||
pagesBuilder.appendInteger(ref.minSnapshotsToKeep()); | ||
pagesBuilder.appendBigint(ref.maxSnapshotAgeMs()); | ||
pagesBuilder.endRow(); | ||
}); | ||
|
||
return pagesBuilder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ public enum TableType | |
PARTITIONS, | ||
FILES, | ||
PROPERTIES, | ||
REFS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters