Search in sources :

Example 6 with AccumuloColumnHandle

use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.

the class AccumuloPageSink method toMutation.

/**
     * Converts a {@link Row} to an Accumulo mutation.
     *
     * @param row Row object
     * @param rowIdOrdinal Ordinal in the list of columns that is the row ID. This isn't checked at all, so I hope you're right. Also, it is expected that the list of column handles is sorted in ordinal order. This is a very demanding function.
     * @param columns All column handles for the Row, sorted by ordinal.
     * @param serializer Instance of {@link AccumuloRowSerializer} used to encode the values of the row to the Mutation
     * @return Mutation
     */
public static Mutation toMutation(Row row, int rowIdOrdinal, List<AccumuloColumnHandle> columns, AccumuloRowSerializer serializer) {
    // Set our value to the row ID
    Text value = new Text();
    Field rowField = row.getField(rowIdOrdinal);
    if (rowField.isNull()) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Column mapped as the Accumulo row ID cannot be null");
    }
    setText(rowField, value, serializer);
    // Iterate through all the column handles, setting the Mutation's columns
    Mutation mutation = new Mutation(value);
    // Store row ID in a special column
    mutation.put(ROW_ID_COLUMN, ROW_ID_COLUMN, new Value(value.copyBytes()));
    for (AccumuloColumnHandle columnHandle : columns) {
        // Skip the row ID ordinal
        if (columnHandle.getOrdinal() == rowIdOrdinal) {
            continue;
        }
        // If the value of the field is not null
        if (!row.getField(columnHandle.getOrdinal()).isNull()) {
            // Serialize the value to the text
            setText(row.getField(columnHandle.getOrdinal()), value, serializer);
            // And add the bytes to the Mutation
            mutation.put(columnHandle.getFamily().get(), columnHandle.getQualifier().get(), new Value(value.copyBytes()));
        }
    }
    return mutation;
}
Also used : Field(com.facebook.presto.accumulo.model.Field) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Value(org.apache.accumulo.core.data.Value) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) Text(org.apache.hadoop.io.Text) PrestoException(com.facebook.presto.spi.PrestoException) Mutation(org.apache.accumulo.core.data.Mutation)

Example 7 with AccumuloColumnHandle

use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.

the class AccumuloClient method renameColumn.

public void renameColumn(AccumuloTable table, String source, String target) {
    if (!table.getColumns().stream().anyMatch(columnHandle -> columnHandle.getName().equalsIgnoreCase(source))) {
        throw new PrestoException(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 : IndexLookup(com.facebook.presto.accumulo.index.IndexLookup) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) Text(org.apache.hadoop.io.Text) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Pair(org.apache.commons.lang3.tuple.Pair) InvalidParameterException(java.security.InvalidParameterException) Locale(java.util.Locale) AccumuloSessionProperties(com.facebook.presto.accumulo.conf.AccumuloSessionProperties) AccumuloView(com.facebook.presto.accumulo.metadata.AccumuloView) Map(java.util.Map) Value(org.apache.accumulo.core.data.Value) Splitter(com.google.common.base.Splitter) FUNCTION_IMPLEMENTATION_ERROR(com.facebook.presto.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_ERROR) INVALID_TABLE_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) AccumuloTableProperties(com.facebook.presto.accumulo.conf.AccumuloTableProperties) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ZooKeeperMetadataManager(com.facebook.presto.accumulo.metadata.ZooKeeperMetadataManager) Set(java.util.Set) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Domain(com.facebook.presto.spi.predicate.Domain) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) AccumuloConfig(com.facebook.presto.accumulo.conf.AccumuloConfig) Entry(java.util.Map.Entry) Optional(java.util.Optional) Scanner(org.apache.accumulo.core.client.Scanner) Iterables(com.google.common.collect.Iterables) AccumuloRowSerializer(com.facebook.presto.accumulo.serializers.AccumuloRowSerializer) Logger(io.airlift.log.Logger) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) Indexer(com.facebook.presto.accumulo.index.Indexer) Connector(org.apache.accumulo.core.client.Connector) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) Objects.requireNonNull(java.util.Objects.requireNonNull) ACCUMULO_TABLE_EXISTS(com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_EXISTS) ACCUMULO_TABLE_DNE(com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_DNE) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Iterator(java.util.Iterator) Bound(com.facebook.presto.spi.predicate.Marker.Bound) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloPageSink(com.facebook.presto.accumulo.io.AccumuloPageSink) AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PartialKey(org.apache.accumulo.core.data.PartialKey) UNEXPECTED_ACCUMULO_ERROR(com.facebook.presto.accumulo.AccumuloErrorCode.UNEXPECTED_ACCUMULO_ERROR) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 8 with AccumuloColumnHandle

use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.

the class AccumuloClient method setLocalityGroups.

private void setLocalityGroups(Map<String, Object> tableProperties, AccumuloTable table) {
    Optional<Map<String, Set<String>>> groups = AccumuloTableProperties.getLocalityGroups(tableProperties);
    if (!groups.isPresent()) {
        LOG.debug("No locality groups to set");
        return;
    }
    ImmutableMap.Builder<String, Set<Text>> localityGroupsBuilder = ImmutableMap.builder();
    for (Map.Entry<String, Set<String>> g : groups.get().entrySet()) {
        ImmutableSet.Builder<Text> familyBuilder = ImmutableSet.builder();
        // For each configured column for this locality group
        for (String col : g.getValue()) {
            // Locate the column family mapping via the Handle
            // We already validated this earlier, so it'll exist
            AccumuloColumnHandle handle = table.getColumns().stream().filter(x -> x.getName().equals(col)).collect(Collectors.toList()).get(0);
            familyBuilder.add(new Text(handle.getFamily().get()));
        }
        localityGroupsBuilder.put(g.getKey(), familyBuilder.build());
    }
    Map<String, Set<Text>> localityGroups = localityGroupsBuilder.build();
    LOG.debug("Setting locality groups: {}", localityGroups);
    tableManager.setLocalityGroups(table.getFullTableName(), localityGroups);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Text(org.apache.hadoop.io.Text) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with AccumuloColumnHandle

use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.

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(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 10 with AccumuloColumnHandle

use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.

the class AccumuloMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
    checkArgument(handle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
    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.build();
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)10 AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)5 Text (org.apache.hadoop.io.Text)4 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 AccumuloColumnConstraint (com.facebook.presto.accumulo.model.AccumuloColumnConstraint)2 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 ImmutableList (com.google.common.collect.ImmutableList)2 Map (java.util.Map)2 Value (org.apache.accumulo.core.data.Value)2 ACCUMULO_TABLE_DNE (com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_DNE)1 ACCUMULO_TABLE_EXISTS (com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_EXISTS)1 UNEXPECTED_ACCUMULO_ERROR (com.facebook.presto.accumulo.AccumuloErrorCode.UNEXPECTED_ACCUMULO_ERROR)1