use of io.trino.spi.connector.MaterializedViewNotFoundException in project trino by trinodb.
the class TrinoHiveCatalog method dropMaterializedView.
@Override
public void dropMaterializedView(ConnectorSession session, SchemaTableName schemaViewName) {
io.trino.plugin.hive.metastore.Table view = metastore.getTable(schemaViewName.getSchemaName(), schemaViewName.getTableName()).orElseThrow(() -> new MaterializedViewNotFoundException(schemaViewName));
String storageTableName = view.getParameters().get(STORAGE_TABLE);
if (storageTableName != null) {
try {
metastore.dropTable(schemaViewName.getSchemaName(), storageTableName, true);
} catch (TrinoException e) {
log.warn(e, "Failed to drop storage table '%s' for materialized view '%s'", storageTableName, schemaViewName);
}
}
metastore.dropTable(schemaViewName.getSchemaName(), schemaViewName.getTableName(), true);
}
use of io.trino.spi.connector.MaterializedViewNotFoundException in project trino by trinodb.
the class IcebergMetadata method getMaterializedViewFreshness.
@Override
public MaterializedViewFreshness getMaterializedViewFreshness(ConnectorSession session, SchemaTableName materializedViewName) {
Map<String, Optional<TableToken>> refreshStateMap = getMaterializedViewToken(session, materializedViewName);
if (refreshStateMap.isEmpty()) {
return new MaterializedViewFreshness(false);
}
for (Map.Entry<String, Optional<TableToken>> entry : refreshStateMap.entrySet()) {
List<String> strings = Splitter.on(".").splitToList(entry.getKey());
if (strings.size() == 3) {
strings = strings.subList(1, 3);
} else if (strings.size() != 2) {
throw new TrinoException(ICEBERG_INVALID_METADATA, format("Invalid table name in '%s' property: %s'", DEPENDS_ON_TABLES, strings));
}
String schema = strings.get(0);
String name = strings.get(1);
SchemaTableName schemaTableName = new SchemaTableName(schema, name);
IcebergTableHandle tableHandle = getTableHandle(session, schemaTableName);
if (tableHandle == null) {
throw new MaterializedViewNotFoundException(materializedViewName);
}
if (!isTableCurrent(session, tableHandle, entry.getValue())) {
return new MaterializedViewFreshness(false);
}
}
return new MaterializedViewFreshness(true);
}
use of io.trino.spi.connector.MaterializedViewNotFoundException in project trino by trinodb.
the class MaterializedViewSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = ((FullConnectorSession) connectorSession).getSession();
InMemoryRecordSet.Builder displayTable = InMemoryRecordSet.builder(getTableMetadata());
Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
listCatalogs(session, metadata, accessControl, catalogFilter).keySet().forEach(catalogName -> {
QualifiedTablePrefix tablePrefix = tablePrefix(catalogName, schemaFilter, tableFilter);
getMaterializedViews(session, metadata, accessControl, tablePrefix).forEach((tableName, definition) -> {
QualifiedObjectName name = new QualifiedObjectName(tablePrefix.getCatalogName(), tableName.getSchemaName(), tableName.getTableName());
MaterializedViewFreshness freshness;
try {
freshness = metadata.getMaterializedViewFreshness(session, name);
} catch (MaterializedViewNotFoundException e) {
// Ignore materialized view that was dropped during query execution (race condition)
return;
}
Object[] materializedViewRow = createMaterializedViewRow(name, freshness, definition);
displayTable.addRow(materializedViewRow);
});
});
return displayTable.build().cursor();
}
Aggregations