use of io.trino.metadata.Metadata in project trino by trinodb.
the class BaseHiveConnectorTest method getHiveInsertTableHandle.
private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName) {
Metadata metadata = getDistributedQueryRunner().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);
List<ColumnHandle> columns = ImmutableList.copyOf(metadata.getColumnHandles(transactionSession, handle.get()).values());
InsertTableHandle insertTableHandle = metadata.beginInsert(transactionSession, handle.get(), columns);
HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle();
metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of());
return hiveInsertTableHandle;
});
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class BaseHiveConnectorTest method getHiveTableProperty.
private Object getHiveTableProperty(String tableName, Function<HiveTableHandle, Object> propertyGetter) {
Session session = getSession();
Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
QualifiedObjectName name = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
TableHandle table = metadata.getTableHandle(transactionSession, name).orElseThrow(() -> new AssertionError("table not found: " + name));
table = metadata.applyFilter(transactionSession, table, Constraint.alwaysTrue()).orElseThrow(() -> new AssertionError("applyFilter did not return a result")).getHandle();
return propertyGetter.apply((HiveTableHandle) table.getConnectorHandle());
});
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class SetRoleTask method execute.
@Override
public ListenableFuture<Void> execute(SetRole statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
Optional<String> catalog = processRoleCommandCatalog(metadata, session, statement, statement.getCatalog().map(Identifier::getValue));
if (statement.getType() == SetRole.Type.ROLE) {
String role = statement.getRole().map(c -> c.getValue().toLowerCase(ENGLISH)).orElseThrow();
if (!metadata.roleExists(session, role, catalog)) {
throw semanticException(ROLE_NOT_FOUND, statement, "Role '%s' does not exist", role);
}
if (catalog.isPresent()) {
accessControl.checkCanSetCatalogRole(SecurityContext.of(session), role, catalog.get());
} else {
Set<RoleGrant> roleGrants = metadata.listApplicableRoles(session, new TrinoPrincipal(USER, session.getUser()), Optional.empty());
if (roleGrants.stream().map(RoleGrant::getRoleName).noneMatch(role::equals)) {
denySetRole(role);
}
}
}
SelectedRole.Type type = toSelectedRoleType(statement.getType());
stateMachine.addSetRole(catalog.orElse("system"), new SelectedRole(type, statement.getRole().map(c -> c.getValue().toLowerCase(ENGLISH))));
return immediateVoidFuture();
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class AbstractOperatorBenchmark method getColumnTypes.
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());
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class MemoryLocalQueryRunner method dropTable.
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());
}
Aggregations