Skip to content

Commit 30137d9

Browse files
committed
Resolve rebase conflicts
1 parent 329286a commit 30137d9

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,47 +1690,47 @@ public void createMaterializedView(
16901690
materializedViewProperties,
16911691
viewMetadata.getComment());
16921692

1693-
try {
1694-
Map<String, String> properties = new HashMap<>();
1695-
properties.put(PRESTO_MATERIALIZED_VIEW_FORMAT_VERSION, CURRENT_MATERIALIZED_VIEW_FORMAT_VERSION + "");
1696-
properties.put(PRESTO_MATERIALIZED_VIEW_ORIGINAL_SQL, viewDefinition.getOriginalSql());
1697-
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_SCHEMA, storageTableName.getSchemaName());
1698-
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_TABLE_NAME, storageTableName.getTableName());
1699-
1700-
String baseTablesStr = serializeSchemaTableNames(viewDefinition.getBaseTables());
1701-
properties.put(PRESTO_MATERIALIZED_VIEW_BASE_TABLES, baseTablesStr);
1702-
properties.put(PRESTO_MATERIALIZED_VIEW_COLUMN_MAPPINGS, serializeColumnMappings(viewDefinition.getColumnMappings()));
1703-
properties.put(PRESTO_MATERIALIZED_VIEW_OWNER, viewDefinition.getOwner()
1704-
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view owner is required")));
1705-
properties.put(PRESTO_MATERIALIZED_VIEW_SECURITY_MODE, viewDefinition.getSecurityMode()
1706-
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view security mode is required (set legacy_materialized_views=false)"))
1707-
.name());
1708-
1709-
getStaleReadBehavior(materializedViewProperties)
1710-
.ifPresent(behavior -> properties.put(PRESTO_MATERIALIZED_VIEW_STALE_READ_BEHAVIOR, behavior.name()));
1711-
getStalenessWindow(materializedViewProperties)
1712-
.ifPresent(window -> properties.put(PRESTO_MATERIALIZED_VIEW_STALENESS_WINDOW, window.toString()));
1713-
MaterializedViewRefreshType refreshType = getRefreshType(materializedViewProperties);
1714-
properties.put(PRESTO_MATERIALIZED_VIEW_REFRESH_TYPE, refreshType.name());
1715-
1716-
for (SchemaTableName baseTable : viewDefinition.getBaseTables()) {
1717-
properties.put(getBaseTableViewPropertyName(baseTable), "0");
1718-
}
1719-
1720-
createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties);
1721-
// Create materialized view should run after the creation of the underlying storage table
1722-
/*transactionContext.registerCallback(() -> createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties));
1723-
createTable(session, storageTableMetadata, false);*/
1724-
}
1725-
catch (Exception e) {
1693+
// Create materialized view should run after the creation of the underlying storage table
1694+
transactionContext.registerCallback(() -> {
17261695
try {
1727-
dropStorageTable(session, storageTableName);
1696+
Map<String, String> properties = new HashMap<>();
1697+
properties.put(PRESTO_MATERIALIZED_VIEW_FORMAT_VERSION, CURRENT_MATERIALIZED_VIEW_FORMAT_VERSION + "");
1698+
properties.put(PRESTO_MATERIALIZED_VIEW_ORIGINAL_SQL, viewDefinition.getOriginalSql());
1699+
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_SCHEMA, storageTableName.getSchemaName());
1700+
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_TABLE_NAME, storageTableName.getTableName());
1701+
1702+
String baseTablesStr = serializeSchemaTableNames(viewDefinition.getBaseTables());
1703+
properties.put(PRESTO_MATERIALIZED_VIEW_BASE_TABLES, baseTablesStr);
1704+
properties.put(PRESTO_MATERIALIZED_VIEW_COLUMN_MAPPINGS, serializeColumnMappings(viewDefinition.getColumnMappings()));
1705+
properties.put(PRESTO_MATERIALIZED_VIEW_OWNER, viewDefinition.getOwner()
1706+
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view owner is required")));
1707+
properties.put(PRESTO_MATERIALIZED_VIEW_SECURITY_MODE, viewDefinition.getSecurityMode()
1708+
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view security mode is required (set legacy_materialized_views=false)"))
1709+
.name());
1710+
1711+
getStaleReadBehavior(materializedViewProperties)
1712+
.ifPresent(behavior -> properties.put(PRESTO_MATERIALIZED_VIEW_STALE_READ_BEHAVIOR, behavior.name()));
1713+
getStalenessWindow(materializedViewProperties)
1714+
.ifPresent(window -> properties.put(PRESTO_MATERIALIZED_VIEW_STALENESS_WINDOW, window.toString()));
1715+
MaterializedViewRefreshType refreshType = getRefreshType(materializedViewProperties);
1716+
properties.put(PRESTO_MATERIALIZED_VIEW_REFRESH_TYPE, refreshType.name());
1717+
1718+
for (SchemaTableName baseTable : viewDefinition.getBaseTables()) {
1719+
properties.put(getBaseTableViewPropertyName(baseTable), "0");
1720+
}
1721+
createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties);
17281722
}
1729-
catch (Exception cleanupException) {
1730-
e.addSuppressed(cleanupException);
1723+
catch (Exception e) {
1724+
try {
1725+
dropStorageTable(session, storageTableName);
1726+
}
1727+
catch (Exception cleanupException) {
1728+
e.addSuppressed(cleanupException);
1729+
}
1730+
throw e;
17311731
}
1732-
throw e;
1733-
}
1732+
});
1733+
createTable(session, storageTableMetadata, false);
17341734
}
17351735
catch (PrestoException e) {
17361736
if (e.getErrorCode() == NOT_SUPPORTED.toErrorCode()) {
@@ -1848,6 +1848,7 @@ public Optional<MaterializedViewDefinition> getMaterializedView(ConnectorSession
18481848
@Override
18491849
public void dropMaterializedView(ConnectorSession session, SchemaTableName viewName)
18501850
{
1851+
shouldRunInAutoCommitTransaction("DROP MATERIALIZED VIEW");
18511852
Optional<MaterializedViewDefinition> definition = getMaterializedView(session, viewName);
18521853

18531854
if (definition.isPresent()) {
@@ -1936,6 +1937,7 @@ public ConnectorInsertTableHandle beginRefreshMaterializedView(
19361937
ConnectorSession session,
19371938
ConnectorTableHandle tableHandle)
19381939
{
1940+
shouldRunInAutoCommitTransaction("REFRESH MATERIALIZED VIEW");
19391941
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
19401942

19411943
if (icebergTableHandle.getMaterializedViewName().isEmpty()) {

presto-iceberg/src/main/java/com/facebook/presto/iceberg/procedure/RewriteManifestsProcedure.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
*/
1414
package com.facebook.presto.iceberg.procedure;
1515

16+
import com.facebook.presto.iceberg.IcebergAbstractMetadata;
1617
import com.facebook.presto.iceberg.IcebergMetadataFactory;
1718
import com.facebook.presto.spi.ConnectorSession;
1819
import com.facebook.presto.spi.PrestoException;
1920
import com.facebook.presto.spi.SchemaTableName;
2021
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
21-
import com.facebook.presto.spi.connector.ConnectorMetadata;
2222
import com.facebook.presto.spi.procedure.Procedure;
2323
import com.facebook.presto.spi.procedure.Procedure.Argument;
2424
import com.google.common.collect.ImmutableList;
@@ -73,7 +73,7 @@ public void rewriteManifests(ConnectorSession clientSession, String schemaName,
7373
{
7474
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
7575
SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
76-
ConnectorMetadata metadata = metadataFactory.create();
76+
IcebergAbstractMetadata metadata = (IcebergAbstractMetadata) metadataFactory.create();
7777
Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);
7878
RewriteManifests rewriteManifests = icebergTable.rewriteManifests().clusterBy(file -> "file");
7979
int targetSpecId;
@@ -87,6 +87,7 @@ public void rewriteManifests(ConnectorSession clientSession, String schemaName,
8787
targetSpecId = icebergTable.spec().specId();
8888
}
8989
rewriteManifests.rewriteIf(manifest -> manifest.partitionSpecId() == targetSpecId).commit();
90+
metadata.commit();
9091
}
9192
}
9293
}

0 commit comments

Comments
 (0)