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));
}
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));
}
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);
}
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);
}
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());
}
Aggregations