Search in sources :

Example 1 with QualifiedObjectName

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

the class RaptorQueryRunner method copyTable.

private static void copyTable(QueryRunner queryRunner, String catalog, Session session, String schema, TpchTable<?> table, String properties) {
    QualifiedObjectName source = new QualifiedObjectName(catalog, schema, table.getTableName());
    String target = table.getTableName();
    String with = properties.isEmpty() ? "" : format(" WITH (%s)", properties);
    @Language("SQL") String sql = format("CREATE TABLE %s%s AS SELECT * FROM %s", target, with, source);
    log.info("Running import for %s", target);
    long start = System.nanoTime();
    long rows = queryRunner.execute(session, sql).getUpdateCount().getAsLong();
    log.info("Imported %s rows for %s in %s", rows, target, nanosSince(start));
}
Also used : Language(org.intellij.lang.annotations.Language) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 2 with QualifiedObjectName

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

the class PrestoSparkQueryRunner 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(com.facebook.presto.common.QualifiedObjectName)

Example 3 with QualifiedObjectName

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

the class MetadataManager method listViews.

@Override
public List<QualifiedObjectName> listViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> views = 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.listViews(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(views::add);
        }
    }
    return ImmutableList.copyOf(views);
}
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 4 with QualifiedObjectName

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

the class MetadataManager method getViews.

@Override
public Map<QualifiedObjectName, ViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, ViewDefinition> views = new LinkedHashMap<>();
    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, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                views.put(viewName, deserializeView(entry.getValue().getViewData()));
            }
        }
    }
    return ImmutableMap.copyOf(views);
}
Also used : ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) 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) LinkedHashMap(java.util.LinkedHashMap) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 5 with QualifiedObjectName

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

the class FunctionAndTypeManager method lookupFunction.

/**
 * Lookup up a function with name and fully bound types. This can only be used for builtin functions. {@link #resolveFunction(Optional, Optional, QualifiedObjectName, List)}
 * should be used for dynamically registered functions.
 *
 * @throws PrestoException if function could not be found
 */
public FunctionHandle lookupFunction(String name, List<TypeSignatureProvider> parameterTypes) {
    QualifiedObjectName functionName = qualifyObjectName(QualifiedName.of(name));
    if (parameterTypes.stream().noneMatch(TypeSignatureProvider::hasDependency)) {
        return lookupCachedFunction(functionName, parameterTypes);
    }
    Collection<? extends SqlFunction> candidates = builtInTypeAndFunctionNamespaceManager.getFunctions(Optional.empty(), functionName);
    Optional<Signature> match = functionSignatureMatcher.match(candidates, parameterTypes, false);
    if (!match.isPresent()) {
        throw new PrestoException(FUNCTION_NOT_FOUND, constructFunctionNotFoundErrorMessage(functionName, parameterTypes, candidates));
    }
    return builtInTypeAndFunctionNamespaceManager.getFunctionHandle(Optional.empty(), match.get());
}
Also used : TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) TypeSignature(com.facebook.presto.common.type.TypeSignature) LiteralEncoder.getMagicLiteralFunctionSignature(com.facebook.presto.sql.planner.LiteralEncoder.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) PrestoException(com.facebook.presto.spi.PrestoException) 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