Search in sources :

Example 1 with DefaultEvent

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

the class TermFrequencyQueryTransformer method transform.

@Override
public DefaultEvent transform(Entry<Key, Value> entry) throws EmptyObjectException {
    if (entry.getKey() == null && entry.getValue() == null) {
        return null;
    }
    if (entry.getKey() == null || entry.getValue() == null) {
        throw new IllegalArgumentException("Null keyy or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
    }
    TermFrequencyKeyValue tfkv;
    try {
        tfkv = TermFrequencyKeyValueFactory.parse(entry.getKey(), entry.getValue(), auths, markingFunctions);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to parse visibility", e);
    }
    DefaultEvent e = new DefaultEvent();
    e.setMarkings(tfkv.getMarkings());
    Metadata m = new Metadata();
    m.setRow(tfkv.getShardId());
    m.setDataType(tfkv.getShardId());
    m.setInternalId(tfkv.getUid());
    e.setMetadata(m);
    List<DefaultField> fields = ImmutableList.of(createField(tfkv, entry, "FIELD_NAME", tfkv.getFieldName()), createField(tfkv, entry, "FIELD_VALUE", tfkv.getFieldValue()), createField(tfkv, entry, "OFFSET_COUNT", String.valueOf(tfkv.getCount())), createField(tfkv, entry, "OFFSETS", tfkv.getOffsets().toString()));
    e.setFields(fields);
    return e;
}
Also used : TermFrequencyKeyValue(datawave.query.table.parser.TermFrequencyKeyValueFactory.TermFrequencyKeyValue) DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) Metadata(datawave.webservice.query.result.event.Metadata) DefaultField(datawave.webservice.query.result.event.DefaultField) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException)

Example 2 with DefaultEvent

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

the class MutableMetadataHandler method findMatchingEventUuid.

/**
 * Finds the event by creating a query by UUID from the keys and values in the runtime parameters.
 *
 * @param uuid
 * @param uuidType
 * @param userAuths
 * @return Event
 * @throws Exception
 */
protected EventBase<?, ?> findMatchingEventUuid(String uuid, String uuidType, Set<Authorizations> userAuths, ModificationOperation operation) throws Exception {
    String field = operation.getFieldName();
    String columnVisibility = operation.getColumnVisibility();
    // query in format uuidType:uuid
    StringBuilder query = new StringBuilder();
    query.append(uuidType.toUpperCase()).append(":\"").append(uuid).append("\"");
    // make the query only return the field to be modified and the UUIDType (avoids NoResultsException on an insert where the field has no values)
    StringBuilder queryOptions = new StringBuilder();
    queryOptions.append("query.syntax:LUCENE-UUID;raw.data.only:true");
    if (field != null) {
        queryOptions.append(";return.fields:").append(field.toUpperCase()).append(",").append(uuidType.toUpperCase());
    }
    String logicName = "LuceneUUIDEventQuery";
    DefaultEvent e = null;
    QueryExecutorBean queryService = this.getQueryService();
    String id = null;
    HashSet<String> auths = new HashSet<>();
    for (Authorizations a : userAuths) auths.addAll(Arrays.asList(a.toString().split(",")));
    Date expiration = new Date();
    expiration = new Date(expiration.getTime() + (1000 * 60 * 60 * 24));
    try {
        MultivaluedMap<String, String> paramsMap = new MultivaluedMapImpl<>();
        paramsMap.putAll(QueryParametersImpl.paramsToMap(logicName, query.toString(), "Query to find matching records for metadata modification", columnVisibility, new Date(0), new Date(), StringUtils.join(auths, ','), expiration, 2, -1, null, QueryPersistence.TRANSIENT, queryOptions.toString(), false));
        GenericResponse<String> createResponse = queryService.createQuery(logicName, paramsMap);
        id = createResponse.getResult();
        BaseQueryResponse response = queryService.next(id);
        if (response instanceof DefaultEventQueryResponse) {
            DefaultEventQueryResponse eResponse = (DefaultEventQueryResponse) response;
            if (eResponse.getEvents().size() > 1) {
                throw new IllegalStateException("More than one event matched " + uuid + " (" + eResponse.getEvents().size() + " matched)");
            }
            if (eResponse.getEvents().isEmpty()) {
                throw new IllegalStateException("No event matched " + uuid);
            }
            e = (DefaultEvent) eResponse.getEvents().get(0);
        }
    } catch (Exception ex) {
        log.error(ex);
    } finally {
        if (id != null) {
            queryService.close(id);
        }
    }
    return e;
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) Authorizations(org.apache.accumulo.core.security.Authorizations) DefaultEventQueryResponse(datawave.webservice.result.DefaultEventQueryResponse) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Date(java.util.Date) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ExecutionException(java.util.concurrent.ExecutionException) QueryExecutorBean(datawave.webservice.query.runner.QueryExecutorBean) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) HashSet(java.util.HashSet)

Example 3 with DefaultEvent

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

the class MixedGeoAndGeoWaveTest method intersectsLargeCircleEvaluationOnlyTest.

@Test
public void intersectsLargeCircleEvaluationOnlyTest() throws Exception {
    String query = "geowave:intersects(" + GEO_FIELD + ", '" + createCircle(0, 0, 90).toText() + "') && ((ASTEvaluationOnly = true) && geowave:intersects(" + GEO_FIELD + ", '" + createCircle(0, 0, 90).toText() + "'))";
    List<DefaultEvent> events = getQueryResults(query);
    Assert.assertEquals(12, events.size());
    List<String> geoList = new ArrayList<>();
    geoList.addAll(Arrays.asList(pointData));
    geoList.addAll(Arrays.asList(geoData));
    for (DefaultEvent event : events) {
        String geo = null;
        for (DefaultField field : event.getFields()) {
            if (field.getName().equals(GEO_FIELD) || field.getName().equals(POINT_FIELD))
                geo = field.getValueString();
        }
        // ensure that this is one of the ingested events
        Assert.assertTrue(geoList.remove(geo));
    }
    Assert.assertEquals(0, geoList.size());
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) ArrayList(java.util.ArrayList) DefaultField(datawave.webservice.query.result.event.DefaultField) Test(org.junit.Test)

Example 4 with DefaultEvent

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

the class MixedGeoAndGeoWaveTest method intersectsSmallBoundingBoxTest.

@Test
public void intersectsSmallBoundingBoxTest() throws Exception {
    String query = "geowave:intersects(" + GEO_FIELD + ", 'POLYGON((0.5 2, 1.5 2, 1.5 10, 0.5 10, 0.5 2))')";
    List<DefaultEvent> events = getQueryResults(query);
    Assert.assertEquals(2, events.size());
    List<String> geoList = new ArrayList<>();
    geoList.addAll(Arrays.asList(GEO_6, POINT_4));
    for (DefaultEvent event : events) {
        String geo = null;
        for (DefaultField field : event.getFields()) {
            if (field.getName().equals(GEO_FIELD) || field.getName().equals(POINT_FIELD))
                geo = field.getValueString();
        }
        // ensure that this is one of the ingested events
        Assert.assertTrue(geoList.remove(geo));
    }
    Assert.assertEquals(0, geoList.size());
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) ArrayList(java.util.ArrayList) DefaultField(datawave.webservice.query.result.event.DefaultField) Test(org.junit.Test)

Example 5 with DefaultEvent

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

the class MixedGeoAndGeoWaveTest method withinLargeBoundingBoxTest.

@Test
public void withinLargeBoundingBoxTest() throws Exception {
    String query = "geo:within_bounding_box(" + GEO_FIELD + ", '-90_-180', '90_180')";
    List<DefaultEvent> events = getQueryResults(query);
    Assert.assertEquals(12, events.size());
    List<String> geoList = new ArrayList<>();
    geoList.addAll(Arrays.asList(pointData));
    geoList.addAll(Arrays.asList(geoData));
    for (DefaultEvent event : events) {
        String geo = null;
        for (DefaultField field : event.getFields()) {
            if (field.getName().equals(GEO_FIELD) || field.getName().equals(POINT_FIELD))
                geo = field.getValueString();
        }
        // ensure that this is one of the ingested events
        Assert.assertTrue(geoList.remove(geo));
    }
    Assert.assertEquals(0, geoList.size());
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) ArrayList(java.util.ArrayList) DefaultField(datawave.webservice.query.result.event.DefaultField) Test(org.junit.Test)

Aggregations

DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)38 ArrayList (java.util.ArrayList)34 DefaultField (datawave.webservice.query.result.event.DefaultField)29 Test (org.junit.Test)26 ShardQueryLogic (datawave.query.tables.ShardQueryLogic)5 Iterator (java.util.Iterator)5 QueryData (datawave.webservice.query.configuration.QueryData)4 EventBase (datawave.webservice.query.result.event.EventBase)3 Metadata (datawave.webservice.query.result.event.Metadata)2 DefaultEventQueryResponse (datawave.webservice.result.DefaultEventQueryResponse)2 Exception (datawave.marking.MarkingFunctions.Exception)1 ContentKeyValue (datawave.query.table.parser.ContentKeyValueFactory.ContentKeyValue)1 TermFrequencyKeyValue (datawave.query.table.parser.TermFrequencyKeyValueFactory.TermFrequencyKeyValue)1 EmptyObjectException (datawave.webservice.query.exception.EmptyObjectException)1 QueryExceptionType (datawave.webservice.query.exception.QueryExceptionType)1 QueryExecutorBean (datawave.webservice.query.runner.QueryExecutorBean)1 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1