Search in sources :

Example 26 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class AccumuloClient method renameTable.

public void renameTable(SchemaTableName oldName, SchemaTableName newName) {
    if (!oldName.getSchemaName().equals(newName.getSchemaName())) {
        throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming tables across schemas");
    }
    AccumuloTable oldTable = getTable(oldName);
    if (oldTable == null) {
        throw new TableNotFoundException(oldName);
    }
    AccumuloTable newTable = new AccumuloTable(oldTable.getSchema(), newName.getTableName(), oldTable.getColumns(), oldTable.getRowId(), oldTable.isExternal(), oldTable.getSerializerClassName(), oldTable.getScanAuthorizations());
    // Validate table existence
    if (!tableManager.exists(oldTable.getFullTableName())) {
        throw new TrinoException(ACCUMULO_TABLE_DNE, format("Table '%s' does not exist", oldTable.getFullTableName()));
    }
    if (tableManager.exists(newTable.getFullTableName())) {
        throw new TrinoException(ACCUMULO_TABLE_EXISTS, format("Table '%s' already exists", newTable.getFullTableName()));
    }
    // Rename index tables (which will also validate table existence)
    renameIndexTables(oldTable, newTable);
    // Rename the Accumulo table
    tableManager.renameAccumuloTable(oldTable.getFullTableName(), newTable.getFullTableName());
    // We'll then create the metadata
    metaManager.deleteTableMetadata(oldTable.getSchemaTableName());
    metaManager.createTableMetadata(newTable);
}
Also used : AccumuloTable(io.trino.plugin.accumulo.metadata.AccumuloTable) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) TrinoException(io.trino.spi.TrinoException)

Example 27 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException 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;
}
Also used : AccumuloTable(io.trino.plugin.accumulo.metadata.AccumuloTable) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Authorizations(org.apache.accumulo.core.security.Authorizations) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 28 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException 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);
}
Also used : AccumuloTable(io.trino.plugin.accumulo.metadata.AccumuloTable) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) AccumuloColumnHandle(io.trino.plugin.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(io.trino.plugin.accumulo.model.AccumuloTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 29 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException 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;
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) AccumuloTableHandle(io.trino.plugin.accumulo.model.AccumuloTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 30 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class AccumuloMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
    AccumuloTable table = client.getTable(handle.toSchemaTableName());
    if (table == null) {
        throw new TableNotFoundException(handle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (AccumuloColumnHandle column : table.getColumns()) {
        columnHandles.put(column.getName(), column);
    }
    return columnHandles.buildOrThrow();
}
Also used : AccumuloTable(io.trino.plugin.accumulo.metadata.AccumuloTable) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ColumnHandle(io.trino.spi.connector.ColumnHandle) AccumuloColumnHandle(io.trino.plugin.accumulo.model.AccumuloColumnHandle) AccumuloColumnHandle(io.trino.plugin.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(io.trino.plugin.accumulo.model.AccumuloTableHandle) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TableNotFoundException (io.trino.spi.connector.TableNotFoundException)84 SchemaTableName (io.trino.spi.connector.SchemaTableName)65 TrinoException (io.trino.spi.TrinoException)39 Table (io.trino.plugin.hive.metastore.Table)33 ImmutableMap (com.google.common.collect.ImmutableMap)27 ImmutableList (com.google.common.collect.ImmutableList)26 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)26 List (java.util.List)25 Optional (java.util.Optional)24 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)22 Path (org.apache.hadoop.fs.Path)22 ColumnHandle (io.trino.spi.connector.ColumnHandle)21 Map (java.util.Map)21 Objects.requireNonNull (java.util.Objects.requireNonNull)20 ConnectorSession (io.trino.spi.connector.ConnectorSession)19 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)18 TupleDomain (io.trino.spi.predicate.TupleDomain)18 Set (java.util.Set)18 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17