Search in sources :

Example 81 with SchemaTableName

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);
}
Also used : AccumuloTable(io.trino.plugin.accumulo.metadata.AccumuloTable) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnHandle(io.trino.plugin.accumulo.model.AccumuloColumnHandle) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 82 with SchemaTableName

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;
}
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 83 with SchemaTableName

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);
}
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 84 with SchemaTableName

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;
}
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 85 with SchemaTableName

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));
}
Also used : CassandraType.isFullySupported(io.trino.plugin.cassandra.CassandraType.isFullySupported) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) Iterables.transform(com.google.common.collect.Iterables.transform) CassandraType.toCassandraType(io.trino.plugin.cassandra.CassandraType.toCassandraType) RegularStatement(com.datastax.driver.core.RegularStatement) Clause(com.datastax.driver.core.querybuilder.Clause) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) ByteBuffer(java.nio.ByteBuffer) Duration(io.airlift.units.Duration) ReconnectionPolicy(com.datastax.driver.core.policies.ReconnectionPolicy) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Session(com.datastax.driver.core.Session) Map(java.util.Map) VersionNumber(com.datastax.driver.core.VersionNumber) ENGLISH(java.util.Locale.ENGLISH) CassandraCqlUtils.validSchemaName(io.trino.plugin.cassandra.util.CassandraCqlUtils.validSchemaName) TableMetadata(com.datastax.driver.core.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) Sets(com.google.common.collect.Sets) SchemaTableName(io.trino.spi.connector.SchemaTableName) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ProtocolVersion(com.datastax.driver.core.ProtocolVersion) List(java.util.List) Stream(java.util.stream.Stream) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host) Optional(java.util.Optional) Select(com.datastax.driver.core.querybuilder.Select) Statement(com.datastax.driver.core.Statement) JsonCodec(io.airlift.json.JsonCodec) TokenRange(com.datastax.driver.core.TokenRange) Logger(io.airlift.log.Logger) NullableValue(io.trino.spi.predicate.NullableValue) Row(com.datastax.driver.core.Row) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) PRESTO_COMMENT_METADATA(io.trino.plugin.cassandra.CassandraMetadata.PRESTO_COMMENT_METADATA) AbstractTableMetadata(com.datastax.driver.core.AbstractTableMetadata) PreparedStatement(com.datastax.driver.core.PreparedStatement) HashSet(java.util.HashSet) CassandraCqlUtils.selectDistinctFrom(io.trino.plugin.cassandra.util.CassandraCqlUtils.selectDistinctFrom) ResultSet(com.datastax.driver.core.ResultSet) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Comparator.comparing(java.util.Comparator.comparing) Suppliers.memoize(com.google.common.base.Suppliers.memoize) QueryBuilder.eq(com.datastax.driver.core.querybuilder.QueryBuilder.eq) TupleDomain(io.trino.spi.predicate.TupleDomain) IndexMetadata(com.datastax.driver.core.IndexMetadata) CassandraCqlUtils(io.trino.plugin.cassandra.util.CassandraCqlUtils) Collectors.toList(java.util.stream.Collectors.toList) MaterializedViewMetadata(com.datastax.driver.core.MaterializedViewMetadata) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) Ordering(com.google.common.collect.Ordering) QueryBuilder.select(com.datastax.driver.core.querybuilder.QueryBuilder.select) DataType(com.datastax.driver.core.DataType) CASSANDRA_VERSION_ERROR(io.trino.plugin.cassandra.CassandraErrorCode.CASSANDRA_VERSION_ERROR) ReconnectionSchedule(com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) AbstractTableMetadata(com.datastax.driver.core.AbstractTableMetadata) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Aggregations

SchemaTableName (io.trino.spi.connector.SchemaTableName)446 Test (org.testng.annotations.Test)212 ImmutableList (com.google.common.collect.ImmutableList)131 ImmutableMap (com.google.common.collect.ImmutableMap)106 List (java.util.List)102 TrinoException (io.trino.spi.TrinoException)100 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)98 ConnectorSession (io.trino.spi.connector.ConnectorSession)98 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)92 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)89 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)86 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)86 Optional (java.util.Optional)78 Map (java.util.Map)67 ColumnHandle (io.trino.spi.connector.ColumnHandle)66 TupleDomain (io.trino.spi.predicate.TupleDomain)59 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)58 Path (org.apache.hadoop.fs.Path)55 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)53 ImmutableSet (com.google.common.collect.ImmutableSet)52