public ColumnVisibility getColumnVisibility() { if (isMetadataSet()) { return metadata.getColumnVisibilityParsed(); } return Constants.EMPTY_VISIBILITY; }
private Map<String,String> getMarkings(Key k) throws MarkingFunctions.Exception { return getMarkings(k.getColumnVisibilityParsed()); }
private Map<String,String> getMarkings(Key k) throws MarkingFunctions.Exception { return getMarkings(k.getColumnVisibilityParsed()); }
private boolean isMatch(Key k) { Text columnVisibilityText = k.getColumnVisibility(); if (columnVisibilityText.getLength() == 0) { return false; } Boolean match = matchCache.get(columnVisibilityText); if (match != null) { return match; } String[] parts = SPLIT_PATTERN.split(k.getColumnVisibilityParsed().toString()); for (String part : parts) { if (part.equals(authorizationToMatch)) { matchCache.put(columnVisibilityText, true); return true; } } matchCache.put(columnVisibilityText, false); return false; } }
private boolean isMatch(Key k) { Text columnVisibilityText = k.getColumnVisibility(); if (columnVisibilityText.getLength() == 0) { return false; } Boolean match = matchCache.get(columnVisibilityText); if (match != null) { return match; } String[] parts = SPLIT_PATTERN.split(k.getColumnVisibilityParsed().toString()); for (String part : parts) { if (part.equals(authorizationToMatch)) { matchCache.put(columnVisibilityText, true); return true; } } matchCache.put(columnVisibilityText, false); return false; } }
private static <M extends Map<Key,V>, V> M transposeMapHelp(Map<Key,V> orig, M neww) { for (Map.Entry<Key, V> entry : orig.entrySet()) { Key k0 = entry.getKey(); Key k = new Key(k0.getColumnQualifier(), k0.getColumnFamily(), k0.getRow(), k0.getColumnVisibilityParsed(), k0.getTimestamp()); neww.put(k, entry.getValue()); } return neww; }
@Override protected void safeMap(Text row, PeekingIterator<Map.Entry<Key, Value>> value, Context context) throws IOException, InterruptedException { context.setStatus(row.toString()); String propertyVisibility = null; while (value.hasNext()) { Map.Entry<Key, Value> column = value.next(); if (column.getKey().getColumnFamily().toString().equals("PROP")) { propertyVisibility = AccumuloGraph.accumuloVisibilityToVisibility(column.getKey().getColumnVisibilityParsed()).getVisibilityString(); } else if (column.getKey().getColumnFamily().toString().equals("PROPMETA")) { updateMetadata(column.getKey(), column.getValue(), propertyVisibility, context); } } }
private void updateMetadata(Key key, Value value, String propertyVisibility, Context context) throws IOException, InterruptedException { String columnQualifier = key.getColumnQualifier().toString(); if (count(columnQualifier, ElementMutationBuilder.VALUE_SEPARATOR) != 2) { return; } Mutation m = new Mutation(key.getRow()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("mutation: " + key.getRow()); } int lastValueSeparator = columnQualifier.lastIndexOf(ElementMutationBuilder.VALUE_SEPARATOR); String newColumnQualifier = columnQualifier.substring(0, lastValueSeparator) + ElementMutationBuilder.VALUE_SEPARATOR + propertyVisibility + columnQualifier.substring(lastValueSeparator); m.put(key.getColumnFamily(), new Text(newColumnQualifier), key.getColumnVisibilityParsed(), key.getTimestamp(), value); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" put: " + key.getColumnFamily() + ", " + newColumnQualifier + ", " + key.getColumnVisibilityParsed() + ", " + key.getTimestamp() + ", " + value); } m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" put delete: " + key.getColumnFamily() + ", " + key.getColumnQualifier() + ", " + key.getColumnVisibilityParsed() + ", " + key.getTimestamp()); } context.write(getOutputTableNameText(), m); }
/** * Output a row via the Hadoop framework (rather than a Rya interface) to the Mapper's configured * child table. * @param key Row's key * @param value Row's value * @param context Context to use for writing * @throws InterruptedException if the framework is interrupted writing output * @throws IOException if the framework encounters an error writing the row to Accumulo */ @Override protected void copyRow(final Key key, final Value value, final Context context) throws IOException, InterruptedException { final Mutation mutation = new Mutation(key.getRow().getBytes()); mutation.put(key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp(), value); context.write(childTableNameText, mutation); } }
private static Mutation makeAddMutation(final Key key, final Value value) { final Mutation mutation = new Mutation(key.getRow().getBytes()); mutation.put(key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp(), value); return mutation; } }
private static void rollback(Environment env, long startTs, PrimaryRowColumn prc, List<Entry<Key, Value>> value, Map<ByteSequence, Mutation> mutations) { for (Entry<Key, Value> entry : value) { if (isPrimary(prc, entry.getKey())) { continue; } long lockTs = entry.getKey().getTimestamp() & ColumnConstants.TIMESTAMP_MASK; Mutation mut = getMutation(entry.getKey().getRowData(), mutations); Key k = entry.getKey(); mut.put(k.getColumnFamilyData().toArray(), k.getColumnQualifierData().toArray(), k.getColumnVisibilityParsed(), ColumnConstants.DEL_LOCK_PREFIX | startTs, DelLockValue.encode(lockTs, false, true)); } }
private void deleteRows(BatchWriter writer, List<Key> rowsToDelete, Options options) throws MutationsRejectedException { rowsToDelete.sort(Comparator.comparingLong(Key::getTimestamp)); int i = 0; for (Key key : rowsToDelete) { if (i < rowsToDelete.size() - options.getVersionsToKeep()) { LOGGER.debug("deleting row: %s", key.getRow().toString()); if (!options.isDryRun()) { Mutation mutation = new Mutation(key.getRow()); mutation.putDelete( key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp() ); writer.addMutation(mutation); } } else { if (options.isDryRun()) { LOGGER.debug("skipping row: %s", key.getRow().toString()); } } i++; } }
private static void rollback(Environment env, long startTs, PrimaryRowColumn prc, List<LockInfo> value, Map<ByteSequence, Mutation> mutations) { for (LockInfo lockInfo : value) { if (isPrimary(prc, lockInfo.entry.getKey())) { continue; } Mutation mut = getMutation(lockInfo.entry.getKey().getRowData(), mutations); Key k = lockInfo.entry.getKey(); if (lockInfo.isReadLock) { mut.put(k.getColumnFamilyData().toArray(), k.getColumnQualifierData().toArray(), k.getColumnVisibilityParsed(), ColumnConstants.RLOCK_PREFIX | ReadLockUtil.encodeTs(lockInfo.lockTs, true), DelReadLockValue.encodeRollback()); } else { mut.put(k.getColumnFamilyData().toArray(), k.getColumnQualifierData().toArray(), k.getColumnVisibilityParsed(), ColumnConstants.DEL_LOCK_PREFIX | lockInfo.lockTs, DelLockValue.encodeRollback(false, true)); } } }
private void deleteRows(BatchWriter writer, List<Key> rowsToDelete, Options options) throws MutationsRejectedException { rowsToDelete.sort(Comparator.comparingLong(Key::getTimestamp)); int i = 0; for (Key key : rowsToDelete) { if (i < rowsToDelete.size() - options.getVersionsToKeep()) { LOGGER.debug("deleting row: %s", key.getRow().toString()); if (!options.isDryRun()) { Mutation mutation = new Mutation(key.getRow()); mutation.putDelete( key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp() ); writer.addMutation(mutation); } } else { if (options.isDryRun()) { LOGGER.debug("skipping row: %s", key.getRow().toString()); } } i++; } }
private static void rollback(Environment env, long startTs, PrimaryRowColumn prc, List<LockInfo> value, Map<ByteSequence, Mutation> mutations) { for (LockInfo lockInfo : value) { if (isPrimary(prc, lockInfo.entry.getKey())) { continue; } Mutation mut = getMutation(lockInfo.entry.getKey().getRowData(), mutations); Key k = lockInfo.entry.getKey(); if (lockInfo.isReadLock) { mut.put(k.getColumnFamilyData().toArray(), k.getColumnQualifierData().toArray(), k.getColumnVisibilityParsed(), ColumnType.RLOCK.encode(ReadLockUtil.encodeTs(lockInfo.lockTs, true)), DelReadLockValue.encodeRollback()); } else { mut.put(k.getColumnFamilyData().toArray(), k.getColumnQualifierData().toArray(), k.getColumnVisibilityParsed(), ColumnType.DEL_LOCK.encode(lockInfo.lockTs), DelLockValue.encodeRollback(false, true)); } } }
private void assertKey(Key key, String uid) { Assert.assertNotNull(key); Assert.assertEquals(key.getRow().toString(), FI_ROW); Assert.assertEquals(key.getColumnFamily().toString(), FI_COLUMN_FAMILY); Assert.assertEquals(key.getColumnQualifier().toString(), FI_COLUMN_QUALIFIER_PREFIX + uid); Assert.assertEquals(new String(key.getColumnVisibilityParsed().getExpression()), FI_VIS); Assert.assertEquals(key.getTimestamp(), FI_TIMESTAMP); }
private static void writeKeyValues(Connector connector, Multimap<BulkIngestKey,Value> keyValues) throws Exception { final TableOperations tops = connector.tableOperations(); final Set<BulkIngestKey> biKeys = keyValues.keySet(); for (final BulkIngestKey biKey : biKeys) { final String tableName = biKey.getTableName().toString(); if (!tops.exists(tableName)) tops.create(tableName); final BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig()); for (final Value val : keyValues.get(biKey)) { final Mutation mutation = new Mutation(biKey.getKey().getRow()); mutation.put(biKey.getKey().getColumnFamily(), biKey.getKey().getColumnQualifier(), biKey.getKey().getColumnVisibilityParsed(), val); writer.addMutation(mutation); } writer.close(); } }
private static void writeKeyValues(Connector connector, Multimap<BulkIngestKey,Value> keyValues) throws Exception { final TableOperations tops = connector.tableOperations(); final Set<BulkIngestKey> biKeys = keyValues.keySet(); for (final BulkIngestKey biKey : biKeys) { final String tableName = biKey.getTableName().toString(); if (!tops.exists(tableName)) tops.create(tableName); final BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig()); for (final Value val : keyValues.get(biKey)) { final Mutation mutation = new Mutation(biKey.getKey().getRow()); mutation.put(biKey.getKey().getColumnFamily(), biKey.getKey().getColumnQualifier(), biKey.getKey().getColumnVisibilityParsed(), biKey.getKey() .getTimestamp(), val); writer.addMutation(mutation); } writer.close(); } }
private static void writeKeyValues(Connector connector, Multimap<BulkIngestKey,Value> keyValues) throws Exception { final TableOperations tops = connector.tableOperations(); final Set<BulkIngestKey> biKeys = keyValues.keySet(); for (final BulkIngestKey biKey : biKeys) { final String tableName = biKey.getTableName().toString(); if (!tops.exists(tableName)) tops.create(tableName); final BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig()); for (final Value val : keyValues.get(biKey)) { final Mutation mutation = new Mutation(biKey.getKey().getRow()); mutation.put(biKey.getKey().getColumnFamily(), biKey.getKey().getColumnQualifier(), biKey.getKey().getColumnVisibilityParsed(), biKey.getKey() .getTimestamp(), val); writer.addMutation(mutation); } writer.close(); } }
private static void writeKeyValues(Connector connector, Multimap<BulkIngestKey,Value> keyValues) throws Exception { final TableOperations tops = connector.tableOperations(); final Set<BulkIngestKey> biKeys = keyValues.keySet(); tops.create(DATE_INDEX_TABLE_NAME); for (final BulkIngestKey biKey : biKeys) { final String tableName = biKey.getTableName().toString(); if (!tops.exists(tableName)) tops.create(tableName); final BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig()); for (final Value val : keyValues.get(biKey)) { final Mutation mutation = new Mutation(biKey.getKey().getRow()); mutation.put(biKey.getKey().getColumnFamily(), biKey.getKey().getColumnQualifier(), biKey.getKey().getColumnVisibilityParsed(), biKey.getKey() .getTimestamp(), val); writer.addMutation(mutation); } writer.close(); } }