Search in sources :

Example 1 with FieldValue

use of datawave.query.parser.EventFields.FieldValue in project datawave by NationalSecurityAgency.

the class EventFields method read.

@Override
public void read(Kryo kryo, Input input) {
    // Read in the number of map entries
    int entries = input.readInt(true);
    for (int i = 0; i < entries; i++) {
        // Read in the key
        String key = input.readString();
        // Read in the fields in the value
        int numBytes = input.readInt(true);
        ColumnVisibility vis = new ColumnVisibility(input.readBytes(numBytes));
        numBytes = input.readInt(true);
        byte[] value = input.readBytes(numBytes);
        FieldValue fv = new FieldValue(vis, value);
        boolean hasContext = input.readBoolean();
        if (hasContext) {
            fv.setContext(input.readString());
        }
        boolean hasIsHit = input.readBoolean();
        if (hasIsHit) {
            fv.setHit(input.readBoolean());
        }
        map.put(key, fv);
    }
}
Also used : ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) FieldValue(datawave.query.parser.EventFields.FieldValue)

Example 2 with FieldValue

use of datawave.query.parser.EventFields.FieldValue in project datawave by NationalSecurityAgency.

the class EventQueryTransformer method transform.

@Override
public EventBase transform(Entry<Key, Value> entry) {
    Key key = entry.getKey();
    Value val = entry.getValue();
    if (entry.getKey() == null && entry.getValue() == null)
        return null;
    if (null == entry.getKey() || null == entry.getValue()) {
        throw new IllegalArgumentException("Null key or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
    }
    EventBase event = this.responseObjectFactory.getEvent();
    Map<String, String> markings = null;
    try {
        markings = this.markingFunctions.translateFromColumnVisibilityForAuths(new ColumnVisibility(key.getColumnVisibility()), this.auths);
    } catch (Exception e) {
        log.error("could not translate " + key.getColumnVisibility() + " to markings, skipping entry");
        return null;
    }
    if (null == markings || markings.isEmpty()) {
        // can't process this one because we did not have valid security markings
        log.error("Transformer visibility interpreter was null, skipping entry");
        return null;
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(entry.getValue().get());
    Input i = new Input(bais);
    eventFields = kryo.readObject(i, EventFields.class);
    i.close();
    String row = entry.getKey().getRow().toString();
    String colf = entry.getKey().getColumnFamily().toString();
    String colq = entry.getKey().getColumnQualifier().toString();
    // evaluated by using the returnUidMapper (@see datawave.core.iterators.EvaluatingIterator: aggregateAltEvent)
    if (!colq.equals("")) {
        colf = colq;
    }
    int sepIndex = colf.indexOf(Constants.NULL_BYTE_STRING);
    String baseUid = colf.substring(sepIndex + 1);
    Set<FieldBase<?>> values = new HashSet<>();
    String origFieldName = null;
    String fieldName = null;
    // Hold unique Column Visibilities and merge them at the end
    // for the overall event ColumnVisibility.
    Set<ColumnVisibility> visibilitiesToMerge = new HashSet<>();
    for (Entry<String, Collection<FieldValue>> e : eventFields.asMap().entrySet()) {
        origFieldName = e.getKey();
        if (this.qm != null) {
            fieldName = this.qm.aliasFieldNameReverseModel(origFieldName);
        } else {
            fieldName = origFieldName;
        }
        for (FieldValue fv : e.getValue()) {
            visibilitiesToMerge.add(fv.getVisibility());
            try {
                Map<String, String> fieldMarkings = this.markingFunctions.translateFromColumnVisibility(fv.getVisibility());
                String value = new String(fv.getValue(), Charset.forName("UTF-8"));
                // if this is a content field name, then replace the value with the uid
                if (getContentFieldNames().contains(fieldName)) {
                    value = baseUid;
                }
                values.add(this.makeField(fieldName, fieldMarkings, new String(fv.getVisibility().getExpression()), entry.getKey().getTimestamp(), value));
            } catch (Exception e1) {
                throw new RuntimeException("could not make markings from: " + fv.getVisibility());
            }
        }
    }
    ColumnVisibility columnVisibility = null;
    try {
        columnVisibility = this.markingFunctions.combine(visibilitiesToMerge);
        event.setMarkings(this.markingFunctions.translateFromColumnVisibility(columnVisibility));
    } catch (Exception e1) {
        throw new RuntimeException("could not make markings from: " + columnVisibility);
    }
    event.setFields(new ArrayList<>(values));
    Metadata metadata = new Metadata();
    String[] colfParts = StringUtils.split(colf, '\0');
    if (colfParts.length >= 1) {
        metadata.setDataType(colfParts[0]);
    }
    if (colfParts.length >= 2) {
        metadata.setInternalId(colfParts[1]);
    }
    if (this.tableName != null) {
        metadata.setTable(this.tableName);
    }
    metadata.setRow(row);
    event.setMetadata(metadata);
    if (eventQueryDataDecoratorTransformer != null) {
        event = (EventBase<?, ?>) eventQueryDataDecoratorTransformer.transform(event);
    }
    // assign an estimate of the event size
    // in practice this is about 6 times the size of the kryo bytes
    event.setSizeInBytes(entry.getValue().getSize() * 6);
    return event;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) Metadata(datawave.webservice.query.result.event.Metadata) Exception(datawave.marking.MarkingFunctions.Exception) EventFields(datawave.query.parser.EventFields) Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) FieldValue(datawave.query.parser.EventFields.FieldValue) Value(org.apache.accumulo.core.data.Value) FieldBase(datawave.webservice.query.result.event.FieldBase) Collection(java.util.Collection) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) FieldValue(datawave.query.parser.EventFields.FieldValue) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Aggregations

FieldValue (datawave.query.parser.EventFields.FieldValue)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 Input (com.esotericsoftware.kryo.io.Input)1 Exception (datawave.marking.MarkingFunctions.Exception)1 EventFields (datawave.query.parser.EventFields)1 EventBase (datawave.webservice.query.result.event.EventBase)1 FieldBase (datawave.webservice.query.result.event.FieldBase)1 Metadata (datawave.webservice.query.result.event.Metadata)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1