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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations