Search in sources :

Example 31 with EventBase

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

the class ShardQueryCountTableTransformer method transform.

@Override
public EventBase transform(Entry<Long, ColumnVisibility> untypedEntry) {
    Long count = untypedEntry.getKey();
    ColumnVisibility vis = untypedEntry.getValue();
    Map<String, String> markings;
    try {
        markings = markingFunctions.translateFromColumnVisibilityForAuths(vis, auths);
    } catch (Exception e1) {
        throw new IllegalArgumentException("Unable to translate markings", e1);
    }
    EventBase e = this.responseObjectFactory.getEvent();
    e.setMarkings(markings);
    FieldBase field = this.makeField(COUNT_CELL, markings, vis, System.currentTimeMillis(), count);
    e.setMarkings(markings);
    List<FieldBase> fields = new ArrayList<>();
    fields.add(field);
    e.setFields(fields);
    Metadata metadata = new Metadata();
    metadata.setDataType(Constants.EMPTY_STRING);
    // There is only one item returned for the entire query logic.
    metadata.setInternalId(field.getName());
    metadata.setRow(Constants.EMPTY_STRING);
    e.setMetadata(metadata);
    return e;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) FieldBase(datawave.webservice.query.result.event.FieldBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) QueryException(datawave.webservice.query.exception.QueryException) Exception(datawave.marking.MarkingFunctions.Exception)

Example 32 with EventBase

use of datawave.webservice.query.result.event.EventBase 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)

Example 33 with EventBase

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

the class EventQueryTransformerSupport method readFromCache.

@Override
public List<Object> readFromCache(List<CacheableQueryRow> cacheableQueryRowList) {
    List<Object> eventList = new ArrayList<>();
    for (CacheableQueryRow cqr : cacheableQueryRowList) {
        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 (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)

Example 34 with EventBase

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

the class EventQueryTransformerSupport method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase<?, ?> event = (EventBase<?, ?>) o;
    CacheableQueryRow cqo = this.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());
    }
    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) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow)

Example 35 with EventBase

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

the class AbstractFunctionalQuery method runCountTest.

/**
 * Executes test cases that use {@link CountingShardQueryLogic}.
 *
 * @param query
 *            query for evaluation
 * @throws Exception
 *             error condition during execution of query
 */
protected void runCountTest(String query) throws Exception {
    Date[] startEndDate = this.dataManager.getShardStartEndDate();
    if (log.isDebugEnabled()) {
        log.debug("  count query[" + query + "]  start(" + YMD_DateFormat.format(startEndDate[0]) + ")  end(" + YMD_DateFormat.format(startEndDate[1]) + ")");
    }
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startEndDate[0]);
    q.setEndDate(startEndDate[1]);
    q.setQuery(query);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(auths.toString());
    RunningQuery runner = new RunningQuery(connector, AccumuloConnectionFactory.Priority.NORMAL, this.countLogic, q, "", principal, new QueryMetricFactoryImpl());
    TransformIterator it = runner.getTransformIterator();
    ShardQueryCountTableTransformer ctt = (ShardQueryCountTableTransformer) it.getTransformer();
    EventQueryResponseBase resp = (EventQueryResponseBase) ctt.createResponse(runner.next());
    Collection<String> expect = getExpectedKeyResponse(query);
    List<EventBase> events = resp.getEvents();
    Assert.assertEquals(1, events.size());
    EventBase<?, ?> event = events.get(0);
    List<?> fields = event.getFields();
    Assert.assertEquals(1, fields.size());
    FieldBase<?> count = (FieldBase) fields.get(0);
    String val = count.getValueString();
    if (log.isDebugEnabled()) {
        log.debug("expected count(" + expect.size() + ") actual count(" + val + ")");
    }
    Assert.assertEquals("" + expect.size(), val);
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ShardQueryCountTableTransformer(datawave.query.transformer.ShardQueryCountTableTransformer) Date(java.util.Date) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase) QueryImpl(datawave.webservice.query.QueryImpl) RunningQuery(datawave.webservice.query.runner.RunningQuery) FieldBase(datawave.webservice.query.result.event.FieldBase) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl)

Aggregations

EventBase (datawave.webservice.query.result.event.EventBase)45 ArrayList (java.util.ArrayList)30 FieldBase (datawave.webservice.query.result.event.FieldBase)24 Metadata (datawave.webservice.query.result.event.Metadata)18 EventQueryResponseBase (datawave.webservice.result.EventQueryResponseBase)12 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)10 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)7 DefaultEventQueryResponse (datawave.webservice.result.DefaultEventQueryResponse)5 Map (java.util.Map)5 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)5 TransformIterator (org.apache.commons.collections4.iterators.TransformIterator)5 Exception (datawave.marking.MarkingFunctions.Exception)4 QueryImpl (datawave.webservice.query.QueryImpl)4 QueryException (datawave.webservice.query.exception.QueryException)4 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)4 HashMap (java.util.HashMap)4 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)3 DatawaveTransformIterator (datawave.webservice.query.iterator.DatawaveTransformIterator)3 DefaultField (datawave.webservice.query.result.event.DefaultField)3