Search in sources :

Example 31 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.

the class ChunkInputFormatIT method testInfoWithoutChunks.

@Test
public void testInfoWithoutChunks() throws Exception {
    conn.tableOperations().create(tableName);
    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
    for (Entry<Key, Value> e : baddata) {
        Key k = e.getKey();
        Mutation m = new Mutation(k.getRow());
        m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp(), e.getValue());
        bw.addMutation(m);
    }
    bw.close();
    assertEquals(0, CIFTester.main(tableName, CIFTester.TestBadData.class.getName()));
    assertEquals(1, assertionErrors.get(tableName).size());
}
Also used : Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 32 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.

the class ChunkInputStreamIT method testWithAccumulo.

@Test
public void testWithAccumulo() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException {
    conn.tableOperations().create(tableName);
    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
    for (Entry<Key, Value> e : data) {
        Key k = e.getKey();
        Mutation m = new Mutation(k.getRow());
        m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), e.getValue());
        bw.addMutation(m);
    }
    bw.close();
    Scanner scan = conn.createScanner(tableName, AUTHS);
    ChunkInputStream cis = new ChunkInputStream();
    byte[] b = new byte[20];
    int read;
    PeekingIterator<Entry<Key, Value>> pi = new PeekingIterator<>(scan.iterator());
    cis.setSource(pi);
    assertEquals(read = cis.read(b), 8);
    assertEquals(new String(b, 0, read), "asdfjkl;");
    assertEquals(read = cis.read(b), -1);
    cis.setSource(pi);
    assertEquals(read = cis.read(b), 10);
    assertEquals(new String(b, 0, read), "qwertyuiop");
    assertEquals(read = cis.read(b), -1);
    assertEquals(cis.getVisibilities().toString(), "[A&B, B&C, D]");
    cis.close();
    cis.setSource(pi);
    assertEquals(read = cis.read(b), 16);
    assertEquals(new String(b, 0, read), "asdfjkl;asdfjkl;");
    assertEquals(read = cis.read(b), -1);
    assertEquals(cis.getVisibilities().toString(), "[A&B]");
    cis.close();
    cis.setSource(pi);
    assertEquals(read = cis.read(b), -1);
    cis.close();
    cis.setSource(pi);
    assertEquals(read = cis.read(b), 8);
    assertEquals(new String(b, 0, read), "asdfjkl;");
    assertEquals(read = cis.read(b), -1);
    cis.close();
    assertFalse(pi.hasNext());
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) PeekingIterator(org.apache.accumulo.core.util.PeekingIterator) Entry(java.util.Map.Entry) KeyValue(org.apache.accumulo.core.data.KeyValue) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 33 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project presto by prestodb.

the class Indexer method index.

/**
 * Index the given mutation, adding mutations to the index and metrics table
 * <p>
 * Like typical use of a BatchWriter, this method does not flush mutations to the underlying index table.
 * For higher throughput the modifications to the metrics table are tracked in memory and added to the metrics table when the indexer is flushed or closed.
 *
 * @param mutation Mutation to index
 */
public void index(Mutation mutation) {
    // Increment the cardinality for the number of rows in the table
    metrics.get(METRICS_TABLE_ROW_COUNT).incrementAndGet();
    // Set the first and last row values of the table based on existing row IDs
    if (firstRow == null || byteArrayComparator.compare(mutation.getRow(), firstRow) < 0) {
        firstRow = mutation.getRow();
    }
    if (lastRow == null || byteArrayComparator.compare(mutation.getRow(), lastRow) > 0) {
        lastRow = mutation.getRow();
    }
    // For each column update in this mutation
    for (ColumnUpdate columnUpdate : mutation.getUpdates()) {
        // Get the column qualifiers we want to index for this column family (if any)
        ByteBuffer family = wrap(columnUpdate.getColumnFamily());
        Collection<ByteBuffer> indexQualifiers = indexColumns.get(family);
        // If we have column qualifiers we want to index for this column family
        if (indexQualifiers != null) {
            // Check if we want to index this particular qualifier
            ByteBuffer qualifier = wrap(columnUpdate.getColumnQualifier());
            if (indexQualifiers.contains(qualifier)) {
                // If so, create a mutation using the following mapping:
                // Row ID = column value
                // Column Family = columnqualifier_columnfamily
                // Column Qualifier = row ID
                // Value = empty
                ByteBuffer indexFamily = getIndexColumnFamily(columnUpdate.getColumnFamily(), columnUpdate.getColumnQualifier());
                Type type = indexColumnTypes.get(family).get(qualifier);
                ColumnVisibility visibility = new ColumnVisibility(columnUpdate.getColumnVisibility());
                // If this is an array type, then index each individual element in the array
                if (Types.isArrayType(type)) {
                    Type elementType = Types.getElementType(type);
                    List<?> elements = serializer.decode(type, columnUpdate.getValue());
                    for (Object element : elements) {
                        addIndexMutation(wrap(serializer.encode(elementType, element)), indexFamily, visibility, mutation.getRow());
                    }
                } else {
                    addIndexMutation(wrap(columnUpdate.getValue()), indexFamily, visibility, mutation.getRow());
                }
            }
        }
    }
}
Also used : Type(com.facebook.presto.common.type.Type) ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ByteBuffer(java.nio.ByteBuffer)

Example 34 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility 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)

Example 35 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project hive by apache.

the class TestAccumuloSerDe method testNoVisibilitySetsEmptyVisibility.

@Test
public void testNoVisibilitySetsEmptyVisibility() throws SerDeException {
    Properties properties = new Properties();
    Configuration conf = new Configuration();
    properties.setProperty(AccumuloSerDeParameters.COLUMN_MAPPINGS, "cf:f1,:rowID");
    properties.setProperty(serdeConstants.LIST_COLUMNS, "field1,field2");
    serde.initialize(conf, properties, null);
    AccumuloRowSerializer serializer = serde.getSerializer();
    Assert.assertEquals(new ColumnVisibility(), serializer.getVisibility());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)145 Mutation (org.apache.accumulo.core.data.Mutation)62 Text (org.apache.hadoop.io.Text)59 Value (org.apache.accumulo.core.data.Value)57 Key (org.apache.accumulo.core.data.Key)43 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 Test (org.junit.Test)23 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)19 Test (org.junit.jupiter.api.Test)18 ArrayList (java.util.ArrayList)17 Entry (java.util.Map.Entry)17 Authorizations (org.apache.accumulo.core.security.Authorizations)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 Scanner (org.apache.accumulo.core.client.Scanner)14 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)13 Configuration (org.apache.hadoop.conf.Configuration)13 ColumnUpdate (org.apache.accumulo.core.data.ColumnUpdate)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 TMutation (org.apache.accumulo.core.dataImpl.thrift.TMutation)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10