use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.
the class TableCommentSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Optional<String> catalogFilter = stringFilter(constraint, 0);
Optional<String> schemaFilter = stringFilter(constraint, 1);
Optional<String> tableFilter = stringFilter(constraint, 2);
Session session = toSession(transactionHandle, connectorSession);
Builder table = InMemoryRecordSet.builder(COMMENT_TABLE);
for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
Set<SchemaTableName> names = ImmutableSet.of();
try {
names = listTables(session, metadata, accessControl, prefix);
} catch (PrestoException e) {
// listTables throws an exception if cannot connect the database
LOG.debug(e, "Failed to get tables for catalog: %s", catalog);
}
for (SchemaTableName name : names) {
QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), name.getSchemaName(), name.getTableName());
Optional<String> comment = Optional.empty();
try {
comment = metadata.getTableHandle(session, tableName).map(handle -> metadata.getTableMetadata(session, handle)).map(metadata -> metadata.getMetadata().getComment()).get();
} catch (PrestoException e) {
// getTableHandle may throw an exception (e.g. Cassandra connector doesn't allow case insensitive column names)
LOG.debug(e, "Failed to get metadata for table: %s", name);
}
table.addRow(prefix.getCatalogName(), name.getSchemaName(), name.getTableName(), comment.orElse(null));
}
}
return table.build().cursor();
}
use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.
the class InformationSchemaMetadata method calculatePrefixesWithSchemaName.
private Set<QualifiedTablePrefix> calculatePrefixesWithSchemaName(ConnectorSession connectorSession, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
Optional<Set<String>> schemas = filterString(constraint, SCHEMA_COLUMN_HANDLE);
if (schemas.isPresent()) {
return schemas.get().stream().filter(this::isLowerCase).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
}
Session session = ((FullConnectorSession) connectorSession).getSession();
return metadata.listSchemaNames(session, catalogName).stream().filter(schema -> !predicate.isPresent() || predicate.get().test(schemaAsFixedValues(schema))).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
}
use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.
the class InformationSchemaPageSourceProvider method getInternalTable.
private InternalTable getInternalTable(ConnectorSession connectorSession, ConnectorTableHandle tablehandle) {
Session session = ((FullConnectorSession) connectorSession).getSession();
InformationSchemaTableHandle handle = (InformationSchemaTableHandle) tablehandle;
Set<QualifiedTablePrefix> prefixes = handle.getPrefixes();
return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), prefixes);
}
use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.
the class InformationSchemaMetadata method calculatePrefixesWithTableName.
public Set<QualifiedTablePrefix> calculatePrefixesWithTableName(ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE);
if (tables.isPresent()) {
return prefixes.stream().flatMap(prefix -> tables.get().stream().filter(this::isLowerCase).map(table -> table.toLowerCase(ENGLISH)).map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))).filter(objectName -> metadata.getTableHandle(session, objectName).isPresent() || metadata.getView(session, objectName).isPresent()).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
}
return prefixes.stream().flatMap(prefix -> Stream.concat(metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())).filter(objectName -> !predicate.isPresent() || predicate.get().test(asFixedValues(objectName))).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
}
use of io.prestosql.metadata.QualifiedTablePrefix in project hetu-core by openlookeng.
the class InformationSchemaPageSourceProvider method buildColumns.
private InternalTable buildColumns(Session session, Set<QualifiedTablePrefix> prefixes) {
InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_COLUMNS));
for (QualifiedTablePrefix prefix : prefixes) {
for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) {
SchemaTableName tableName = entry.getKey();
int ordinalPosition = 1;
for (ColumnMetadata column : entry.getValue()) {
if (column.isHidden()) {
continue;
}
table.add(prefix.getCatalogName(), tableName.getSchemaName(), tableName.getTableName(), column.getName(), ordinalPosition, null, "YES", column.getType().getDisplayName(), column.getComment(), column.getExtraInfo(), column.getComment());
ordinalPosition++;
}
}
}
return table.build();
}
Aggregations