本文整理了Java中com.facebook.presto.metadata.Metadata.getTableHandle()
方法的一些代码示例,展示了Metadata.getTableHandle()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getTableHandle()
方法的具体详情如下:
包路径:com.facebook.presto.metadata.Metadata
类名称:Metadata
方法名:getTableHandle
[英]Returns a table handle for the specified table name.
[中]
代码示例来源:origin: prestodb/presto
private TableHandle getTableHandle(ShowStats node, QualifiedName table)
{
QualifiedObjectName qualifiedTableName = createQualifiedObjectName(session, node, table);
return metadata.getTableHandle(session, qualifiedTableName)
.orElseThrow(() -> new SemanticException(MISSING_TABLE, node, "Table %s not found", table));
}
代码示例来源:origin: prestodb/presto
public static boolean tableExists(Metadata metadata, Session session, String table)
{
if (!session.getCatalog().isPresent() || !session.getSchema().isPresent()) {
return false;
}
QualifiedObjectName name = new QualifiedObjectName(session.getCatalog().get(), session.getSchema().get(), table);
return metadata.getTableHandle(session, name).isPresent();
}
代码示例来源:origin: prestodb/presto
protected final List<Type> getColumnTypes(String tableName, String... columnNames)
{
checkState(session.getCatalog().isPresent(), "catalog not set");
checkState(session.getSchema().isPresent(), "schema not set");
// look up the table
Metadata metadata = localQueryRunner.getMetadata();
QualifiedObjectName qualifiedTableName = new QualifiedObjectName(session.getCatalog().get(), session.getSchema().get(), tableName);
TableHandle tableHandle = metadata.getTableHandle(session, qualifiedTableName)
.orElseThrow(() -> new IllegalArgumentException(format("Table %s does not exist", qualifiedTableName)));
Map<String, ColumnHandle> allColumnHandles = metadata.getColumnHandles(session, tableHandle);
return Arrays.stream(columnNames)
.map(allColumnHandles::get)
.map(columnHandle -> metadata.getColumnMetadata(session, tableHandle, columnHandle).getType())
.collect(toImmutableList());
}
代码示例来源:origin: prestodb/presto
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(QualifiedObjectName::asQualifiedTablePrefix)
.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(QualifiedObjectName::asQualifiedTablePrefix)
.collect(toImmutableSet());
}
代码示例来源:origin: prestodb/presto
@Override
public ListenableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
return immediateFuture(null);
}
accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);
metadata.dropTable(session, tableHandle.get());
return immediateFuture(null);
}
}
代码示例来源:origin: prestodb/presto
public void dropTable(String tableName)
{
Session session = localQueryRunner.getDefaultSession();
Metadata metadata = localQueryRunner.getMetadata();
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, QualifiedObjectName.valueOf(tableName));
assertTrue(tableHandle.isPresent(), "Table " + tableName + " does not exist");
metadata.dropTable(session, tableHandle.get());
}
代码示例来源:origin: prestodb/presto
@Override
public ListenableFuture<?> execute(RenameTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
QualifiedObjectName target = createQualifiedObjectName(session, statement, statement.getTarget());
if (!metadata.getCatalogHandle(session, target.getCatalogName()).isPresent()) {
throw new SemanticException(MISSING_CATALOG, statement, "Target catalog '%s' does not exist", target.getCatalogName());
}
if (metadata.getTableHandle(session, target).isPresent()) {
throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Target table '%s' already exists", target);
}
if (!tableName.getCatalogName().equals(target.getCatalogName())) {
throw new SemanticException(NOT_SUPPORTED, statement, "Table rename across catalogs is not supported");
}
accessControl.checkCanRenameTable(session.getRequiredTransactionId(), session.getIdentity(), tableName, target);
metadata.renameTable(session, tableHandle.get(), target);
return immediateFuture(null);
}
}
代码示例来源:origin: prestodb/presto
@Override
public ListenableFuture<?> execute(Grant statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
Set<Privilege> privileges;
if (statement.getPrivileges().isPresent()) {
privileges = statement.getPrivileges().get().stream()
.map(privilege -> parsePrivilege(statement, privilege))
.collect(toImmutableSet());
}
else {
// All privileges
privileges = EnumSet.allOf(Privilege.class);
}
// verify current identity has permissions to grant permissions
for (Privilege privilege : privileges) {
accessControl.checkCanGrantTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), privilege, tableName, statement.getGrantee().getValue(), statement.isWithGrantOption());
}
metadata.grantTablePrivileges(session, tableName, privileges, statement.getGrantee().getValue(), statement.isWithGrantOption());
return immediateFuture(null);
}
代码示例来源:origin: prestodb/presto
@Override
public ListenableFuture<?> execute(Revoke statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
Set<Privilege> privileges;
if (statement.getPrivileges().isPresent()) {
privileges = statement.getPrivileges().get().stream()
.map(privilege -> parsePrivilege(statement, privilege))
.collect(toImmutableSet());
}
else {
// All privileges
privileges = EnumSet.allOf(Privilege.class);
}
// verify current identity has permissions to revoke permissions
for (Privilege privilege : privileges) {
accessControl.checkCanRevokeTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), privilege, tableName, statement.getGrantee().getValue(), statement.isGrantOptionFor());
}
metadata.revokeTablePrivileges(session, tableName, privileges, statement.getGrantee().getValue(), statement.isGrantOptionFor());
return immediateFuture(null);
}
代码示例来源:origin: prestodb/presto
TableHandle tableHandle = metadata.getTableHandle(session, tableName)
.orElseThrow(() -> new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName));
代码示例来源:origin: prestodb/presto
@TearDown(Level.Invocation)
public void dropPointsTable()
{
queryRunner.inTransaction(queryRunner.getDefaultSession(), transactionSession -> {
Metadata metadata = queryRunner.getMetadata();
Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, QualifiedObjectName.valueOf("memory.default.points"));
assertTrue(tableHandle.isPresent(), "Table memory.default.points does not exist");
metadata.dropTable(transactionSession, tableHandle.get());
return null;
});
}
代码示例来源:origin: prestodb/presto
TableHandle tableHandle = metadata.getTableHandle(session, tableName)
.orElseThrow(() -> new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName));
代码示例来源:origin: prestodb/presto
@Test
public void testTopicExists()
{
QualifiedObjectName name = new QualifiedObjectName("kafka", "default", topicName);
transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl())
.singleStatement()
.execute(SESSION, session -> {
Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
assertTrue(handle.isPresent());
});
}
代码示例来源:origin: prestodb/presto
@Test
public void testTableExists()
{
QualifiedObjectName name = new QualifiedObjectName("redis", "default", tableName);
transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl())
.singleStatement()
.execute(SESSION, session -> {
Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
assertTrue(handle.isPresent());
});
}
代码示例来源:origin: prestodb/presto
!metadata.getTableHandle(session, qualifiedTableName).isPresent()) {
throw new SemanticException(MISSING_TABLE, showGrants, "Table '%s' does not exist", tableName);
代码示例来源:origin: prestodb/presto
private Object getHiveTableProperty(String tableName, Function<HiveTableLayoutHandle, Object> propertyGetter)
{
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, TPCH_SCHEMA, tableName));
assertTrue(tableHandle.isPresent());
List<TableLayoutResult> layouts = metadata.getLayouts(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty());
TableLayout layout = getOnlyElement(layouts).getLayout();
return propertyGetter.apply((HiveTableLayoutHandle) layout.getHandle().getConnectorHandle());
});
}
代码示例来源:origin: prestodb/presto
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());
});
}
代码示例来源:origin: prestodb/presto
private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName)
{
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());
HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle();
metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of());
return hiveInsertTableHandle;
});
}
代码示例来源:origin: prestodb/presto
@Override
protected Node visitShowColumns(ShowColumns showColumns, Void context)
{
QualifiedObjectName tableName = createQualifiedObjectName(session, showColumns, showColumns.getTable());
if (!metadata.getView(session, tableName).isPresent() &&
!metadata.getTableHandle(session, tableName).isPresent()) {
throw new SemanticException(MISSING_TABLE, showColumns, "Table '%s' does not exist", tableName);
}
return simpleQuery(
selectList(
aliasedName("column_name", "Column"),
aliasedName("data_type", "Type"),
aliasedNullToEmpty("extra_info", "Extra"),
aliasedNullToEmpty("comment", "Comment")),
from(tableName.getCatalogName(), TABLE_COLUMNS),
logicalAnd(
equal(identifier("table_schema"), new StringLiteral(tableName.getSchemaName())),
equal(identifier("table_name"), new StringLiteral(tableName.getObjectName()))),
ordering(ascending("ordinal_position")));
}
代码示例来源:origin: prestodb/presto
analysis.setCreateTableDestination(targetTable);
Optional<TableHandle> targetTableHandle = metadata.getTableHandle(session, targetTable);
if (targetTableHandle.isPresent()) {
if (node.isNotExists()) {
内容来源于网络,如有侵权,请联系作者删除!