-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iceberg $properties system table
Cherry-pick of trinodb/trino@8abb12f Co-Authored-By: Victoria Bukta <victoria.bukta@shopify.com>
- Loading branch information
1 parent
63a6b0f
commit cd68273
Showing
4 changed files
with
95 additions
and
0 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
83 changes: 83 additions & 0 deletions
83
presto-iceberg/src/main/java/com/facebook/presto/iceberg/PropertiesTable.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,83 @@ | ||
/* | ||
* 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 com.facebook.presto.iceberg; | ||
|
||
import com.facebook.presto.common.Page; | ||
import com.facebook.presto.common.predicate.TupleDomain; | ||
import com.facebook.presto.iceberg.util.PageListBuilder; | ||
import com.facebook.presto.spi.ColumnMetadata; | ||
import com.facebook.presto.spi.ConnectorPageSource; | ||
import com.facebook.presto.spi.ConnectorSession; | ||
import com.facebook.presto.spi.ConnectorTableMetadata; | ||
import com.facebook.presto.spi.FixedPageSource; | ||
import com.facebook.presto.spi.SchemaTableName; | ||
import com.facebook.presto.spi.SystemTable; | ||
import com.facebook.presto.spi.connector.ConnectorTransactionHandle; | ||
import com.google.common.collect.ImmutableList; | ||
import org.apache.iceberg.Table; | ||
|
||
import java.util.List; | ||
|
||
import static com.facebook.presto.common.type.VarcharType.VARCHAR; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PropertiesTable | ||
implements SystemTable | ||
{ | ||
private final ConnectorTableMetadata tableMetadata; | ||
private final Table icebergTable; | ||
|
||
public PropertiesTable(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("key", VARCHAR)) | ||
.add(new ColumnMetadata("value", VARCHAR)) | ||
.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.properties().forEach((key, value) -> { | ||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(key); | ||
pagesBuilder.appendVarchar(value); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ public enum TableType | |
MANIFESTS, | ||
PARTITIONS, | ||
FILES, | ||
PROPERTIES, | ||
} |
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