Search in sources :

Example 1 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloClient method createTable.

public AccumuloTable createTable(ConnectorTableMetadata meta) {
    // Validate the DDL is something we can handle
    validateCreateTable(meta);
    Map<String, Object> tableProperties = meta.getProperties();
    String rowIdColumn = getRowIdColumn(meta);
    // Get the list of column handles
    List<AccumuloColumnHandle> columns = getColumnHandles(meta, rowIdColumn);
    // Create the AccumuloTable object
    AccumuloTable table = new AccumuloTable(meta.getTable().getSchemaName(), meta.getTable().getTableName(), columns, rowIdColumn, AccumuloTableProperties.isExternal(tableProperties), AccumuloTableProperties.getSerializerClass(tableProperties), AccumuloTableProperties.getScanAuthorizations(tableProperties));
    // First, create the metadata
    metaManager.createTableMetadata(table);
    // Make sure the namespace exists
    tableManager.ensureNamespace(table.getSchema());
    // Create the Accumulo table if it does not exist (for 'external' table)
    if (!tableManager.exists(table.getFullTableName())) {
        tableManager.createAccumuloTable(table.getFullTableName());
    }
    // Set any locality groups on the data table
    setLocalityGroups(tableProperties, table);
    // Create index tables, if appropriate
    createIndexTables(table);
    return table;
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle)

Example 2 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloMetadata method beginCreateTable.

@Override
public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) {
    checkNoRollback();
    SchemaTableName tableName = tableMetadata.getTable();
    AccumuloTable table = client.createTable(tableMetadata);
    AccumuloTableHandle handle = new AccumuloTableHandle(connectorId, tableName.getSchemaName(), tableName.getTableName(), table.getRowId(), table.isExternal(), table.getSerializerClassName(), table.getScanAuthorizations());
    setRollback(() -> rollbackCreateTable(table));
    return handle;
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 3 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

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(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Authorizations(org.apache.accumulo.core.security.Authorizations) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 4 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class TestAccumuloClient method testCreateTableEmptyAccumuloColumn.

@Test
public void testCreateTableEmptyAccumuloColumn() {
    SchemaTableName tableName = new SchemaTableName("default", "test_create_table_empty_accumulo_column");
    try {
        List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("id", BIGINT), new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT));
        Map<String, Object> properties = new HashMap<>();
        new AccumuloTableProperties().getTableProperties().forEach(meta -> properties.put(meta.getName(), meta.getDefaultValue()));
        properties.put("external", true);
        properties.put("column_mapping", "a:a:a,b::b,c:c:,d::");
        client.createTable(new ConnectorTableMetadata(tableName, columns, properties));
        assertNotNull(client.getTable(tableName));
    } finally {
        AccumuloTable table = zooKeeperMetadataManager.getTable(tableName);
        if (table != null) {
            client.dropTable(table);
        }
    }
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) HashMap(java.util.HashMap) AccumuloTableProperties(com.facebook.presto.accumulo.conf.AccumuloTableProperties) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 5 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class TestIndexer method setupClass.

@BeforeClass
public void setupClass() {
    AccumuloColumnHandle c1 = new AccumuloColumnHandle("id", Optional.empty(), Optional.empty(), VARCHAR, 0, "", false);
    AccumuloColumnHandle c2 = new AccumuloColumnHandle("age", Optional.of("cf"), Optional.of("age"), BIGINT, 1, "", true);
    AccumuloColumnHandle c3 = new AccumuloColumnHandle("firstname", Optional.of("cf"), Optional.of("firstname"), VARCHAR, 2, "", true);
    AccumuloColumnHandle c4 = new AccumuloColumnHandle("arr", Optional.of("cf"), Optional.of("arr"), new ArrayType(VARCHAR), 3, "", true);
    table = new AccumuloTable("default", "index_test_table", ImmutableList.of(c1, c2, c3, c4), "id", true, LexicoderRowSerializer.class.getCanonicalName(), null);
    m1 = new Mutation(M1_ROWID);
    m1.put(CF, AGE, AGE_VALUE);
    m1.put(CF, FIRSTNAME, M1_FNAME_VALUE);
    m1.put(CF, SENDERS, M1_ARR_VALUE);
    m2 = new Mutation(M2_ROWID);
    m2.put(CF, AGE, AGE_VALUE);
    m2.put(CF, FIRSTNAME, M2_FNAME_VALUE);
    m2.put(CF, SENDERS, M2_ARR_VALUE);
    ColumnVisibility visibility1 = new ColumnVisibility("private");
    ColumnVisibility visibility2 = new ColumnVisibility("moreprivate");
    m1v = new Mutation(M1_ROWID);
    m1v.put(CF, AGE, visibility1, AGE_VALUE);
    m1v.put(CF, FIRSTNAME, visibility1, M1_FNAME_VALUE);
    m1v.put(CF, SENDERS, visibility2, M1_ARR_VALUE);
    m2v = new Mutation(M2_ROWID);
    m2v.put(CF, AGE, visibility1, AGE_VALUE);
    m2v.put(CF, FIRSTNAME, visibility2, M2_FNAME_VALUE);
    m2v.put(CF, SENDERS, visibility2, M2_ARR_VALUE);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)10 AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)5 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)4 AccumuloTableProperties (com.facebook.presto.accumulo.conf.AccumuloTableProperties)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Logger (com.facebook.airlift.log.Logger)1 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 AccumuloConfig (com.facebook.presto.accumulo.conf.AccumuloConfig)1 AccumuloSessionProperties (com.facebook.presto.accumulo.conf.AccumuloSessionProperties)1 IndexLookup (com.facebook.presto.accumulo.index.IndexLookup)1 Indexer (com.facebook.presto.accumulo.index.Indexer)1 AccumuloPageSink (com.facebook.presto.accumulo.io.AccumuloPageSink)1 AccumuloView (com.facebook.presto.accumulo.metadata.AccumuloView)1