|
69 | 69 | import java.util.Set;
|
70 | 70 | import java.util.stream.Stream;
|
71 | 71 |
|
| 72 | +import static com.google.common.base.Preconditions.checkArgument; |
72 | 73 | import static com.google.common.base.Throwables.throwIfUnchecked;
|
73 | 74 | import static com.google.common.collect.ImmutableList.toImmutableList;
|
74 | 75 | import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
|
79 | 80 | import static io.trino.plugin.hive.metastore.glue.converter.GlueToTrinoConverter.mappedCopy;
|
80 | 81 | import static io.trino.plugin.hive.util.HiveUtil.escapeTableName;
|
81 | 82 | import static io.trino.plugin.iceberg.IcebergErrorCode.ICEBERG_FILESYSTEM_ERROR;
|
82 |
| -import static io.trino.plugin.iceberg.IcebergErrorCode.ICEBERG_INVALID_METADATA; |
83 | 83 | import static io.trino.plugin.iceberg.IcebergMaterializedViewDefinition.decodeMaterializedViewData;
|
84 |
| -import static io.trino.plugin.iceberg.IcebergMaterializedViewProperties.STORAGE_SCHEMA; |
85 |
| -import static io.trino.plugin.iceberg.IcebergMaterializedViewProperties.getStorageSchema; |
| 84 | +import static io.trino.plugin.iceberg.IcebergMaterializedViewProperties.isSeparateStorageTable; |
86 | 85 | import static io.trino.plugin.iceberg.IcebergTableName.tableNameWithType;
|
87 | 86 | import static io.trino.plugin.iceberg.IcebergTableProperties.getPartitioning;
|
88 | 87 | import static io.trino.plugin.iceberg.IcebergTableProperties.getSortOrder;
|
|
97 | 96 | import static io.trino.plugin.iceberg.SortFieldUtils.parseSortFields;
|
98 | 97 | import static io.trino.plugin.iceberg.TableType.MATERIALIZED_VIEW_STORAGE;
|
99 | 98 | import static io.trino.plugin.iceberg.TypeConverter.toTrinoType;
|
100 |
| -import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED; |
101 | 99 | import static io.trino.spi.StandardErrorCode.TABLE_NOT_FOUND;
|
102 | 100 | import static io.trino.spi.type.IntegerType.INTEGER;
|
103 | 101 | import static io.trino.spi.type.SmallintType.SMALLINT;
|
@@ -211,16 +209,9 @@ public Optional<ConnectorMaterializedViewDefinition> getMaterializedView(Connect
|
211 | 209 | @Override
|
212 | 210 | public Map<String, Object> getMaterializedViewProperties(ConnectorSession session, SchemaTableName viewName, ConnectorMaterializedViewDefinition definition)
|
213 | 211 | {
|
214 |
| - SchemaTableName storageTableName = definition.getStorageTable() |
215 |
| - .orElseThrow(() -> new TrinoException(ICEBERG_INVALID_METADATA, "Materialized view definition is missing a storage table")) |
216 |
| - .getSchemaTableName(); |
217 |
| - |
218 | 212 | try {
|
219 | 213 | Table storageTable = loadTable(session, definition.getStorageTable().orElseThrow().getSchemaTableName());
|
220 |
| - return ImmutableMap.<String, Object>builder() |
221 |
| - .putAll(getIcebergTableProperties(storageTable)) |
222 |
| - .put(STORAGE_SCHEMA, storageTableName.getSchemaName()) |
223 |
| - .buildOrThrow(); |
| 214 | + return getIcebergTableProperties(storageTable); |
224 | 215 | }
|
225 | 216 | catch (RuntimeException e) {
|
226 | 217 | throw new TrinoException(ICEBERG_FILESYSTEM_ERROR, "Unable to load storage table metadata for materialized view: " + viewName);
|
@@ -313,9 +304,7 @@ protected Location createMaterializedViewStorage(
|
313 | 304 | ConnectorMaterializedViewDefinition definition,
|
314 | 305 | Map<String, Object> materializedViewProperties)
|
315 | 306 | {
|
316 |
| - if (getStorageSchema(materializedViewProperties).isPresent()) { |
317 |
| - throw new TrinoException(NOT_SUPPORTED, "Materialized view property '%s' is not supported when hiding materialized view storage tables is enabled".formatted(STORAGE_SCHEMA)); |
318 |
| - } |
| 307 | + checkArgument(!isSeparateStorageTable(materializedViewProperties), "Invalid request to create hidden materialized view storage table when separate storage table is requested"); |
319 | 308 | SchemaTableName storageTableName = new SchemaTableName(viewName.getSchemaName(), tableNameWithType(viewName.getTableName(), MATERIALIZED_VIEW_STORAGE));
|
320 | 309 | String tableLocation = getTableLocation(materializedViewProperties)
|
321 | 310 | .orElseGet(() -> defaultTableLocation(session, viewName));
|
@@ -355,7 +344,7 @@ protected SchemaTableName createMaterializedViewStorageTable(
|
355 | 344 | // storage table as indicated in the materialized view definition.
|
356 | 345 | String storageTableName = "st_" + randomUUID().toString().replace("-", "");
|
357 | 346 |
|
358 |
| - String storageSchema = getStorageSchema(materializedViewProperties).orElse(viewName.getSchemaName()); |
| 347 | + String storageSchema = viewName.getSchemaName(); |
359 | 348 | SchemaTableName storageTable = new SchemaTableName(storageSchema, storageTableName);
|
360 | 349 | List<ColumnMetadata> columns = columnsForMaterializedView(definition, materializedViewProperties);
|
361 | 350 |
|
@@ -494,7 +483,6 @@ protected Map<String, String> createMaterializedViewProperties(ConnectorSession
|
494 | 483 | {
|
495 | 484 | return ImmutableMap.<String, String>builder()
|
496 | 485 | .put(TRINO_QUERY_ID_NAME, session.getQueryId())
|
497 |
| - .put(STORAGE_SCHEMA, storageTableName.getSchemaName()) |
498 | 486 | .put(STORAGE_TABLE, storageTableName.getTableName())
|
499 | 487 | .put(PRESTO_VIEW_FLAG, "true")
|
500 | 488 | .put(TRINO_CREATED_BY, TRINO_CREATED_BY_VALUE)
|
|
0 commit comments