Trino ConnectorMetadata.
| 99 | |
| 100 | /** Trino {@link ConnectorMetadata}. */ |
| 101 | public class TrinoMetadata implements ConnectorMetadata { |
| 102 | private static final String TAG_PREFIX = "tag-"; |
| 103 | |
| 104 | protected final TrinoCatalog catalog; |
| 105 | |
| 106 | public TrinoMetadata(TrinoCatalog catalog) { |
| 107 | this.catalog = catalog; |
| 108 | } |
| 109 | |
| 110 | public TrinoCatalog catalog() { |
| 111 | return catalog; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public Optional<ConnectorTableLayout> getInsertLayout( |
| 116 | ConnectorSession session, ConnectorTableHandle tableHandle) { |
| 117 | TrinoTableHandle trinoTableHandle = (TrinoTableHandle) tableHandle; |
| 118 | Table table = trinoTableHandle.table(catalog); |
| 119 | if (!(table instanceof FileStoreTable)) { |
| 120 | throw new IllegalArgumentException(table.getClass() + " is not supported"); |
| 121 | } |
| 122 | FileStoreTable storeTable = (FileStoreTable) table; |
| 123 | BucketMode bucketMode = storeTable.bucketMode(); |
| 124 | switch (bucketMode) { |
| 125 | case HASH_FIXED: |
| 126 | try { |
| 127 | return Optional.of( |
| 128 | new ConnectorTableLayout( |
| 129 | new TrinoPartitioningHandle( |
| 130 | InstantiationUtil.serializeObject(storeTable.schema())), |
| 131 | storeTable.schema().bucketKeys(), |
| 132 | false)); |
| 133 | } catch (IOException e) { |
| 134 | throw new RuntimeException(e); |
| 135 | } |
| 136 | case BUCKET_UNAWARE: |
| 137 | return Optional.empty(); |
| 138 | default: |
| 139 | throw new IllegalArgumentException("Unsupported table bucket mode: " + bucketMode); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public ConnectorOutputTableHandle beginCreateTable( |
| 145 | ConnectorSession session, |
| 146 | ConnectorTableMetadata tableMetadata, |
| 147 | Optional<ConnectorTableLayout> layout, |
| 148 | RetryMode retryMode, |
| 149 | boolean replace) { |
| 150 | if (replace) { |
| 151 | throw new UnsupportedOperationException("Create or replace table is not supported."); |
| 152 | } |
| 153 | createTable(session, tableMetadata, SaveMode.FAIL); |
| 154 | return getTableHandle(session, tableMetadata.getTable(), Collections.emptyMap()); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public Optional<ConnectorOutputMetadata> finishCreateTable( |
nothing calls this directly
no outgoing calls
no test coverage detected