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

The following examples show how to use org.apache.accumulo.core.data.Key#getColumnQualifier() . 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: 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 4
Source File: MetricsDailySummaryReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
protected void reduce(Key key, Iterable<Value> values, Context context) throws IOException, InterruptedException {
    key.getColumnQualifier(holder);
    Mutation m;
    if (STATS_METRIC_TEXT.equals(holder))
        m = statsMutation(key, values);
    else if (PERCENTILE_STATS_METRIC_TEXT.equals(holder))
        m = statsPercentileMutation(key, values);
    else
        m = sumMutation(key, values);
    context.write(empty, m);
}
 
Example 5
Source File: Reverse.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  opts.parseArgs(Reverse.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      Scanner scanner = client.createScanner(opts.shardTable, Authorizations.EMPTY);
      BatchWriter bw = client.createBatchWriter(opts.doc2TermTable)) {
    for (Entry<Key,Value> entry : scanner) {
      Key key = entry.getKey();
      Mutation m = new Mutation(key.getColumnQualifier());
      m.put(key.getColumnFamily(), new Text(), new Value(new byte[0]));
      bw.addMutation(m);
    }
  }
}
 
Example 6
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 7
Source File: BucketRollupIterator.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@Override
public Key getTopKey() {
    Key topKey = super.getTopKey();

    long timestamp = reverseTimestampToNormalTime(Long.parseLong(topKey.getRow().toString()));

    Key retKey = new Key(new Text(truncatedReverseTimestamp(timestamp, bucketSize).toString()),
            topKey.getColumnFamily(), topKey.getColumnQualifier(),
            new Text(topKey.getColumnVisibility().toString()), topKey.getTimestamp());

    return retKey;
}
 
Example 8
Source File: CreateUidsIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Method that ensures if we have to skip the current key, we do so with the contract provided by the create UID iterator.
 * 
 * @param range
 */
protected Range skipKey(Range range) {
    Key startKey = range.getStartKey();
    Key newKey = new Key(startKey.getRow(), startKey.getColumnFamily(), new Text(startKey.getColumnQualifier() + "\u0000\uffff"));
    return new Range(newKey, true, range.getEndKey(), range.isEndKeyInclusive());
    
}
 
Example 9
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 10
Source File: ValueToAttributes.java    From datawave with Apache License 2.0 5 votes vote down vote up
public Attribute<?> getFieldValue(String fieldName, Key k) {
    k.getColumnQualifier(holder);
    int index = holder.find(Constants.NULL);
    
    if (0 > index) {
        throw new IllegalArgumentException("Could not find null-byte contained in columnqualifier for key: " + k);
    }
    
    try {
        String data = Text.decode(holder.getBytes(), index + 1, (holder.getLength() - (index + 1)));
        
        ColumnVisibility cv = getCV(k);
        
        Attribute<?> attr = this.attrFactory.create(fieldName, data, k, (attrFilter == null || attrFilter.keep(k)));
        if (attrFilter != null) {
            attr.setToKeep(attrFilter.keep(k));
        }
        
        if (log.isTraceEnabled()) {
            log.trace("Created " + attr.getClass().getName() + " for " + fieldName);
        }
        
        return attr;
    } catch (CharacterCodingException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 11
Source File: FileByteSummaryLoader.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
protected void map(Key key, Value value, Context context) throws IOException, InterruptedException {
    key.getRow(holder);
    String name = holder.toString().substring(12);
    long loadTime = key.getTimestamp();
    String outRow = DateHelper.format(new Date(loadTime));
    Matcher m = radixRegex.matcher(name);
    key.getColumnQualifier(holder);
    if (m.matches()) {
        context.write(makeKey(outRow, "GROOMER_RLABEL_FILES", m.group(1), defaultVisibility), makeValue("1"));
        context.write(makeKey(outRow, "GROOMER_RLABEL_BYTES", m.group(1), defaultVisibility), makeValue(holder.toString()));
    }
}
 
Example 12
Source File: IdentityAggregator.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
protected Key getSeekStartKey(Key current, ByteSequence pointer) {
    return new Key(current.getRow(), current.getColumnFamily(), current.getColumnQualifier(), 0);
}
 
Example 13
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 14
Source File: NormalizerLoader.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean store(String storeKey, Key key, Value value) {
    boolean reverse = false;
    
    if (log.isTraceEnabled())
        log.trace("== Requesting to store " + storeKey + " " + key);
    
    if (null != key.getColumnQualifier()) {
        String colq = key.getColumnQualifier().toString();
        int idx = colq.indexOf(Constants.NULL);
        
        if (key.getColumnFamily().toString().equals(ColumnFamilyConstants.COLF_RI.toString())) {
            reverse = true;
        }
        
        if (idx != -1) {
            try {
                String type = colq.substring(0, idx);
                
                Multimap<String,Type<?>> dataNormalizer = entryCache.get("DATA_TYPES");
                
                if (null == dataNormalizer) {
                    dataNormalizer = ArrayListMultimap.create();
                    entryCache.put("DATA_TYPES", dataNormalizer);
                }
                
                dataNormalizer.put(type, LcNoDiacriticsType.class.newInstance());
                
                if (!dataTypeFilters.isEmpty() && !dataTypeFilters.contains(type)) {
                    if (log.isTraceEnabled())
                        log.trace("Returning since " + type + " is not in the data type cache");
                    return false;
                }
                
                String row = key.getRow().toString().toUpperCase();
                
                if (reverse)
                    row = new StringBuffer(row).reverse().toString();
                
                Multimap<String,Type<?>> typedNormalizers = entryCache.get(row);
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(row, typedNormalizers);
                }
                
                @SuppressWarnings("unchecked")
                Class<? extends Type<?>> clazz = (Class<? extends Type<?>>) Class.forName(colq.substring(idx + 1));
                
                Type<?> normalizer = clazz.newInstance();
                
                typedNormalizers.put(type, normalizer);
                
                typedNormalizers = entryCache.get(type);
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(type, typedNormalizers);
                }
                
                typedNormalizers.put(row, normalizer);
                
                typedNormalizers = entryCache.get(clazz.getCanonicalName());
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(clazz.getCanonicalName(), typedNormalizers);
                }
                
                typedNormalizers.put(row, normalizer);
                
                return true;
                
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                log.error("Unable to find normalizer on class path: " + colq.substring(idx + 1), e);
            }
            
        }
    }
    return false;
    
}
 
Example 15
Source File: IndexedFieldLoader.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean store(String storeKey, Key key, Value value) {
    boolean reverse = false;
    
    if (log.isTraceEnabled())
        log.trace("== Requesting to store " + storeKey + " " + key);
    
    if (null != key.getColumnQualifier()) {
        String colq = key.getColumnQualifier().toString();
        int idx = colq.indexOf(Constants.NULL);
        
        if (key.getColumnFamily().equals(ColumnFamilyConstants.COLF_RI)) {
            reverse = true;
        }
        
        if (idx != -1) {
            try {
                String type = colq.substring(0, idx);
                
                Set<String> dataNormalizer = entryCache.get("DATA_TYPES");
                
                if (null == dataNormalizer) {
                    dataNormalizer = Sets.newHashSet();
                    entryCache.put("DATA_TYPES", dataNormalizer);
                }
                
                dataNormalizer.add(type);
                
                if (!dataTypeFilters.isEmpty() && !dataTypeFilters.contains(type)) {
                    if (log.isTraceEnabled())
                        log.trace("Returning since " + type + " is not in the data type cache");
                    return false;
                }
                
                String row = key.getRow().toString().toUpperCase();
                
                if (reverse)
                    row = new StringBuffer(row).reverse().toString();
                
                Set<String> typedNormalizers = entryCache.get(row);
                
                if (typedNormalizers == null) {
                    typedNormalizers = Sets.newHashSet();
                    entryCache.put(row, typedNormalizers);
                }
                
                @SuppressWarnings("unchecked")
                Class<? extends Type<?>> clazz = (Class<? extends Type<?>>) Class.forName(colq.substring(idx + 1));
                
                Type<?> normalizer = clazz.newInstance();
                
                typedNormalizers.add(type);
                
                typedNormalizers = entryCache.get(type);
                
                if (typedNormalizers == null) {
                    typedNormalizers = Sets.newHashSet();
                    entryCache.put(type, typedNormalizers);
                }
                
                typedNormalizers.add(row);
                
                typedNormalizers = entryCache.get(clazz.getCanonicalName());
                
                if (typedNormalizers == null) {
                    typedNormalizers = Sets.newHashSet();
                    entryCache.put(clazz.getCanonicalName(), typedNormalizers);
                }
                
                typedNormalizers.add(row);
                
                return true;
                
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                log.error("Unable to find normalizer on class path: " + colq.substring(idx + 1), e);
            }
            
        }
    }
    return false;
    
}
 
Example 16
Source File: DatatypeLoader.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean store(String storeKey, Key key, Value value) {
    boolean reverse = false;
    
    if (log.isTraceEnabled())
        log.trace("== Requesting to store " + storeKey + " " + key);
    
    if (null != key.getColumnQualifier()) {
        String colq = key.getColumnQualifier().toString();
        int idx = colq.indexOf(Constants.NULL);
        
        if (key.getColumnFamily().equals(ColumnFamilyConstants.COLF_RI)) {
            reverse = true;
        }
        
        if (idx != -1) {
            try {
                String type = colq.substring(0, idx);
                
                Multimap<String,Type<?>> dataNormalizer = entryCache.get("DATA_TYPES");
                
                if (null == dataNormalizer) {
                    dataNormalizer = ArrayListMultimap.create();
                    entryCache.put("DATA_TYPES", dataNormalizer);
                }
                
                dataNormalizer.put(type, LcNoDiacriticsType.class.newInstance());
                
                if (!dataTypeFilters.isEmpty() && !dataTypeFilters.contains(type)) {
                    if (log.isTraceEnabled())
                        log.trace("Returning since " + type + " is not in the data type cache");
                    return false;
                }
                
                String row = key.getRow().toString().toUpperCase();
                
                if (reverse)
                    row = new StringBuffer(row).reverse().toString();
                
                Multimap<String,Type<?>> typedNormalizers = entryCache.get(row);
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(row, typedNormalizers);
                }
                
                @SuppressWarnings("unchecked")
                Class<? extends Type<?>> clazz = (Class<? extends Type<?>>) Class.forName(colq.substring(idx + 1));
                
                Type<?> normalizer = clazz.newInstance();
                
                typedNormalizers.put(type, normalizer);
                
                typedNormalizers = entryCache.get(type);
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(type, typedNormalizers);
                }
                
                typedNormalizers.put(row, normalizer);
                
                typedNormalizers = entryCache.get(clazz.getCanonicalName());
                
                if (typedNormalizers == null) {
                    typedNormalizers = ArrayListMultimap.create();
                    entryCache.put(clazz.getCanonicalName(), typedNormalizers);
                }
                
                typedNormalizers.put(row, normalizer);
                
                return true;
                
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                log.error("Unable to find normalizer on class path: " + colq.substring(idx + 1), e);
            }
            
        }
    }
    return false;
    
}
 
Example 17
Source File: QueryModelLoader.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean store(Entry<String,String> storeKey, Key key, Value value) {
    if (log.isDebugEnabled())
        log.debug("== Requesting to store (" + storeKey.getKey() + "," + storeKey.getValue() + ") " + key);
    
    Set<String> indexOnlyFields = new HashSet<>(); // will hold index only fields
    // We need the entire Model so we can do both directions.
    
    Entry<QueryModel,Set<String>> modelEntry = entryCache.get(storeKey);
    
    QueryModel queryModel = null;
    
    if (null == modelEntry)
        queryModel = new QueryModel();
    else
        queryModel = modelEntry.getKey();
    
    if (null != key.getColumnQualifier()) {
        String original = key.getRow().toString();
        Text cq = key.getColumnQualifier();
        String[] parts = StringUtils.split(cq.toString(), "\0");
        if (parts.length > 1 && null != parts[0] && !parts[0].isEmpty()) {
            String replacement = parts[0];
            
            for (String part : parts) {
                if ("forward".equalsIgnoreCase(part)) {
                    // Do *not* add a forward mapping entry
                    // when the replacement does not exist in the database
                    if (allFields == null || allFields.contains(replacement)) {
                        queryModel.addTermToModel(original, replacement);
                    } else if (log.isTraceEnabled()) {
                        log.trace("Ignoring forward mapping of " + replacement + " for " + original + " because the metadata table has no reference to it");
                        
                    }
                    
                } else if ("reverse".equalsIgnoreCase(part)) {
                    queryModel.addTermToReverseModel(original, replacement);
                } else if ("index_only".equalsIgnoreCase(part)) {
                    indexOnlyFields.add(replacement);
                }
            }
        }
    }
    
    entryCache.put(storeKey, Maps.immutableEntry(queryModel, indexOnlyFields));
    
    return true;
    
}
 
Example 18
Source File: DocumentIndexIntersectingIterator.java    From rya with Apache License 2.0 4 votes vote down vote up
protected Text getTermCond(Key key) {
  return key.getColumnQualifier();
}
 
Example 19
Source File: AndingIterator.java    From rya with Apache License 2.0 4 votes vote down vote up
protected Text getDocID(final Key key) {
	return key.getColumnQualifier();
}
 
Example 20
Source File: BooleanTreeIterator.java    From rya with Apache License 2.0 4 votes vote down vote up
private void seekDocSource(Key key) throws IOException {
    Key docKey = new Key(key.getRow(), ColumnPrefixes.DOCS_CF_PREFIX, key.getColumnQualifier());
    docSource.seek(new Range(docKey, true, null, false), Collections.<ByteSequence> emptyList(), false);
}