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);
}
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);
}
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();
}
Aggregations