use of io.trino.FullConnectorSession 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();
}
use of io.trino.FullConnectorSession in project trino by trinodb.
the class ColumnJdbcTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Builder table = InMemoryRecordSet.builder(METADATA);
if (constraint.isNone()) {
return table.build().cursor();
}
Session session = ((FullConnectorSession) connectorSession).getSession();
boolean omitDateTimeTypePrecision = isOmitDateTimeTypePrecision(session);
Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
Domain catalogDomain = constraint.getDomains().get().getOrDefault(0, Domain.all(createUnboundedVarcharType()));
Domain schemaDomain = constraint.getDomains().get().getOrDefault(1, Domain.all(createUnboundedVarcharType()));
Domain tableDomain = constraint.getDomains().get().getOrDefault(2, Domain.all(createUnboundedVarcharType()));
if (isNonLowercase(schemaFilter) || isNonLowercase(tableFilter)) {
// Non-lowercase predicate will never match a lowercase name (until TODO https://github.com/trinodb/trino/issues/17)
return table.build().cursor();
}
for (String catalog : listCatalogs(session, metadata, accessControl, catalogFilter).keySet()) {
if (!catalogDomain.includesNullableValue(utf8Slice(catalog))) {
continue;
}
if ((schemaDomain.isAll() && tableDomain.isAll()) || schemaFilter.isPresent()) {
QualifiedTablePrefix tablePrefix = tablePrefix(catalog, schemaFilter, tableFilter);
Map<SchemaTableName, List<ColumnMetadata>> tableColumns = listTableColumns(session, metadata, accessControl, tablePrefix);
addColumnsRow(table, catalog, tableColumns, omitDateTimeTypePrecision);
} else {
Collection<String> schemas = listSchemas(session, metadata, accessControl, catalog, schemaFilter);
for (String schema : schemas) {
if (!schemaDomain.includesNullableValue(utf8Slice(schema))) {
continue;
}
QualifiedTablePrefix tablePrefix = tableFilter.isPresent() ? new QualifiedTablePrefix(catalog, schema, tableFilter.get()) : new QualifiedTablePrefix(catalog, schema);
Set<SchemaTableName> tables = listTables(session, metadata, accessControl, tablePrefix);
for (SchemaTableName schemaTableName : tables) {
String tableName = schemaTableName.getTableName();
if (!tableDomain.includesNullableValue(utf8Slice(tableName))) {
continue;
}
Map<SchemaTableName, List<ColumnMetadata>> tableColumns = listTableColumns(session, metadata, accessControl, new QualifiedTablePrefix(catalog, schema, tableName));
addColumnsRow(table, catalog, tableColumns, omitDateTimeTypePrecision);
}
}
}
}
return table.build().cursor();
}
use of io.trino.FullConnectorSession in project trino by trinodb.
the class TableJdbcTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
Optional<String> typeFilter = tryGetSingleVarcharValue(constraint, 3);
boolean includeTables = emptyOrEquals(typeFilter, "TABLE");
boolean includeViews = emptyOrEquals(typeFilter, "VIEW");
Builder table = InMemoryRecordSet.builder(METADATA);
if (!includeTables && !includeViews) {
return table.build().cursor();
}
if (isNonLowercase(schemaFilter) || isNonLowercase(tableFilter)) {
// Non-lowercase predicate will never match a lowercase name (until TODO https://github.com/trinodb/trino/issues/17)
return table.build().cursor();
}
for (String catalog : listCatalogs(session, metadata, accessControl, catalogFilter).keySet()) {
QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
Set<SchemaTableName> views = listViews(session, metadata, accessControl, prefix);
for (SchemaTableName name : listTables(session, metadata, accessControl, prefix)) {
boolean isView = views.contains(name);
if ((includeTables && !isView) || (includeViews && isView)) {
table.addRow(tableRow(catalog, name, isView ? "VIEW" : "TABLE"));
}
}
}
return table.build().cursor();
}
Aggregations