Search in sources :

Example 6 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class FieldIndexCountQueryTransformer method readFromCache.

@Override
public List<Object> readFromCache(List<CacheableQueryRow> cacheableQueryRowList) {
    List<Object> eventList = new ArrayList<>();
    for (CacheableQueryRow cqr : cacheableQueryRowList) {
        if (this.variableFieldList == null) {
            this.variableFieldList = cqr.getVariableColumnNames();
        }
        Map<String, String> markings = cqr.getMarkings();
        String dataType = cqr.getDataType();
        String internalId = cqr.getEventId();
        String row = cqr.getRow();
        EventBase event = this.responseObjectFactory.getEvent();
        event.setMarkings(markings);
        Metadata metadata = new Metadata();
        metadata.setDataType(dataType);
        metadata.setInternalId(internalId);
        metadata.setRow(row);
        metadata.setTable(logic.getTableName());
        event.setMetadata(metadata);
        List<FieldBase> fieldList = new ArrayList<>();
        Map<String, String> columnValueMap = cqr.getColumnValues();
        for (Map.Entry<String, String> entry : columnValueMap.entrySet()) {
            String columnName = entry.getKey();
            String columnValue = entry.getValue();
            Map<String, String> columnMarkings = cqr.getColumnMarkings(columnName);
            String columnVisibility = cqr.getColumnVisibility(columnName);
            Long columnTimestamp = cqr.getColumnTimestamp(columnName);
            FieldBase field = this.makeField(columnName, columnMarkings, columnVisibility, columnTimestamp, columnValue);
            fieldList.add(field);
        }
        event.setFields(fieldList);
        eventList.add(event);
    }
    return eventList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) FieldBase(datawave.webservice.query.result.event.FieldBase) Map(java.util.Map)

Example 7 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class FieldIndexCountQueryTransformer method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase event = (EventBase) o;
    CacheableQueryRow cqo = responseObjectFactory.getCacheableQueryRow();
    Metadata metadata = event.getMetadata();
    cqo.setColFam(metadata.getDataType() + ":" + cqo.getEventId());
    cqo.setDataType(metadata.getDataType());
    cqo.setEventId(metadata.getInternalId());
    cqo.setRow(metadata.getRow());
    List<? extends FieldBase> fields = event.getFields();
    for (FieldBase f : fields) {
        cqo.addColumn(f.getName(), f.getTypedValue(), f.getMarkings(), f.getColumnVisibility(), f.getTimestamp());
    }
    // set the size in bytes using the initial event size as an approximation
    cqo.setSizeInBytes(event.getSizeInBytes());
    cqoList.add(cqo);
    return cqoList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) FieldBase(datawave.webservice.query.result.event.FieldBase) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow)

Example 8 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class DiscoveryTransformer method transform.

@Override
public EventBase transform(DiscoveredThing thing) {
    Preconditions.checkNotNull(thing, "Received a null object to transform!");
    EventBase event = this.responseObjectFactory.getEvent();
    Map<String, String> markings;
    try {
        markings = this.markingFunctions.translateFromColumnVisibility(new ColumnVisibility(thing.getColumnVisibility()));
    } catch (Exception e) {
        throw new RuntimeException("could not parse to markings: " + thing.getColumnVisibility());
    }
    event.setMarkings(markings);
    List<FieldBase> fields = new ArrayList<>();
    fields.add(this.makeField("VALUE", markings, "", 0L, thing.getTerm()));
    /**
     * Added query model to alias FIELD
     */
    fields.add(this.makeField("FIELD", markings, "", 0L, myQueryModel.aliasFieldNameReverseModel(thing.getField())));
    fields.add(this.makeField("DATE", markings, "", 0L, thing.getDate()));
    fields.add(this.makeField("DATA TYPE", markings, "", 0L, thing.getType()));
    // If requested return counts separated by colvis, all counts by colvis could be > total record count
    if (thing.getCountsByColumnVisibility() != null && !thing.getCountsByColumnVisibility().isEmpty()) {
        for (Map.Entry<Writable, Writable> entry : thing.getCountsByColumnVisibility().entrySet()) {
            try {
                Map<String, String> eMarkings = this.markingFunctions.translateFromColumnVisibility(new ColumnVisibility(entry.getKey().toString()));
                fields.add(this.makeField("RECORD COUNT", new HashMap<>(), entry.getKey().toString(), 0L, entry.getValue().toString()));
            } catch (Exception e) {
                throw new RuntimeException("could not parse to markings: " + thing.getColumnVisibility());
            }
        }
    } else {
        fields.add(this.makeField("RECORD COUNT", markings, "", 0L, Long.toString(thing.getCount())));
    }
    event.setFields(fields);
    Metadata metadata = new Metadata();
    // there is no UUID for a single index pointer
    metadata.setInternalId("");
    // duplicate
    metadata.setDataType(thing.getType());
    // duplicate
    metadata.setRow(thing.getTerm());
    metadata.setTable(logic.getTableName());
    event.setMetadata(metadata);
    return event;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) Writable(org.apache.hadoop.io.Writable) QueryException(datawave.webservice.query.exception.QueryException) Exception(datawave.marking.MarkingFunctions.Exception) FieldBase(datawave.webservice.query.result.event.FieldBase) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class DiscoveryTransformer method readFromCache.

@Override
public List<Object> readFromCache(List<CacheableQueryRow> cacheableQueryRowList) {
    List<Object> eventList = new ArrayList<>();
    for (CacheableQueryRow cqr : cacheableQueryRowList) {
        if (this.variableFieldList == null) {
            this.variableFieldList = cqr.getVariableColumnNames();
        }
        Map<String, String> markings = cqr.getMarkings();
        String dataType = cqr.getDataType();
        String internalId = cqr.getEventId();
        String row = cqr.getRow();
        EventBase event = this.responseObjectFactory.getEvent();
        event.setMarkings(markings);
        Metadata metadata = new Metadata();
        metadata.setDataType(dataType);
        metadata.setInternalId(internalId);
        metadata.setRow(row);
        metadata.setTable(logic.getTableName());
        event.setMetadata(metadata);
        List<FieldBase> fieldList = new ArrayList<>();
        Map<String, String> columnValueMap = cqr.getColumnValues();
        for (Map.Entry<String, String> entry : columnValueMap.entrySet()) {
            String columnName = entry.getKey();
            String columnValue = entry.getValue();
            String columnVisibility = cqr.getColumnVisibility(columnName);
            Long columnTimestamp = cqr.getColumnTimestamp(columnName);
            Map<String, String> columnMarkings = cqr.getColumnMarkings(columnName);
            FieldBase field = this.responseObjectFactory.getField();
            field.setName(columnName);
            field.setMarkings(columnMarkings);
            field.setColumnVisibility(columnVisibility);
            field.setTimestamp(columnTimestamp);
            field.setValue(columnValue);
            fieldList.add(field);
        }
        event.setFields(fieldList);
        eventList.add(event);
    }
    return eventList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) FieldBase(datawave.webservice.query.result.event.FieldBase) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class DiscoveryTransformer method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase event = (EventBase) o;
    CacheableQueryRow cqo = new CacheableQueryRowImpl();
    Metadata metadata = event.getMetadata();
    cqo.setColFam(metadata.getDataType() + ":" + cqo.getEventId());
    cqo.setDataType(metadata.getDataType());
    cqo.setEventId(metadata.getInternalId());
    cqo.setRow(metadata.getRow());
    List<FieldBase> fields = event.getFields();
    for (FieldBase f : fields) {
        cqo.addColumn(f.getName(), f.getTypedValue(), f.getMarkings(), f.getColumnVisibility(), f.getTimestamp());
    }
    cqoList.add(cqo);
    return cqoList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) FieldBase(datawave.webservice.query.result.event.FieldBase) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) CacheableQueryRowImpl(datawave.webservice.query.cachedresults.CacheableQueryRowImpl)

Aggregations

Metadata (datawave.webservice.query.result.event.Metadata)20 EventBase (datawave.webservice.query.result.event.EventBase)18 FieldBase (datawave.webservice.query.result.event.FieldBase)15 ArrayList (java.util.ArrayList)15 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)10 Exception (datawave.marking.MarkingFunctions.Exception)5 Map (java.util.Map)5 QueryException (datawave.webservice.query.exception.QueryException)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)4 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)2 DefaultField (datawave.webservice.query.result.event.DefaultField)2 HashMap (java.util.HashMap)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 Input (com.esotericsoftware.kryo.io.Input)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Uid (datawave.ingest.protobuf.Uid)1 EventFields (datawave.query.parser.EventFields)1 FieldValue (datawave.query.parser.EventFields.FieldValue)1