use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AccumuloClient method renameColumn.
public void renameColumn(AccumuloTable table, String source, String target) {
if (table.getColumns().stream().noneMatch(columnHandle -> columnHandle.getName().equalsIgnoreCase(source))) {
throw new TrinoException(NOT_FOUND, format("Failed to find source column %s to rename to %s", source, target));
}
// Copy existing column list, replacing the old column name with the new
ImmutableList.Builder<AccumuloColumnHandle> newColumnList = ImmutableList.builder();
for (AccumuloColumnHandle columnHandle : table.getColumns()) {
if (columnHandle.getName().equalsIgnoreCase(source)) {
newColumnList.add(new AccumuloColumnHandle(target, columnHandle.getFamily(), columnHandle.getQualifier(), columnHandle.getType(), columnHandle.getOrdinal(), columnHandle.getComment(), columnHandle.isIndexed()));
} else {
newColumnList.add(columnHandle);
}
}
// Create new table metadata
AccumuloTable newTable = new AccumuloTable(table.getSchema(), table.getTable(), newColumnList.build(), table.getRowId().equalsIgnoreCase(source) ? target : table.getRowId(), table.isExternal(), table.getSerializerClassName(), table.getScanAuthorizations());
// Replace the table metadata
metaManager.deleteTableMetadata(new SchemaTableName(table.getSchema(), table.getTable()));
metaManager.createTableMetadata(newTable);
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AccumuloClient method getScanAuthorizations.
/**
* Gets the scan authorizations to use for scanning tables.
* <p>
* In order of priority: session username authorizations, then table property, then the default connector auths.
*
* @param session Current session
* @param schema Schema name
* @param table Table Name
* @return Scan authorizations
* @throws AccumuloException If a generic Accumulo error occurs
* @throws AccumuloSecurityException If a security exception occurs
*/
private Authorizations getScanAuthorizations(ConnectorSession session, String schema, String table) throws AccumuloException, AccumuloSecurityException {
String sessionScanUser = AccumuloSessionProperties.getScanUsername(session);
if (sessionScanUser != null) {
Authorizations scanAuths = connector.securityOperations().getUserAuthorizations(sessionScanUser);
LOG.debug("Using session scan auths for user %s: %s", sessionScanUser, scanAuths);
return scanAuths;
}
AccumuloTable accumuloTable = this.getTable(new SchemaTableName(schema, table));
if (accumuloTable == null) {
throw new TableNotFoundException(new SchemaTableName(schema, table));
}
Optional<String> strAuths = accumuloTable.getScanAuthorizations();
if (strAuths.isPresent()) {
Authorizations scanAuths = new Authorizations(Iterables.toArray(COMMA_SPLITTER.split(strAuths.get()), String.class));
LOG.debug("scan_auths table property set, using: %s", scanAuths);
return scanAuths;
}
LOG.debug("scan_auths table property not set, using connector auths: %s", this.auths);
return this.auths;
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AccumuloMetadata method renameColumn.
@Override
public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source, String target) {
AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
AccumuloColumnHandle columnHandle = (AccumuloColumnHandle) source;
AccumuloTable table = client.getTable(handle.toSchemaTableName());
if (table == null) {
throw new TableNotFoundException(new SchemaTableName(handle.getSchema(), handle.getTable()));
}
client.renameColumn(table, columnHandle.getName(), target);
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AccumuloMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table) {
AccumuloTableHandle handle = (AccumuloTableHandle) table;
SchemaTableName tableName = new SchemaTableName(handle.getSchema(), handle.getTable());
ConnectorTableMetadata metadata = getTableMetadata(tableName);
if (metadata == null) {
throw new TableNotFoundException(tableName);
}
return metadata;
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class CassandraSession method getTableMetadata.
private static AbstractTableMetadata getTableMetadata(KeyspaceMetadata keyspace, String caseInsensitiveTableName) {
List<AbstractTableMetadata> tables = Stream.concat(keyspace.getTables().stream(), keyspace.getMaterializedViews().stream()).filter(table -> table.getName().equalsIgnoreCase(caseInsensitiveTableName)).collect(toImmutableList());
if (tables.size() == 0) {
throw new TableNotFoundException(new SchemaTableName(keyspace.getName(), caseInsensitiveTableName));
}
if (tables.size() == 1) {
return tables.get(0);
}
String tableNames = tables.stream().map(AbstractTableMetadata::getName).sorted().collect(joining(", "));
throw new TrinoException(NOT_SUPPORTED, format("More than one table has been found for the case insensitive table name: %s -> (%s)", caseInsensitiveTableName, tableNames));
}
Aggregations