Search in sources :

Example 1 with MaterializedViewNotFoundException

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);
}
Also used : MaterializedViewNotFoundException(io.trino.spi.connector.MaterializedViewNotFoundException) TrinoException(io.trino.spi.TrinoException)

Example 2 with MaterializedViewNotFoundException

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);
}
Also used : Optional(java.util.Optional) MaterializedViewFreshness(io.trino.spi.connector.MaterializedViewFreshness) TrinoException(io.trino.spi.TrinoException) MaterializedViewNotFoundException(io.trino.spi.connector.MaterializedViewNotFoundException) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName)

Example 3 with MaterializedViewNotFoundException

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();
}
Also used : QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) MaterializedViewFreshness(io.trino.spi.connector.MaterializedViewFreshness) MaterializedViewNotFoundException(io.trino.spi.connector.MaterializedViewNotFoundException) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession)

Aggregations

MaterializedViewNotFoundException (io.trino.spi.connector.MaterializedViewNotFoundException)3 TrinoException (io.trino.spi.TrinoException)2 MaterializedViewFreshness (io.trino.spi.connector.MaterializedViewFreshness)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 FullConnectorSession (io.trino.FullConnectorSession)1 Session (io.trino.Session)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 QualifiedTablePrefix (io.trino.metadata.QualifiedTablePrefix)1 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 InMemoryRecordSet (io.trino.spi.connector.InMemoryRecordSet)1 SchemaTableName (io.trino.spi.connector.SchemaTableName)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1