Search in sources :

Example 6 with DocumentData

use of datawave.query.iterator.aggregation.DocumentData in project datawave by NationalSecurityAgency.

the class DocumentDataIterator method next.

@Override
public DocumentData next() {
    DocumentData returnDocumentData = documentData.getKey();
    findNextDocument();
    return returnDocumentData;
}
Also used : KeyToDocumentData(datawave.query.function.KeyToDocumentData) DocumentData(datawave.query.iterator.aggregation.DocumentData)

Example 7 with DocumentData

use of datawave.query.iterator.aggregation.DocumentData in project datawave by NationalSecurityAgency.

the class IndexOnlyKeyToDocumentData method apply.

@Override
public Entry<DocumentData, Document> apply(final Entry<Key, Document> from) {
    try {
        // Validate the starting entry
        if (null == from) {
            throw new IllegalArgumentException("Starting key cannot be null");
        }
        // get the document key
        Key docKey = getDocKey(from.getKey());
        // Ensure that we have a non-empty colqual
        final Key stopKey = new Key(from.getKey().getRow().toString(), from.getKey().getColumnFamily().toString(), from.getKey().getColumnQualifier().toString() + '\u0000' + '\uffff');
        // Create the primary range
        final Range keyRange = new Range(from.getKey(), true, stopKey, true);
        try {
            // Trigger the initial seek
            this.source.seek(keyRange, COLUMN_FAMILIES, false);
            // Assign the start key
            this.iteratorStartKey = from.getKey();
            // Assign the conversion attributes
            this.iteratorConversionAttributes = this.newKeyConversionAttributes();
        } catch (IOException e) {
            QueryException qe = new QueryException(DatawaveErrorCode.PRIMARY_RANGE_CREATE_ERROR, e);
            throw new DatawaveFatalQueryException(qe);
        }
        // Create a result key
        final Key resultKey = this.newResultKey(from);
        // Set the default iterator document key using the result key
        this.iteratorDocumentKey = resultKey;
        // Iterate through the range of tf entries, converting relevant ones into standard field entries
        final List<Entry<Key, Value>> attrs;
        if (this.seekOnApply) {
            attrs = this.newFieldEntriesFromTfEntries(from.getKey());
        } else // Otherwise, expect that seeks will be performed incrementally via the Iterator
        // hasNext() and next() implementations.
        {
            attrs = Collections.emptyList();
        }
        // Try to construct a new document key based on the first converted tf record
        if (!attrs.isEmpty()) {
            final Entry<Key, Value> firstEntry = attrs.get(0);
            final Key fieldKey = firstEntry.getKey();
            long timestamp = resultKey.getTimestamp();
            this.iteratorDocumentKey = this.newDocumentKey(fieldKey, timestamp);
        } else {
            this.iteratorDocument = from.getValue();
        }
        // Set the parent document
        this.iteratorDocument = from.getValue();
        // Create an entry for the initialized Document
        final DocumentData documentData = new DocumentData(this.iteratorDocumentKey, Collections.singleton(docKey), attrs, true);
        return Maps.immutableEntry(documentData, this.iteratorDocument);
    } catch (DatawaveFatalQueryException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.APPLY_FUNCTION_ERROR, e);
        throw new DatawaveFatalQueryException(qe);
    }
}
Also used : IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) NoSuchElementException(java.util.NoSuchElementException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) DocumentData(datawave.query.iterator.aggregation.DocumentData) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) Entry(java.util.Map.Entry) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

DocumentData (datawave.query.iterator.aggregation.DocumentData)7 Key (org.apache.accumulo.core.data.Key)6 Entry (java.util.Map.Entry)5 Document (datawave.query.attributes.Document)4 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)3 KeyToDocumentData (datawave.query.function.KeyToDocumentData)3 QueryException (datawave.webservice.query.exception.QueryException)3 IOException (java.io.IOException)3 PartialKey (org.apache.accumulo.core.data.PartialKey)3 Value (org.apache.accumulo.core.data.Value)3 Aggregation (datawave.query.function.Aggregation)2 NoSuchElementException (java.util.NoSuchElementException)2 Nullable (javax.annotation.Nullable)2 Range (org.apache.accumulo.core.data.Range)2 Function (com.google.common.base.Function)1 AttributeKeepFilter (datawave.query.attributes.AttributeKeepFilter)1 DataTypeAsField (datawave.query.function.DataTypeAsField)1 DocumentCountCardinality (datawave.query.function.DocumentCountCardinality)1 DocumentMetadata (datawave.query.function.DocumentMetadata)1 DocumentPermutation (datawave.query.function.DocumentPermutation)1