/** * Decode the key leaving the row portion native to the accumulo key, leaving the source and sink as they are in the accumulo row. Iterators which create * new keys without the builders, can safely decode with this method and reseek to the same position, without knowledge of the underlying escaping encodings * * @param key * a key from the Datawave edge table * @return an immutable EdgeKey object */ public static EdgeKey decodeForInternal(Key key) { EdgeKeyBuilder builder = EdgeKey.newBuilder(); builder.unescape = false; builder.escape = false; return decode(key, builder); }
/** * Creates an edge table key from the various EdgeKey fields. * * @return a key for the Datawave edge table */ public Key encode() { if (this.getDateType() == DATE_TYPE.OLD_EVENT) { return encodeLegacyProtobufKey(); } else { if (this.getFormat() == EDGE_FORMAT.STATS) { return encode(EDGE_VERSION.DATE_STATS_PROTOBUF); } else if (this.getFormat() == EDGE_FORMAT.STANDARD) { return encode(EDGE_VERSION.DATE_PROTOBUF); } else { // EDGE_FORMAT.UNKNOWN throw new IllegalStateException("Can't encode unknown edge key format." + this); } } }
/** * Creates the metadata table key entry for this EdgeKey * * @return a key object for use in the Datawave Metadata table */ public Key getMetadataKey() { Text row = new Text(this.getType() + COL_SEPARATOR + this.getRelationship()); Text colf = new Text(EDGE_METADATA_COLUMN); Text colq = new Text(this.getAttribute1()); return new Key(row, colf, colq, new Text(""), this.getTimestamp()); }
/** * Creates the metadata table key entry for a given edge table Key * * @return a key object for use in the Datawave Metadata table */ public static Key getMetadataKey(Key key) { EdgeKey eKey = EdgeKey.decode(key); return eKey.getMetadataKey(); }
public Key encodeLegacyAttribute2Key() { if (this.getFormat() == EDGE_FORMAT.STATS) { return encode(EDGE_VERSION.STATS_ATTRIBUTE2); } else if (this.getFormat() == EDGE_FORMAT.STANDARD) { return encode(EDGE_VERSION.BASE_ATTRIBUTE2); } else { // EDGE_FORMAT.UNKNOWN throw new IllegalStateException("Can't encode unknown edge key format." + this); } }
private EdgeKeyBuilder(EdgeKey key) { escape = false; format = key.getFormat(); statsType = key.getStatsType(); sourceData = key.getSourceData(); sinkData = key.getSinkData(); type = key.getType(); unescape = false; sourceRelationship = key.getSourceRelationship(); sinkRelationship = key.getSinkRelationship(); sourceAttribute1 = key.getSourceAttribute1(); sinkAttribute1 = key.getSinkAttribute1(); attribute2 = key.getAttribute2(); attribute3 = key.getAttribute3(); yyyymmdd = key.getYyyymmdd(); dateType = key.getDateType(); colvis = new Text(key.getColvis()); timestamp = key.getTimestamp(); deleted = key.isDeleted(); }
EdgeKey edgeKey = EdgeKey.decode(entry.getKey()); Value value = entry.getValue(); boolean statsEdge = edgeKey.isStatsKey(); try { Map<String,String> markings = markingFunctions.translateFromColumnVisibilityForAuths(new ColumnVisibility(edgeKey.getColvis()), auths); edge.setMarkings(markings); edge.setEdgeType(edgeKey.getType()); edge.setEdgeRelationship(edgeKey.getRelationship()); edge.setEdgeAttribute1Source(edgeKey.getAttribute1()); if (edgeKey.getDateType() == EdgeKey.DATE_TYPE.ACTIVITY_ONLY || edgeKey.getDateType() == EdgeKey.DATE_TYPE.ACTIVITY_AND_EVENT) { edge.setActivityDate(edgeKey.getYyyymmdd()); log.error("cound not get markings for " + new ColumnVisibility(edgeKey.getColvis()), ex); edge.setLoadDate(edgeValue.getLoadDate()); } else { edge.setLoadDate(edgeKey.getYyyymmdd()); edge.setSource(edgeKey.getSourceData()); edge.setSink(edgeKey.getSinkData()); edge.setStatsType(edgeKey.getStatsType().name()); switch (edgeKey.getStatsType()) { case ACTIVITY: edge.setCounts(EdgeValueHelper.decodeActivityHistogram(value));
rowsb.append(this.getSourceData()); parts.set(0, STATS_COLF); parts.set(version.getStatsTypeIndex(), this.getStatsType().name()); } else if (this.format == EDGE_FORMAT.STANDARD) { rowsb.append(this.getSourceData()).append("\0").append(this.getSinkData()); } else { throw new IllegalStateException("Invalid Edge Type encountered: " + this.format); parts.set(version.getTypeIndex(), this.getType()); parts.set(version.getRelationshipIndex(), this.getRelationship()); parts.set(version.getCategoryIndex(), this.getAttribute1()); parts.set(version.getYMDIndex(), this.getYyyymmdd()); if (version.hasAttribute2()) { parts.set(version.getAttribute2Index(), this.getAttribute2()); parts.set(version.getAttribute3Index(), this.getAttribute3()); parts.set(version.getDateTypeIndex(), this.getDateType().toString()); colvis = new Text(this.getColvis()); timestamp = this.getTimestamp(); deleted = this.isDeleted();
public static EdgeKey swapSourceSink(EdgeKey swap) { EdgeKeyBuilder builder = newBuilder(swap); builder.setSourceData(swap.getSinkData()); builder.setSinkData(swap.getSourceData()); builder.setSourceRelationship(swap.getSinkRelationship()); builder.setSinkRelationship(swap.getSourceRelationship()); builder.setSourceAttribute1(swap.getSinkAttribute1()); builder.setSinkAttribute1(swap.getSourceAttribute1()); return builder.build(); }
.getSink().getIndexedFieldValue(), this.getVisibility(edgeValue)); Key fwdMetaKey = EdgeKey.getMetadataKey(baseKey); Key revMetaKey = EdgeKey.getMetadataKey(EdgeKey.swapSourceSink(EdgeKey.decode(baseKey)).encode());
protected Key createStatsKey(STATS_TYPE statsType, EdgeDataBundle edgeValue, VertexValue vertex, String value, Text visibility, EdgeKey.DATE_TYPE date_type) { String typeName = edgeValue.getDataTypeName(); datawave.edge.util.EdgeKey.EdgeKeyBuilder builder = datawave.edge.util.EdgeKey.newBuilder(EDGE_FORMAT.STATS).escape(); builder.setSourceData(value).setStatsType(statsType).setType(edgeValue.getEdgeType()).setYyyymmdd(edgeValue.getYyyyMMdd(date_type)) .setSourceRelationship(vertex.getRelationshipType()).setSourceAttribute1(vertex.getCollectionType()) .setTimestamp(edgeValue.getEventDate()).setDateType(date_type); builder.setDeleted(edgeValue.isDeleting()); Key key = builder.build().encode(); boolean isNewKey = false;
/** * Determines if the edge key matches the desired date type.<br> * <strong>note:</strong> Some edges qualify as both an event and an activity edge. Hence, can't simply negate the return value of isEventEdge or * isActivityEdge. * * @param k * @param V * @return boolean - true if it is a match. */ @Override public boolean accept(Key k, Value V) { return (state[EdgeKey.getDateType(k).ordinal()]); }
private Key createEdgeKey(EdgeDataBundle edgeValue, VertexValue source, String sourceValue, VertexValue sink, String sinkValue, Text visibility, long timestamp, EdgeKey.DATE_TYPE date_type) { String typeName = edgeValue.getDataTypeName(); datawave.edge.util.EdgeKey.EdgeKeyBuilder builder = datawave.edge.util.EdgeKey.newBuilder(EDGE_FORMAT.STANDARD).escape(); builder.setSourceData(sourceValue).setSinkData(sinkValue).setType(edgeValue.getEdgeType()).setYyyymmdd(edgeValue.getYyyyMMdd(date_type)) .setSourceRelationship(source.getRelationshipType()).setSinkRelationship(sink.getRelationshipType()) .setSourceAttribute1(source.getCollectionType()).setSinkAttribute1(sink.getCollectionType()) .setAttribute3(edgeValue.getEdgeAttribute3()).setAttribute2(edgeValue.getEdgeAttribute2()).setColvis(visibility) .setTimestamp(timestamp).setDateType(date_type); builder.setDeleted(edgeValue.isDeleting()); return builder.build().encode(); }
public Key encodeLegacyKey() { if (this.getFormat() == EDGE_FORMAT.STATS) { return encode(EDGE_VERSION.STATS_BASE); } else if (this.getFormat() == EDGE_FORMAT.STANDARD) { return encode(EDGE_VERSION.BASE); } else { // EDGE_FORMAT.UNKNOWN throw new IllegalStateException("Can't encode unknown edge key format." + this); } }
/** * Parses edge table keys into the various fields encoded within the key. The source and sink are unescaped, ready to send to external clients. * * @param key * a key from the Datawave edge table * @return an immutable EdgeKey object */ public static EdgeKey decode(Key key) { return decode(key, EdgeKey.newBuilder().unescape()); }
public Key encodeLegacyProtobufKey() { if (this.getFormat() == EDGE_FORMAT.STATS) { return encode(EDGE_VERSION.STATS_PROTOBUF); } else if (this.getFormat() == EDGE_FORMAT.STANDARD) { return encode(EDGE_VERSION.PROTOBUF); } else { // EDGE_FORMAT.UNKNOWN throw new IllegalStateException("Can't encode unknown edge key format." + this); } }