Search in sources :

Example 46 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class TestMaterializedViewCandidateExtractor method testWithSimpleQuery.

@Test
public void testWithSimpleQuery() {
    String baseTable = "base_table_v0";
    QualifiedObjectName materializedViewName = QualifiedObjectName.valueOf("catalog.schema.view0");
    ImmutableSet<QualifiedObjectName> expectedMaterializedViewCandidates = ImmutableSet.of(materializedViewName);
    String baseQuerySql = format("SELECT x, y From %s", baseTable);
    assertCandidateMaterializedView(expectedMaterializedViewCandidates, baseQuerySql);
}
Also used : QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 47 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class MetadataManager method listTables.

@Override
public List<QualifiedObjectName> listTables(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> tables = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            metadata.listTables(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(tables::add);
        }
    }
    return ImmutableList.copyOf(tables);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 48 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class MetadataManager method listTableColumns.

@Override
public Map<QualifiedObjectName, List<ColumnMetadata>> listTableColumns(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, List<ColumnMetadata>> tableColumns = new HashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            for (Entry<SchemaTableName, List<ColumnMetadata>> entry : metadata.listTableColumns(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                tableColumns.put(tableName, entry.getValue());
            }
            // if table and view names overlap, the view wins
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
                for (ViewColumn column : deserializeView(entry.getValue().getViewData()).getColumns()) {
                    columns.add(new ColumnMetadata(column.getName(), column.getType()));
                }
                tableColumns.put(tableName, columns.build());
            }
        }
    }
    return ImmutableMap.copyOf(tableColumns);
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) SchemaTableName(com.facebook.presto.spi.SchemaTableName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 49 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testFunctionNameTooLong.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Function name exceeds max length of 256.*")
public void testFunctionNameTooLong() {
    QualifiedObjectName functionName = QualifiedObjectName.valueOf(TEST_CATALOG, TEST_SCHEMA, dummyString(257));
    createFunction(createFunctionTangent(functionName), false);
}
Also used : QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 50 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class UserDefinedTypeRowMapper method map.

@Override
public UserDefinedType map(ResultSet rs, StatementContext ctx) throws SQLException {
    QualifiedObjectName typeName = QualifiedObjectName.valueOf(rs.getString("catalog_name"), rs.getString("schema_name"), rs.getString("type_name"));
    String physicalType = rs.getString("physical_type");
    TypeSignature typeSignature = parseTypeSignature(physicalType);
    return new UserDefinedType(typeName, typeSignature);
}
Also used : TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.common.type.TypeSignature) UserDefinedType(com.facebook.presto.common.type.UserDefinedType) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Aggregations

QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)59 TableHandle (com.facebook.presto.spi.TableHandle)20 Metadata (com.facebook.presto.metadata.Metadata)15 Session (com.facebook.presto.Session)14 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)14 List (java.util.List)13 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)12 ConnectorId (com.facebook.presto.spi.ConnectorId)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 Map (java.util.Map)11 Objects.requireNonNull (java.util.Objects.requireNonNull)11 Optional (java.util.Optional)11 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)10 TransactionManager (com.facebook.presto.transaction.TransactionManager)10 Type (com.facebook.presto.common.type.Type)9 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 PrestoException (com.facebook.presto.spi.PrestoException)9 WarningCollector (com.facebook.presto.spi.WarningCollector)9 Expression (com.facebook.presto.sql.tree.Expression)9 ImmutableList (com.google.common.collect.ImmutableList)9