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());
}
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());
}
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());
}
}
}
}
}
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);
}
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());
}
Aggregations