Java Code Examples for org.apache.accumulo.core.data.Key#getColumnVisibility()

The following examples show how to use org.apache.accumulo.core.data.Key#getColumnVisibility() . 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: SpanUtil.java    From fluo with Apache License 2.0 6 votes vote down vote up
/**
 * Converts from an Accumulo Key to a Fluo RowColumn
 * 
 * @param key Key
 * @return RowColumn
 */
public static RowColumn toRowColumn(Key key) {
  if (key == null) {
    return RowColumn.EMPTY;
  }
  if ((key.getRow() == null) || key.getRow().getLength() == 0) {
    return RowColumn.EMPTY;
  }
  Bytes row = ByteUtil.toBytes(key.getRow());
  if ((key.getColumnFamily() == null) || key.getColumnFamily().getLength() == 0) {
    return new RowColumn(row);
  }
  Bytes cf = ByteUtil.toBytes(key.getColumnFamily());
  if ((key.getColumnQualifier() == null) || key.getColumnQualifier().getLength() == 0) {
    return new RowColumn(row, new Column(cf));
  }
  Bytes cq = ByteUtil.toBytes(key.getColumnQualifier());
  if ((key.getColumnVisibility() == null) || key.getColumnVisibility().getLength() == 0) {
    return new RowColumn(row, new Column(cf, cq));
  }
  Bytes cv = ByteUtil.toBytes(key.getColumnVisibility());
  return new RowColumn(row, new Column(cf, cq, cv));
}
 
Example 2
Source File: AccumuloGraphLogger.java    From vertexium with Apache License 2.0 6 votes vote down vote up
private String keyToString(Key key) {
    if (key == null) {
        return "null";
    }
    StringBuilder sb = new StringBuilder();
    appendText(sb, key.getRow());
    if (key.getColumnFamily() != null && key.getColumnFamily().getLength() > 0) {
        sb.append(":");
        appendText(sb, key.getColumnFamily());
    }
    if (key.getColumnQualifier() != null && key.getColumnQualifier().getLength() > 0) {
        sb.append(":");
        appendText(sb, key.getColumnQualifier());
    }
    if (key.getColumnVisibility() != null && key.getColumnVisibility().getLength() > 0) {
        sb.append(":");
        appendText(sb, key.getColumnVisibility());
    }
    if (key.getTimestamp() != Long.MAX_VALUE) {
        sb.append(":");
        sb.append(key.getTimestamp());
    }
    return sb.toString();
}
 
Example 3
Source File: HasAuthorizationFilter.java    From vertexium with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: CompositeSeeker.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public Key nextSeekKey(List<String> fields, Key currentKey, Range currentRange, String separator) {
    Key startKey = currentRange.getStartKey();
    Key endKey = currentRange.getEndKey();
    
    List<String> values = Arrays.asList(currentKey.getRow().toString().split(separator));
    List<String> startValues = Arrays.asList(startKey.getRow().toString().split(separator));
    List<String> endValues = Arrays.asList(endKey.getRow().toString().split(separator));
    
    String nextLowerBound = nextLowerBound(fields, values, separator, startValues, currentRange.isStartKeyInclusive(), endValues,
                    currentRange.isEndKeyInclusive());
    
    Key newStartKey = new Key(new Text(nextLowerBound), startKey.getColumnFamily(), startKey.getColumnQualifier(), startKey.getColumnVisibility(), 0L);
    
    // return a new seek key only if it falls within the current range
    if (currentRange.contains(newStartKey))
        return newStartKey;
    
    return startKey;
}
 
Example 5
Source File: EventToFieldIndexTransform.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static Key fieldIndexKeyToEventKey(Key key) {
    // field index key is shardId : fi\0fieldName : fieldValue\0datatype\0uid
    // event key is shardId : dataType\0uid : fieldName\0fieldValue
    String cf = key.getColumnFamily().toString();
    String cq = key.getColumnQualifier().toString();
    int cqNullIndex = cq.indexOf('\0');
    return new Key(key.getRow(), new Text(cq.substring(cqNullIndex + 1)), new Text(cf.substring(3) + '\0' + cq.substring(0, cqNullIndex)),
                    key.getColumnVisibility(), key.getTimestamp());
}
 
Example 6
Source File: DatawaveFieldIndexCachingIteratorJexl.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * From a field index key, this builds row=shardId, cf=datatype\0UID, cq=fieldname\0fieldvalue Note: in the non-sorted case we need to include the COLQUAL
 * to maintain the position in the FI for reseeking purposes
 *
 * @param key
 * @return Key(shardId, datatype\0UID)
 */
public Key buildEventKey(Key key, PartialKey keyType) {
    // field index key is shardId : fi\0fieldName : fieldValue\0datatype\0uid
    // event key is shardId : dataType\0uid : fieldName\0fieldValue
    String cf = key.getColumnFamily().toString();
    String cq = key.getColumnQualifier().toString();
    // track backwards in the column qualifier to find the end of the value
    int cqNullIndex = cq.lastIndexOf('\0');
    cqNullIndex = cq.lastIndexOf('\0', cqNullIndex - 1);
    String cqStr = cq.substring(cqNullIndex + 1);
    if (!sortedUIDs) {
        // to enable repositioning appropriately in the field index, we need the other elements as well.
        keyType = PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME;
    }
    switch (keyType) {
        case ROW:
            // we really do not support ROW only, at least return the CF which contains the UID
        case ROW_COLFAM:
            return new Key(key.getRow(), new Text(cqStr));
        case ROW_COLFAM_COLQUAL:
            return new Key(key.getRow(), new Text(cqStr), new Text(cf.substring(3) + '\0' + cq.substring(0, cqNullIndex)));
        case ROW_COLFAM_COLQUAL_COLVIS:
            return new Key(key.getRow(), new Text(cqStr), new Text(cf.substring(3) + '\0' + cq.substring(0, cqNullIndex)), key.getColumnVisibility());
        default:
            return new Key(key.getRow(), new Text(cqStr), new Text(cf.substring(3) + '\0' + cq.substring(0, cqNullIndex)), key.getColumnVisibility(),
                            key.getTimestamp());
    }
}
 
Example 7
Source File: ShardUidMappingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
private KeyValue replaceEventUidInCF(KeyValue keyValue, int partIndex, boolean startKey, boolean startKeyInclusive, boolean endKey, boolean endKeyInclusive) {
    Key key = keyValue.getKey();
    String[] replacement = replaceUid(key.getColumnFamily().toString(), partIndex, startKey, startKeyInclusive, endKey, endKeyInclusive);
    // if no change in the uid, then return the original key
    if (replacement == null) {
        return keyValue;
    }
    
    Key newKey = new Key(key.getRow(), new Text(replacement[CQ_INDEX]), key.getColumnQualifier(), key.getColumnVisibility(), key.getTimestamp());
    return new KeyValue(newKey, replacement[ORG_UID_INDEX].getBytes());
}
 
Example 8
Source File: ShardUidMappingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/********************** Helper methods ***********************/
private KeyValue replaceEventUidInCQ(KeyValue keyValue, int partIndex, boolean startKey, boolean startKeyInclusive, boolean endKey, boolean endKeyInclusive) {
    Key key = keyValue.getKey();
    String[] replacement = replaceUid(key.getColumnQualifier().toString(), partIndex, startKey, startKeyInclusive, endKey, endKeyInclusive);
    // if no change in the uid, then return the original key
    if (replacement == null) {
        return keyValue;
    }
    
    Key newKey = new Key(key.getRow(), key.getColumnFamily(), new Text(replacement[CQ_INDEX]), key.getColumnVisibility(), key.getTimestamp());
    return new KeyValue(newKey, replacement[ORG_UID_INDEX].getBytes());
}
 
Example 9
Source File: MetricsDailySummaryReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a simple summation metric value. The key is written out as is and the values, assumed to be string longs, are aggregated and written out.
 */
private Mutation sumMutation(Key key, Iterable<Value> values) {
    LongValueSum sum = new LongValueSum();
    for (Value v : values)
        sum.addNextValue(v);
    
    ColumnVisibility columnVisibility = new ColumnVisibility(key.getColumnVisibility());
    Mutation m = new Mutation(key.getRow());
    m.put(key.getColumnFamily(), key.getColumnQualifier(), columnVisibility, new Value(sum.getReport().getBytes()));
    return m;
}
 
Example 10
Source File: EventToFieldIndexTransform.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static Key eventKeyToFieldIndexKey(Key k) {
    // event key is shardId : dataType\0uid : fieldName\0fieldValue
    // field index key is shardId : fi\0fieldName : fieldValue\0datatype\0uid
    String cf = k.getColumnFamily().toString();
    String cq = k.getColumnQualifier().toString();
    int cqNullIndex = cq.indexOf('\0');
    return new Key(new Text(k.getRow()), new Text("fi\0" + cq.substring(0, cqNullIndex)), new Text(cq.substring(cqNullIndex + 1) + '\0' + cf),
                    k.getColumnVisibility(), k.getTimestamp());
}
 
Example 11
Source File: CompositeSeeker.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public Key nextSeekKey(List<String> fields, Key currentKey, Range currentRange, String separator) {
    Key startKey = currentRange.getStartKey();
    Key endKey = currentRange.getEndKey();
    
    String currentValue = currentKey.getColumnQualifier().toString().split("\0")[0];
    
    String startColQual = startKey.getColumnQualifier().toString();
    String lowerBound = startColQual.split("\0")[0];
    
    String endColQual = endKey.getColumnQualifier().toString();
    String upperBound = endColQual.split("\0")[0];
    
    List<String> values = Arrays.asList(currentValue.split(separator));
    List<String> startValues = Arrays.asList(lowerBound.split(separator));
    List<String> endValues = Arrays.asList(upperBound.split(separator));
    
    String nextLowerBound = nextLowerBound(fields, values, separator, startValues, currentRange.isStartKeyInclusive(), endValues,
                    currentRange.isEndKeyInclusive());
    
    // build a new range only if the new lower bound exceeds the current value without exceeding the upper bound of the range
    if (nextLowerBound.compareTo(currentValue) > 0 && nextLowerBound.compareTo(upperBound) <= 0) {
        String newColQual = nextLowerBound + "\0";
        return new Key(currentKey.getRow(), currentKey.getColumnFamily(), new Text(newColQual), startKey.getColumnVisibility(), 0L);
    }
    
    return startKey;
}
 
Example 12
Source File: IndexOnlyKeyToDocumentData.java    From datawave with Apache License 2.0 5 votes vote down vote up
private Key newResultKey(final Entry<Key,Document> from) {
    final Key key = from.getKey();
    final Text row = key.getRow();
    final Text cf = key.getColumnFamily();
    final Text cq = key.getColumnQualifier();
    final Text visibility = key.getColumnVisibility();
    long timestamp = from.getValue().getTimestamp();
    return new Key(row, cf, cq, visibility, timestamp);
}
 
Example 13
Source File: MetricsDailySummaryReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a "stats" metric value. Each incoming value in {@code values} is assumed to be a unique value. We calculate min, max, median, and average values
 * and include those in the output mutation. Note that median will only be calculated if there are not more than {@code MAX_MEDIAN_COUNT} values. This
 * restriction prevents us from using too much memory in the task tracker.
 */
private Mutation statsMutation(Key key, Iterable<Value> values) {
    long numLongs = 0;
    long min = Long.MAX_VALUE;
    long max = Long.MIN_VALUE;
    longs.clear();
    LongValueSum sum = new LongValueSum();
    for (Value v : values) {
        ++numLongs;
        long aLong = Long.parseLong(v.toString());
        min = Math.min(aLong, min);
        max = Math.max(aLong, max);
        sum.addNextValue(aLong);
        
        if (numLongs <= MAX_MEDIAN_COUNT)
            longs.add(aLong);
    }
    numLongs = Math.max(1, numLongs);
    
    String average = String.format("%1.4f", sum.getSum() / (double) numLongs);
    
    ColumnVisibility columnVisibility = new ColumnVisibility(key.getColumnVisibility());
    Text columnFamily = key.getColumnFamily();
    Mutation m = new Mutation(key.getRow());
    m.put(columnFamily, MIN_TEXT, columnVisibility, new Value(Long.toString(min).getBytes()));
    m.put(columnFamily, MAX_TEXT, columnVisibility, new Value(Long.toString(max).getBytes()));
    m.put(columnFamily, AVERAGE_TEXT, columnVisibility, new Value(average.getBytes()));
    if (numLongs <= MAX_MEDIAN_COUNT) {
        Collections.sort(longs);
        String median = "" + longs.get(longs.size() / 2);
        m.put(columnFamily, MEDIAN_TEXT, columnVisibility, new Value(median.getBytes()));
    }
    return m;
}
 
Example 14
Source File: FacetedTransformer.java    From datawave with Apache License 2.0 4 votes vote down vote up
private FacetsBase _transform(Entry<Key,Document> documentEntry) throws EmptyObjectException {
    if (documentEntry == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    
    Key documentKey = correctKey(documentEntry.getKey());
    Document document = documentEntry.getValue();
    
    if (null == documentKey || null == document)
        throw new IllegalArgumentException("Null key or value. Key:" + documentKey + ", Value: " + documentEntry.getValue());
    
    extractMetrics(document, documentKey);
    document.debugDocumentSize(documentKey);
    
    String row = documentKey.getRow().toString();
    
    String colf = documentKey.getColumnFamily().toString();
    
    int index = colf.indexOf("\0");
    Preconditions.checkArgument(-1 != index);
    
    String dataType = colf.substring(0, index);
    String uid = colf.substring(index + 1);
    
    // We don't have to consult the Document to rebuild the Visibility, the key
    // should have the correct top-level visibility
    ColumnVisibility eventCV = new ColumnVisibility(documentKey.getColumnVisibility());
    
    FacetsBase output = null;
    try {
        // build response method here
        output = buildResponse(document, documentKey, eventCV, colf, row, this.markingFunctions);
    } catch (Exception ex) {
        log.error("Error building response document", ex);
        throw new RuntimeException(ex);
    }
    
    if (output == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    
    if (cardinalityConfiguration != null) {
        collectCardinalities(document, documentKey, uid, dataType);
    }
    
    return output;
}
 
Example 15
Source File: DocumentTransformer.java    From datawave with Apache License 2.0 4 votes vote down vote up
private EventBase _transform(Entry<Key,Document> documentEntry) throws EmptyObjectException {
    if (documentEntry == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    
    Key documentKey = correctKey(documentEntry.getKey());
    Document document = documentEntry.getValue();
    
    if (null == documentKey || null == document)
        throw new IllegalArgumentException("Null key or value. Key:" + documentKey + ", Value: " + documentEntry.getValue());
    
    extractMetrics(document, documentKey);
    document.debugDocumentSize(documentKey);
    
    String row = documentKey.getRow().toString();
    
    String colf = documentKey.getColumnFamily().toString();
    
    int index = colf.indexOf("\0");
    Preconditions.checkArgument(-1 != index);
    
    String dataType = colf.substring(0, index);
    String uid = colf.substring(index + 1);
    
    // We don't have to consult the Document to rebuild the Visibility, the key
    // should have the correct top-level visibility
    ColumnVisibility eventCV = new ColumnVisibility(documentKey.getColumnVisibility());
    
    EventBase output = null;
    try {
        // build response method here
        output = buildResponse(document, documentKey, eventCV, colf, row, this.markingFunctions);
    } catch (Exception ex) {
        log.error("Error building response document", ex);
        throw new RuntimeException(ex);
    }
    
    if (output == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    
    if (cardinalityConfiguration != null) {
        collectCardinalities(document, documentKey, uid, dataType);
    }
    
    return output;
}
 
Example 16
Source File: GlobalIndexDateSummaryIterator.java    From datawave with Apache License 2.0 4 votes vote down vote up
public TermInfo(Key key, Value value) {
    // Get the shard id and datatype from the colq
    fieldValue = key.getRow().toString();
    fieldName = key.getColumnFamily().toString();
    String colq = key.getColumnQualifier().toString();
    
    int separator = colq.indexOf(Constants.NULL_BYTE_STRING);
    if (separator != -1) {
        int end_separator = colq.lastIndexOf(Constants.NULL_BYTE_STRING);
        // if we have multiple separators, then we must have a tasking data type entry.
        if (separator != end_separator) {
            // ensure we at least have yyyyMMdd
            if ((end_separator - separator) < 9) {
                return;
            }
            // in this case the form is datatype\0date\0task status (old knowledge entry)
            date = colq.substring(separator + 1, separator + 9);
            datatype = colq.substring(0, separator);
        } else {
            // ensure we at least have yyyyMMdd
            if (separator < 8) {
                return;
            }
            // in this case the form is shardid\0datatype
            date = colq.substring(0, 8);
            datatype = colq.substring(separator + 1);
        }
        
        // Parse the UID.List object from the value
        Uid.List uidList = null;
        try {
            uidList = Uid.List.parseFrom(value.get());
            if (null != uidList) {
                count = uidList.getCOUNT();
            }
        } catch (InvalidProtocolBufferException e) {
            // Don't add UID information, at least we know what shard
            // it is located in.
        }
        
        Text tvis = key.getColumnVisibility();
        vis = new ColumnVisibility(tvis);
        
        // we now have a valid info
        valid = true;
    }
}
 
Example 17
Source File: ResultCountingIterator.java    From datawave with Apache License 2.0 4 votes vote down vote up
private Key addKeyCount(Key key) {
    resultCount.getAndIncrement();
    return new Key(key.getRow(), new Text(NumericalEncoder.encode(Long.toString(resultCount.get())) + '\0' + key.getColumnFamily()),
                    key.getColumnQualifier(), key.getColumnVisibility(), key.getTimestamp());
}
 
Example 18
Source File: IndexOnlyKeyToDocumentData.java    From datawave with Apache License 2.0 4 votes vote down vote up
private Entry<Key,Value> newFieldKeyFromTfKey(final Key tfKey, final KeyConversionAttributes attributes) {
    // Begin extracting information from the tf key that may, if relevant,
    // be used to create a standard record field key
    final Text row = tfKey.getRow();
    final Text cf = tfKey.getColumnFamily();
    final Text cq = tfKey.getColumnQualifier();
    final String tfCqPrefix = attributes.getTfCqPrefix();
    final String tfCqSuffix = attributes.getTfCqSuffix();
    final Text newCf = attributes.getNewCf();
    
    // Declare the return value
    final Entry<Key,Value> holder;
    
    // Validate the tf column family for null
    if (null == cf) {
        holder = NULL_COLUMNFAMILY_KEY;
    }
    // Validate the tf column qualifier for null
    else if (null == cq) {
        holder = NULL_COLUMNQUALIFIER_KEY;
    }
    // Otherwise, examine the column qualifier more closely. If it's still relevant,
    // construct a standard record field key.
    else {
        // Extract a string version of the column qualifier
        final String cqAsString = cq.toString();
        
        // Verify a non-null string
        if (null == cqAsString) {
            holder = NULL_COLUMNQUALIFIER_KEY;
        }
        // Ignore a top-level tf key. Although the range used via the IndexOnlyFunctionIterator
        // should prevent such a key from being scanned/created, this validation safeguards
        // against the return of invalid keys.
        else if (cqAsString.isEmpty()) {
            holder = TOP_RECORD_KEY;
        }
        // Verify the prefix matches the document's desired column family. Although the range
        // constructed via the IndexOnlyFunctionIterator should prevent an invalid cf from reaching
        // this point, this validation safeguards against its processing.
        else if (!cqAsString.startsWith(tfCqPrefix)) {
            holder = WRONG_DOCUMENT_KEY;
        }
        // Verify the suffix matches the field name. Although the range constructed via the
        // IndexOnlyFunctionIterator should prevent an invalid cq prefix from reaching this point,
        // this validation safeguards against its processing.
        else if (!cqAsString.endsWith(tfCqSuffix)) {
            holder = WRONG_FIELD_KEY;
        }
        // Extract the tf record's value without the use of String.split() or instantiating more than
        // a single String. Although splitting on the null character may seem quick and easy, unexpected
        // results may occur if the value contains one or more null characters.
        else {
            // Declare the value, which will be assigned only once for sake of efficiency
            final String value;
            
            // Get the lengths of the relevant strings
            int cqLength = cqAsString.length();
            int prefixLength = tfCqPrefix.length();
            int suffixLength = tfCqSuffix.length();
            
            // Verify that the cq string's length is at least as big as the combined
            // prefix and suffix
            if (cqLength >= (prefixLength + suffixLength)) {
                // Extract and assign the value
                value = cqAsString.substring(prefixLength, (cqLength - suffixLength));
            } else {
                value = null;
            }
            
            // If a value is defined, even if it is an empty string, use it to construct a new
            // field key
            if (null != value) {
                final Text newFieldCq = new Text(this.fieldName + this.delimiter + value);
                final Key newKey = new Key(row, newCf, newFieldCq, tfKey.getColumnVisibility(), tfKey.getTimestamp());
                holder = Maps.immutableEntry(newKey, EMPTY_VALUE);
            } else {
                holder = INVALID_COLUMNQUALIFIER_FORMAT_KEY;
            }
        }
    }
    
    return holder;
}
 
Example 19
Source File: TermInfo.java    From datawave with Apache License 2.0 4 votes vote down vote up
public TermInfo(Key key, Value value) {
    // Get the shard id and datatype from the colq
    fieldValue = key.getRow().toString();
    fieldName = key.getColumnFamily().toString();
    String colq = key.getColumnQualifier().toString();
    
    int separator = colq.indexOf(Constants.NULL_BYTE_STRING);
    if (separator != -1) {
        int end_separator = colq.lastIndexOf(Constants.NULL_BYTE_STRING);
        // if we have multiple separators, then we must have a tasking data type entry.
        if (separator != end_separator) {
            // ensure we at least have yyyyMMdd
            if ((end_separator - separator) < 9) {
                return;
            }
            // in this case the form is datatype\0date\0task status (old knowledge entry)
            date = colq.substring(separator + 1, separator + 9);
            datatype = colq.substring(0, separator);
        } else {
            // ensure we at least have yyyyMMdd
            if (separator < 8) {
                return;
            }
            // in this case the form is shardid\0datatype
            date = colq.substring(0, 8);
            datatype = colq.substring(separator + 1);
        }
        
        // Parse the UID.List object from the value
        Uid.List uidList = null;
        try {
            uidList = Uid.List.parseFrom(value.get());
            if (null != uidList) {
                count = uidList.getCOUNT();
                setListSize(uidList.getUIDList().size());
            }
        } catch (InvalidProtocolBufferException e) {
            // Don't add UID information, at least we know what shard
            // it is located in.
        }
        
        Text tvis = key.getColumnVisibility();
        vis = new ColumnVisibility(tvis);
        
        // we now have a valid info
        valid = true;
    }
}