Java Code Examples for org.apache.accumulo.core.data.Value#get()

The following examples show how to use org.apache.accumulo.core.data.Value#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryFilterIterator.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected FlattenedUnreadData aggregateFieldData(
    final Key key,
    final Value value,
    final PersistentDataset<CommonIndexValue> commonData) {
  final GeoWaveKey gwKey = new GeoWaveKeyImpl(key.getRow().copyBytes(), partitionKeyLength);
  final GeoWaveValue gwValue =
      new GeoWaveValueImpl(
          key.getColumnQualifier().getBytes(),
          key.getColumnVisibilityData().getBackingArray(),
          value.get());
  return DataStoreUtils.aggregateFieldData(
      gwKey,
      gwValue,
      commonData,
      model,
      commonIndexFieldNames);
}
 
Example 2
Source File: ChunkCombiner.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private String diffInfo(Value v1, Value v2) {
  if (v1.getSize() != v2.getSize()) {
    return "val len not equal " + v1.getSize() + "!=" + v2.getSize();
  }

  byte[] vb1 = v1.get();
  byte[] vb2 = v2.get();

  for (int i = 0; i < vb1.length; i++) {
    if (vb1[i] != vb2[i]) {
      return String.format("first diff at offset %,d 0x%02x != 0x%02x", i, 0xff & vb1[i],
          0xff & vb2[i]);
    }
  }

  return null;
}
 
Example 3
Source File: IteratorHistoricalEvent.java    From vertexium with Apache License 2.0 6 votes vote down vote up
public static List<IteratorHistoricalEvent> decode(Value value, String elementId) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(value.get());
    DataInputStream din = new DataInputStream(in);
    List<IteratorHistoricalEvent> results = new ArrayList<>();
    byte[] header = new byte[HEADER.length];
    int read = din.read(header);
    if (read != header.length) {
        throw new IOException("Invalid header length. Found " + read + " expected " + header.length);
    }
    if (!Arrays.equals(header, HEADER)) {
        throw new IOException("Invalid header.");
    }
    int resultsLength = din.readInt();
    for (int i = 0; i < resultsLength; i++) {
        results.add(decodeEvent(din, elementId));
    }
    if (din.available() > 0) {
        throw new IOException("Expected end of array. Found " + din.available() + " more bytes");
    }
    return results;
}
 
Example 4
Source File: EmptyEncodedRowFilter.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Override
public boolean accept(Key key, Value value) {

    if(key.getColumnFamily().toString().startsWith(Constants.PREFIX_E)) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(value.get());
            DataInputStream dis = new DataInputStream(bais);
            long size = dis.readInt();
            return value.get().length > 0 &&  size > 0;
        } catch (IOException e) {
            return false;
        }
    }

    return true;
}
 
Example 5
Source File: GlobalIndexValue.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
public GlobalIndexValue(Value value) {

        String str = new String(value.get());

        int idx = str.indexOf(",");

        if(idx == -1) {
            cardinatlity = Long.parseLong(str);
            expiration = -1;
        } else {
            cardinatlity = Long.parseLong(str.substring(0, idx));
            expiration = Long.parseLong(str.substring(idx + 1, str.length()));
        }
    }
 
Example 6
Source File: KeyValueSerializable.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    this.key = new Key();
    key.readFields(in);
    Value val = new Value();
    val.readFields(in);
    this.value = val.get();
}
 
Example 7
Source File: SecondaryIndexQueryFilterIterator.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public boolean acceptRow(final SortedKeyValueIterator<Key, Value> rowIterator)
    throws IOException {
  if (filter != null) {
    while (rowIterator.hasTop()) {
      final Key key = rowIterator.getTopKey();
      final Value value = rowIterator.getTopValue();
      final String cq =
          StringUtils.stringFromBinary(key.getColumnQualifierData().getBackingArray());
      if (!cq.equals(primaryIndexId)) {
        final IndexedPersistenceEncoding<ByteArray> persistenceEncoding =
            new IndexedPersistenceEncoding<>(
                null, // not needed
                null, // not needed
                null, // not needed
                null, // not needed
                0, // not needed
                new MultiFieldPersistentDataset<>(
                    StringUtils.stringFromBinary(key.getColumnQualifierData().getBackingArray()),
                    new ByteArray(value.get())),
                null);
        if (filter.accept(null, persistenceEncoding)) {
          return true;
        }
      }
      rowIterator.next();
    }
    return false;
  }
  // should not happen but if the filter is not sent to this iterator, it
  // will accept everything
  return true;
}
 
Example 8
Source File: QueryUtil.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static <T extends Query> T deserialize(String queryImplClassName, Text columnVisibility, Value value) throws InvalidProtocolBufferException,
                ClassNotFoundException {
    @SuppressWarnings("unchecked")
    Class<T> queryClass = (Class<T>) Class.forName(queryImplClassName);
    byte[] b = value.get();
    Schema<T> schema = RuntimeSchema.getSchema(queryClass);
    T queryImpl = schema.newMessage();
    ProtobufIOUtil.mergeFrom(b, queryImpl, schema);
    queryImpl.setColumnVisibility(columnVisibility.toString());
    return queryImpl;
}
 
Example 9
Source File: DownsampleIterator.java    From timely with Apache License 2.0 5 votes vote down vote up
public static Map<Set<Tag>, Downsample> decodeValue(Value value) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(value.get());
    ObjectInputStream ois = new ObjectInputStream(bis);
    @SuppressWarnings("unchecked")
    Map<Set<Tag>, Downsample> unchecked = (Map<Set<Tag>, Downsample>) ois.readObject();
    return unchecked;
}
 
Example 10
Source File: AggregationIterator.java    From timely with Apache License 2.0 5 votes vote down vote up
public static Map<Set<Tag>, Aggregation> decodeValue(Value value) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(value.get());
    ObjectInputStream ois = new ObjectInputStream(bis);
    @SuppressWarnings("unchecked")
    Map<Set<Tag>, Aggregation> unchecked = (Map<Set<Tag>, Aggregation>) ois.readObject();
    return unchecked;
}
 
Example 11
Source File: HistoricalEventsIterator.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private Value readHiddenValue(KeyValue r) {
    Value v = r.peekValue();
    if (ElementIterator.HIDDEN_VALUE.equals(v) || ElementIterator.HIDDEN_VALUE_DELETED.equals(v)) {
        return null;
    }
    byte[] hiddenValueDeletedArray = ElementIterator.HIDDEN_VALUE_DELETED.get();
    if (ArrayUtils.startsWith(v.get(), hiddenValueDeletedArray)) {
        byte[] data = new byte[v.get().length - hiddenValueDeletedArray.length];
        System.arraycopy(v.get(), hiddenValueDeletedArray.length, data, 0, data.length);
        return new Value(data);
    } else {
        return r.takeValue();
    }
}
 
Example 12
Source File: MetadataExpirationFilter.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
protected long parseTimestampFromValue(Value v) {
    ByteArrayInputStream bais = new ByteArrayInputStream(v.get());
    DataInputStream dis = new DataInputStream(bais);
    try {
        dis.readLong();
        long returnVal = dis.readLong();
        return returnVal;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return -1;
}
 
Example 13
Source File: AccumuloNamespaceTableIterator.java    From rya with Apache License 2.0 5 votes vote down vote up
public static Namespace getNamespace(final Iterator<Entry<Key, Value>> rowResults) {
    for (; rowResults.hasNext(); ) {
        final Entry<Key, Value> next = rowResults.next();
        final Key key = next.getKey();
        final Value val = next.getValue();
        final String cf = key.getColumnFamily().toString();
        final String cq = key.getColumnQualifier().toString();
        return new NamespaceImpl(key.getRow().toString(),
                new String(val.get(), StandardCharsets.UTF_8));
    }
    return null;
}
 
Example 14
Source File: MergeToolMapper.java    From rya with Apache License 2.0 5 votes vote down vote up
private static RyaStatement createRyaStatement(final Key key, final Value value, final RyaTripleContext ryaTripleContext) throws TripleRowResolverException {
    final byte[] row = key.getRowData() != null  && key.getRowData().toArray().length > 0 ? key.getRowData().toArray() : null;
    final byte[] columnFamily = key.getColumnFamilyData() != null  && key.getColumnFamilyData().toArray().length > 0 ? key.getColumnFamilyData().toArray() : null;
    final byte[] columnQualifier = key.getColumnQualifierData() != null  && key.getColumnQualifierData().toArray().length > 0 ? key.getColumnQualifierData().toArray() : null;
    final Long timestamp = key.getTimestamp();
    final byte[] columnVisibility = key.getColumnVisibilityData() != null && key.getColumnVisibilityData().toArray().length > 0 ? key.getColumnVisibilityData().toArray() : null;
    final byte[] valueBytes = value != null && value.get().length > 0 ? value.get() : null;
    final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier, timestamp, columnVisibility, valueBytes);
    final RyaStatement ryaStatement = ryaTripleContext.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow);

    return ryaStatement;
}
 
Example 15
Source File: ReadAheadIterator.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
public QueueElement(Key key, Value value) {
    super();
    this.key = new Key(key);
    this.value = new Value(value.get(), true);
}
 
Example 16
Source File: IndexEntryFilteringIterator.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
/**
 * Makes sure only those rows with an index row are kept around. The versioning iterator should have run already
 * and evicted older index rows.
 *
 * @param key
 * @param value
 * @return
 */
@Override
public boolean accept(Key key, Value value) {

    try {
        // first find out if we are inside of an index row
        if (key.getColumnFamily().toString().equals(NULL_BYTE + "INDEX")) {

            if (!key.getRow().toString().equals(currentIndex)) {
                currentIndex = key.getRow().toString();
                uuidSet = new HashSet<String>();
            }

            uuidSet.add(new String(value.get()));

            return true;
        }

        // otherwise, assume we are in an event row
        else {

            String uuid = key.getColumnFamily().toString().replace(END_BYTE, "");
            String hash = new String(value.get());

            if (!uuidSet.contains(uuid + NULL_BYTE + hash)) {
                return false;
            }

            String[] keyValue = key.getColumnQualifier().toString().split(NULL_BYTE);

            // here we want to make sure that any duplicate events added are filtered out (this is possible simply
            // because the maxVersions > 1)

            if (previousEvent != null && previousEvent.equals(key.getRow() + NULL_BYTE + uuid + NULL_BYTE + hash
                    + NULL_BYTE + keyValue[0] + NULL_BYTE + keyValue[1])) {
                return false;
            }

            previousEvent = key.getRow() + NULL_BYTE + uuid + NULL_BYTE + hash + NULL_BYTE
                    + keyValue[0] + NULL_BYTE + keyValue[1];

        }
    } catch (Exception e) {

        return true;
    }

    return true;
}
 
Example 17
Source File: AccumuloEdge.java    From vertexium with Apache License 2.0 4 votes vote down vote up
public static Edge createFromIteratorValue(
    AccumuloGraph graph,
    Key key,
    Value value,
    FetchHints fetchHints,
    Authorizations authorizations
) {
    try {
        String edgeId;
        Visibility vertexVisibility;
        Iterable<Property> properties;
        Iterable<Visibility> hiddenVisibilities;
        long timestamp;

        ByteArrayInputStream bain = new ByteArrayInputStream(value.get());
        try (DataInputStream in = DataInputStreamUtils.decodeHeader(bain, ElementData.TYPE_ID_EDGE)) {
            edgeId = DataInputStreamUtils.decodeString(in);
            timestamp = in.readLong();
            vertexVisibility = new Visibility(DataInputStreamUtils.decodeString(in));

            hiddenVisibilities = Iterables.transform(DataInputStreamUtils.decodeStringSet(in), new Function<String, Visibility>() {
                @Nullable
                @Override
                public Visibility apply(String input) {
                    return new Visibility(input);
                }
            });

            ImmutableSet<String> additionalVisibilities = DataInputStreamUtils.decodeStringSet(in);

            List<MetadataEntry> metadataEntries = DataInputStreamUtils.decodeMetadataEntries(in);
            properties = DataInputStreamUtils.decodeProperties(graph, in, metadataEntries, fetchHints);
            ImmutableSet<String> extendedDataTableNames = DataInputStreamUtils.decodeStringSet(in);
            String inVertexId = DataInputStreamUtils.decodeString(in);
            String outVertexId = DataInputStreamUtils.decodeString(in);
            String label = graph.getNameSubstitutionStrategy().inflate(DataInputStreamUtils.decodeString(in));

            return new AccumuloEdge(
                graph,
                edgeId,
                outVertexId,
                inVertexId,
                label,
                null,
                vertexVisibility,
                properties,
                null,
                null,
                hiddenVisibilities,
                additionalVisibilities,
                extendedDataTableNames,
                timestamp,
                fetchHints,
                authorizations
            );
        }
    } catch (IOException ex) {
        throw new VertexiumException("Could not read vertex", ex);
    }
}
 
Example 18
Source File: EntryIterator.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
/**
 * For each index row in the lastN store, grab the associated getAttributes (further down in the tablet) and construct
 * the entry to be returned.
 *
 * @return
 */
@Override
public Value getTopValue() {

    if (hasTop()) {

        Key topKey = getTopKey();
        Value topVal = super.getTopValue();
        String entryId = new String(topVal.get());

        Key startRangeKey = new Key(topKey.getRow(), new Text(END_BYTE + entryId));
        Key stopRangeKey = new Key(topKey.getRow(), new Text(END_BYTE + entryId + END_BYTE));

        Range range = new Range(startRangeKey, stopRangeKey);

        long timestamp = 0;

        try {
            sourceItr.seek(range, Collections.<ByteSequence>emptyList(), false);

            Collection<Attribute> attributes = new ArrayList<Attribute>();
            while (sourceItr.hasTop()) {

                Key nextKey = sourceItr.getTopKey();
                sourceItr.next();

                if (!nextKey.getColumnFamily().toString().endsWith(entryId)) {
                    break;
                }

                String[] keyValueDatatype = nextKey.getColumnQualifier().toString().split(NULL_BYTE);

                if (keyValueDatatype.length == 3) {

                    String vis = nextKey.getColumnVisibility().toString();

                    Attribute attribute = new Attribute(
                            keyValueDatatype[0],
                            typeRegistry.decode(keyValueDatatype[2], keyValueDatatype[1]),
                            setVisibility(new HashMap<String, String>(1), vis)
                    );


                    attributes.add(attribute);
                    timestamp = nextKey.getTimestamp();
                }
            }

            int oneByte = entryId.indexOf(ONE_BYTE);
            String finalType = entryId.substring(0, oneByte);
            String finalId = entryId.substring(oneByte+1, entryId.length());

            EventBuilder entry = EventBuilder.create(finalType, finalId, timestamp);

            if (attributes.size() > 0)
                entry.attrs(attributes);

            writable.set(entry.build());
            return new Value(serialize(writable));

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return new Value("".getBytes());
}
 
Example 19
Source File: CountAggregatingIterator.java    From datawave with Apache License 2.0 4 votes vote down vote up
private ResultCountingIterator.ResultCountTuple unpackValue(Value value) {
    ByteArrayInputStream bais = new ByteArrayInputStream(value.get());
    Input input = new Input(bais);
    return kryo.readObject(input, ResultCountingIterator.ResultCountTuple.class);
}
 
Example 20
Source File: RowEncoderUtil.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
public static final List<Map.Entry<Key,Value>> decodeRow(Key rowKey, Value rowValue) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get());
    return decodeRow(rowKey, in);
}