Skip to content

Commit 92a9cfb

Browse files
committed
Resolve rebase conflicts
1 parent 1c545cc commit 92a9cfb

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
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
@@ -1644,47 +1644,47 @@ public void createMaterializedView(
16441644
materializedViewProperties,
16451645
viewMetadata.getComment());
16461646

1647-
try {
1648-
Map<String, String> properties = new HashMap<>();
1649-
properties.put(PRESTO_MATERIALIZED_VIEW_FORMAT_VERSION, CURRENT_MATERIALIZED_VIEW_FORMAT_VERSION + "");
1650-
properties.put(PRESTO_MATERIALIZED_VIEW_ORIGINAL_SQL, viewDefinition.getOriginalSql());
1651-
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_SCHEMA, storageTableName.getSchemaName());
1652-
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_TABLE_NAME, storageTableName.getTableName());
1653-
1654-
String baseTablesStr = serializeSchemaTableNames(viewDefinition.getBaseTables());
1655-
properties.put(PRESTO_MATERIALIZED_VIEW_BASE_TABLES, baseTablesStr);
1656-
properties.put(PRESTO_MATERIALIZED_VIEW_COLUMN_MAPPINGS, serializeColumnMappings(viewDefinition.getColumnMappings()));
1657-
properties.put(PRESTO_MATERIALIZED_VIEW_OWNER, viewDefinition.getOwner()
1658-
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view owner is required")));
1659-
properties.put(PRESTO_MATERIALIZED_VIEW_SECURITY_MODE, viewDefinition.getSecurityMode()
1660-
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view security mode is required (set legacy_materialized_views=false)"))
1661-
.name());
1662-
1663-
getStaleReadBehavior(materializedViewProperties)
1664-
.ifPresent(behavior -> properties.put(PRESTO_MATERIALIZED_VIEW_STALE_READ_BEHAVIOR, behavior.name()));
1665-
getStalenessWindow(materializedViewProperties)
1666-
.ifPresent(window -> properties.put(PRESTO_MATERIALIZED_VIEW_STALENESS_WINDOW, window.toString()));
1667-
MaterializedViewRefreshType refreshType = getRefreshType(materializedViewProperties);
1668-
properties.put(PRESTO_MATERIALIZED_VIEW_REFRESH_TYPE, refreshType.name());
1669-
1670-
for (SchemaTableName baseTable : viewDefinition.getBaseTables()) {
1671-
properties.put(getBaseTableViewPropertyName(baseTable), "0");
1672-
}
1673-
1674-
createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties);
1675-
// Create materialized view should run after the creation of the underlying storage table
1676-
/*transactionContext.registerCallback(() -> createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties));
1677-
createTable(session, storageTableMetadata, false);*/
1678-
}
1679-
catch (Exception e) {
1647+
// Create materialized view should run after the creation of the underlying storage table
1648+
transactionContext.registerCallback(() -> {
16801649
try {
1681-
dropStorageTable(session, storageTableName);
1650+
Map<String, String> properties = new HashMap<>();
1651+
properties.put(PRESTO_MATERIALIZED_VIEW_FORMAT_VERSION, CURRENT_MATERIALIZED_VIEW_FORMAT_VERSION + "");
1652+
properties.put(PRESTO_MATERIALIZED_VIEW_ORIGINAL_SQL, viewDefinition.getOriginalSql());
1653+
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_SCHEMA, storageTableName.getSchemaName());
1654+
properties.put(PRESTO_MATERIALIZED_VIEW_STORAGE_TABLE_NAME, storageTableName.getTableName());
1655+
1656+
String baseTablesStr = serializeSchemaTableNames(viewDefinition.getBaseTables());
1657+
properties.put(PRESTO_MATERIALIZED_VIEW_BASE_TABLES, baseTablesStr);
1658+
properties.put(PRESTO_MATERIALIZED_VIEW_COLUMN_MAPPINGS, serializeColumnMappings(viewDefinition.getColumnMappings()));
1659+
properties.put(PRESTO_MATERIALIZED_VIEW_OWNER, viewDefinition.getOwner()
1660+
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view owner is required")));
1661+
properties.put(PRESTO_MATERIALIZED_VIEW_SECURITY_MODE, viewDefinition.getSecurityMode()
1662+
.orElseThrow(() -> new PrestoException(INVALID_VIEW, "Materialized view security mode is required (set legacy_materialized_views=false)"))
1663+
.name());
1664+
1665+
getStaleReadBehavior(materializedViewProperties)
1666+
.ifPresent(behavior -> properties.put(PRESTO_MATERIALIZED_VIEW_STALE_READ_BEHAVIOR, behavior.name()));
1667+
getStalenessWindow(materializedViewProperties)
1668+
.ifPresent(window -> properties.put(PRESTO_MATERIALIZED_VIEW_STALENESS_WINDOW, window.toString()));
1669+
MaterializedViewRefreshType refreshType = getRefreshType(materializedViewProperties);
1670+
properties.put(PRESTO_MATERIALIZED_VIEW_REFRESH_TYPE, refreshType.name());
1671+
1672+
for (SchemaTableName baseTable : viewDefinition.getBaseTables()) {
1673+
properties.put(getBaseTableViewPropertyName(baseTable), "0");
1674+
}
1675+
createIcebergView(session, viewName, viewMetadata.getColumns(), viewDefinition.getOriginalSql(), properties);
16821676
}
1683-
catch (Exception cleanupException) {
1684-
e.addSuppressed(cleanupException);
1677+
catch (Exception e) {
1678+
try {
1679+
dropStorageTable(session, storageTableName);
1680+
}
1681+
catch (Exception cleanupException) {
1682+
e.addSuppressed(cleanupException);
1683+
}
1684+
throw e;
16851685
}
1686-
throw e;
1687-
}
1686+
});
1687+
createTable(session, storageTableMetadata, false);
16881688
}
16891689
catch (PrestoException e) {
16901690
if (e.getErrorCode() == NOT_SUPPORTED.toErrorCode()) {
@@ -1802,6 +1802,7 @@ public Optional<MaterializedViewDefinition> getMaterializedView(ConnectorSession
18021802
@Override
18031803
public void dropMaterializedView(ConnectorSession session, SchemaTableName viewName)
18041804
{
1805+
shouldRunInAutoCommitTransaction("DROP MATERIALIZED VIEW");
18051806
Optional<MaterializedViewDefinition> definition = getMaterializedView(session, viewName);
18061807

18071808
if (definition.isPresent()) {
@@ -1890,6 +1891,7 @@ public ConnectorInsertTableHandle beginRefreshMaterializedView(
18901891
ConnectorSession session,
18911892
ConnectorTableHandle tableHandle)
18921893
{
1894+
shouldRunInAutoCommitTransaction("REFRESH MATERIALIZED VIEW");
18931895
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
18941896

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

0 commit comments

Comments
 (0)