@Override public String toString() { StringBuilder sb = new StringBuilder(); String sep = ""; for (ByteSequence auth : auths) { sb.append(sep); sep = ","; sb.append(new String(auth.toArray(), UTF_8)); } return sb.toString(); }
private void checkAuths() { Set<ByteSequence> sortedAuths = new TreeSet<>(auths); for (ByteSequence bs : sortedAuths) { if (bs.length() == 0) { throw new IllegalArgumentException("Empty authorization"); } authsList.add(bs.toArray()); } }
public ConditionalMutation(ByteSequence row, Condition... conditions) { // TODO add ByteSequence methods to mutations super(row.toArray()); init(conditions); }
NMIterator(Key key) { if (nmPointer == 0) { throw new IllegalStateException(); } expectedModCount = modCount; nmiPointer = createNMI(nmPointer, key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getColumnVisibilityData().toArray(), key.getTimestamp(), key.isDeleted(), fieldsLens); hasNext = nmiPointer != 0; }
private boolean isVisible(ByteSequence cv) { Text testVis = new Text(cv.toArray()); if (testVis.getLength() == 0) return true; Boolean b = cache.get(testVis); if (b != null) return b; try { Boolean bb = ve.evaluate(new ColumnVisibility(testVis)); cache.put(new Text(testVis), bb); return bb; } catch (VisibilityParseException | BadArgumentException e) { return false; } }
@Override public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException { AccumuloConfiguration conf = new ConfigurationCopy(this.getProperties(tableName)); Map<String,Set<ByteSequence>> groups = LocalityGroupUtil.getLocalityGroups(conf); Map<String,Set<Text>> groups2 = new HashMap<>(); for (Entry<String,Set<ByteSequence>> entry : groups.entrySet()) { HashSet<Text> colFams = new HashSet<>(); for (ByteSequence bs : entry.getValue()) { colFams.add(new Text(bs.toArray())); } groups2.put(entry.getKey(), colFams); } return groups2; }
@VisibleForTesting public void put(Key key, Value value) { wlock.lock(); try { if (nmPointer == 0) { throw new IllegalStateException("Native Map Deleted"); } modCount++; singleUpdate(nmPointer, key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getColumnVisibilityData().toArray(), key.getTimestamp(), key.isDeleted(), value.get(), 0); } finally { wlock.unlock(); } }
@Override public synchronized SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { return new VisibilityFilter(source.deepCopy(env), authorizations, defaultVisibility.toArray()); }
/** * Make a new key with a column qualifier, and column visibility. Copy the rest of the parts of * the key (including delete flag) from {@code originalKey}. */ protected Key replaceKeyParts(Key originalKey, Text newColQual, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = newColQual.getBytes(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use * {@code newColFam} as the column family. */ protected Key replaceColumnFamily(Key originalKey, Text newColFam) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = newColFam.getBytes(); byte[] cq = originalKey.getColumnQualifierData().toArray(); byte[] cv = originalKey.getColumnVisibilityData().toArray(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq, 0, cq.length, cv, 0, cv.length, timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
private Set<ByteSequence> findAuths(ByteSequence vis) { HashSet<ByteSequence> auths = new HashSet<>(); byte[] expression = vis.toArray(); Node root = new ColumnVisibility(expression).getParseTree(); findAuths(root, expression, auths); return auths; }
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use * {@code newColQual} as the column qualifier. */ protected Key replaceColumnQualifier(Key originalKey, Text newColQual) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = newColQual.getBytes(); byte[] cv = originalKey.getColumnVisibilityData().toArray(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, newColQual.getLength(), cv, 0, cv.length, timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use * {@code newColVis} as the column visibility. */ protected Key replaceColumnVisibility(Key originalKey, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = originalKey.getColumnQualifierData().toArray(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
/** * Make a new key with a column family, column qualifier, and column visibility. Copy the rest of * the parts of the key (including delete flag) from {@code originalKey}. */ protected Key replaceKeyParts(Key originalKey, Text newColFam, Text newColQual, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = newColFam.getBytes(); byte[] cq = newColQual.getBytes(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq, 0, newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { return ByteBuffer.wrap(bs.toArray()); } }
private static byte[] readPrefix(DataInput in, ByteSequence prefixSource) throws IOException { int prefixLen = WritableUtils.readVInt(in); int remainingLen = WritableUtils.readVInt(in); byte[] data = new byte[prefixLen + remainingLen]; if (prefixSource.isBackedByArray()) { System.arraycopy(prefixSource.getBackingArray(), prefixSource.offset(), data, 0, prefixLen); } else { byte[] prefixArray = prefixSource.toArray(); System.arraycopy(prefixArray, 0, data, 0, prefixLen); } // read remaining in.readFully(data, prefixLen, remainingLen); return data; }
@Override public byte[] getBytes() { if (bsrow.isBackedByArray() && bsrow.offset() == 0) return bsrow.getBackingArray(); return bsrow.toArray(); } };
public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); // read the col fam byte[] cq = readField(din); // read the col qual byte[] cv = readField(din); // read the col visibility long timestamp = din.readLong(); // read the timestamp byte[] valBytes = readField(din); // read the value map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; }
private static byte[] copy(ByteSequence bs) { if (bs.isBackedByArray()) { return Arrays.copyOfRange(bs.getBackingArray(), bs.offset(), bs.offset() + bs.length()); } else { return bs.toArray(); } }
private void consumeRow(ByteSequence row) throws IOException { // try reading a few and if still not to next row, then seek int count = 0; while (source.hasTop() && source.getTopKey().getRowData().equals(row)) { source.next(); count++; if (count >= 10) { Key nextRowStart = new Key(new Text(row.toArray())).followingKey(PartialKey.ROW); reseek(nextRowStart); count = 0; } } }