Search in sources :

Example 1 with MaterializedViewFreshness

use of io.trino.spi.connector.MaterializedViewFreshness in project trino by trinodb.

the class MetadataManager method getMaterializedViewFreshness.

@Override
public MaterializedViewFreshness getMaterializedViewFreshness(Session session, QualifiedObjectName viewName) {
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, viewName.getCatalogName());
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        CatalogName catalogName = catalogMetadata.getConnectorId(session, viewName);
        ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
        ConnectorSession connectorSession = session.toConnectorSession(catalogName);
        return metadata.getMaterializedViewFreshness(connectorSession, viewName.asSchemaTableName());
    }
    return new MaterializedViewFreshness(false);
}
Also used : MaterializedViewFreshness(io.trino.spi.connector.MaterializedViewFreshness) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 2 with MaterializedViewFreshness

use of io.trino.spi.connector.MaterializedViewFreshness 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 MaterializedViewFreshness

use of io.trino.spi.connector.MaterializedViewFreshness 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

MaterializedViewFreshness (io.trino.spi.connector.MaterializedViewFreshness)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)2 MaterializedViewNotFoundException (io.trino.spi.connector.MaterializedViewNotFoundException)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 CatalogName (io.trino.connector.CatalogName)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 QualifiedTablePrefix (io.trino.metadata.QualifiedTablePrefix)1 TrinoException (io.trino.spi.TrinoException)1 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)1 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)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