Search in sources :

Example 21 with QualifiedObjectName

use of io.prestosql.spi.connector.QualifiedObjectName in project hetu-core by openlookeng.

the class MetadataManager method getViews.

@Override
public Map<QualifiedObjectName, ConnectorViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, ConnectorViewDefinition> views = new LinkedHashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            Map<SchemaTableName, ConnectorViewDefinition> viewMap;
            if (tablePrefix.getTable().isPresent()) {
                viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
            } else {
                viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
            }
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : viewMap.entrySet()) {
                QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                views.put(viewName, entry.getValue());
            }
        }
    }
    return ImmutableMap.copyOf(views);
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) MetadataUtil.toSchemaTableName(io.prestosql.metadata.MetadataUtil.toSchemaTableName) MetadataUtil.convertFromSchemaTableName(io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) LinkedHashMap(java.util.LinkedHashMap) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Example 22 with QualifiedObjectName

use of io.prestosql.spi.connector.QualifiedObjectName in project hetu-core by openlookeng.

the class MetadataUtil method createQualifiedObjectName.

public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name) {
    requireNonNull(session, "session is null");
    requireNonNull(name, "name is null");
    // Hetu supports cluster so that there can be 4 dots in <cluster>.<catalog>.<schema>.<table>
    if (name.getParts().size() > 4) {
        throw new PrestoException(SYNTAX_ERROR, format("Too many dots in table name: %s", name));
    }
    List<String> parts = Lists.reverse(name.getParts());
    String objectName = parts.get(0);
    String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema().orElseThrow(() -> new SemanticException(SCHEMA_NOT_SPECIFIED, node, "Schema must be specified when session schema is not set"));
    String catalogName;
    // If there are 4 dots, combine the first two components into one and use it as catalog
    if (parts.size() > 3) {
        catalogName = (parts.size() > 3) ? parts.get(3) + "." + parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
    } else {
        catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
    }
    return new QualifiedObjectName(catalogName, schemaName, objectName);
}
Also used : PrestoException(io.prestosql.spi.PrestoException) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 23 with QualifiedObjectName

use of io.prestosql.spi.connector.QualifiedObjectName in project hetu-core by openlookeng.

the class HiveQueryRunner method copyTpchTablesBucketed.

public static void copyTpchTablesBucketed(QueryRunner queryRunner, String sourceCatalog, String sourceSchema, Session session, Iterable<TpchTable<?>> tables) {
    log.info("Loading data from %s.%s...", sourceCatalog, sourceSchema);
    long startTime = System.nanoTime();
    for (TpchTable<?> table : tables) {
        copyTableBucketed(queryRunner, new QualifiedObjectName(sourceCatalog, sourceSchema, table.getTableName().toLowerCase(ENGLISH)), session);
    }
    log.info("Loading from %s.%s complete in %s", sourceCatalog, sourceSchema, nanosSince(startTime).toString(SECONDS));
}
Also used : QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Example 24 with QualifiedObjectName

use of io.prestosql.spi.connector.QualifiedObjectName in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method getHiveInsertTableHandle.

private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName) {
    getQueryRunner().getMetadata().cleanupQuery(session);
    Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
    return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
        QualifiedObjectName objectName = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
        Optional<TableHandle> handle = metadata.getTableHandle(transactionSession, objectName);
        InsertTableHandle insertTableHandle = metadata.beginInsert(transactionSession, handle.get(), false);
        HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle();
        metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of());
        return hiveInsertTableHandle;
    });
}
Also used : Metadata(io.prestosql.metadata.Metadata) TableMetadata(io.prestosql.metadata.TableMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) InsertTableHandle(io.prestosql.metadata.InsertTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) InsertTableHandle(io.prestosql.metadata.InsertTableHandle)

Example 25 with QualifiedObjectName

use of io.prestosql.spi.connector.QualifiedObjectName in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method getTableMetadata.

private TableMetadata getTableMetadata(String catalog, String schema, String tableName) {
    Session session = getSession();
    Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
    return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
        Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, schema, tableName));
        assertTrue(tableHandle.isPresent());
        return metadata.getTableMetadata(transactionSession, tableHandle.get());
    });
}
Also used : Metadata(io.prestosql.metadata.Metadata) TableMetadata(io.prestosql.metadata.TableMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) InsertTableHandle(io.prestosql.metadata.InsertTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Session(io.prestosql.Session) ConnectorSession(io.prestosql.spi.connector.ConnectorSession)

Aggregations

QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)97 Test (org.testng.annotations.Test)45 Session (io.prestosql.Session)29 TableHandle (io.prestosql.spi.metadata.TableHandle)26 ViewExpression (io.prestosql.spi.security.ViewExpression)25 Metadata (io.prestosql.metadata.Metadata)18 PrestoException (io.prestosql.spi.PrestoException)18 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)17 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)16 SemanticException (io.prestosql.sql.analyzer.SemanticException)16 Map (java.util.Map)13 CatalogName (io.prestosql.spi.connector.CatalogName)12 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)12 ImmutableList (com.google.common.collect.ImmutableList)11 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)11 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)11 Optional (java.util.Optional)11 TableMetadata (io.prestosql.metadata.TableMetadata)10 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)10 ArrayList (java.util.ArrayList)10