use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingStartProperty.
@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingStartProperty() throws AccumuloElementConversionException {
Properties properties = new Properties();
properties.put(AccumuloPropertyNames.PROP_2, 166);
properties.put(AccumuloPropertyNames.PROP_3, 299);
properties.put(AccumuloPropertyNames.PROP_4, 10);
properties.put(AccumuloPropertyNames.COUNT, 8);
final Value value = converter.getValueFromProperties(TestGroups.EDGE, properties);
final Properties deSerialisedProperties = converter.getPropertiesFromValue(TestGroups.EDGE, value);
assertEquals(166, deSerialisedProperties.get(AccumuloPropertyNames.PROP_2));
assertEquals(299, deSerialisedProperties.get(AccumuloPropertyNames.PROP_3));
assertEquals(10, deSerialisedProperties.get(AccumuloPropertyNames.PROP_4));
assertEquals(8, deSerialisedProperties.get(AccumuloPropertyNames.COUNT));
}
use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldGetPropertiesFromTimestamp.
@Test
public void shouldGetPropertiesFromTimestamp() throws AccumuloElementConversionException {
// Given
// add extra timestamp property to schema
final Schema schema = new Schema.Builder().json(StreamUtil.schemas(getClass())).build();
converter = createConverter(new Schema.Builder(schema).type("timestamp", Long.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(AccumuloPropertyNames.TIMESTAMP, "timestamp").build()).timestampProperty(AccumuloPropertyNames.TIMESTAMP).build());
final long timestamp = System.currentTimeMillis();
final String group = TestGroups.EDGE;
// When
final Properties properties = converter.getPropertiesFromTimestamp(group, timestamp);
// Then
assertEquals(1, properties.size());
assertEquals(timestamp, properties.get(AccumuloPropertyNames.TIMESTAMP));
}
use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.
the class ElementAggregatorTest method shouldWrapPropertiesInPropertiesTupleAndCallSuper.
@Test
public void shouldWrapPropertiesInPropertiesTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
final List<String> references = Collections.singletonList(reference);
given(functionContext1.getSelection()).willReturn(references);
aggregator.addFunction(functionContext1);
final Properties properties = new Properties(reference, value);
final ArgumentCaptor<PropertiesTuple> propertiesTupleCaptor = ArgumentCaptor.forClass(PropertiesTuple.class);
given(functionContext1.select(propertiesTupleCaptor.capture())).willReturn(new String[] { value });
// When
aggregator.aggregate(properties);
// Then
verify(functionContext1, times(2)).getFunction();
assertSame(properties, propertiesTupleCaptor.getValue().getProperties());
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).aggregate(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.
the class CoreKeyGroupByAggregatorIterator method reduce.
@Override
public Properties reduce(final String group, final Key key, final Iterator<Properties> iter) {
if (!iter.hasNext()) {
return new Properties();
}
final Properties properties = iter.next();
if (!iter.hasNext()) {
return properties;
}
final ElementAggregator aggregator = schema.getElement(group).getAggregator();
aggregator.aggregate(properties);
while (iter.hasNext()) {
aggregator.aggregate(iter.next());
}
final Properties aggregatedProperties = new Properties();
aggregator.state(aggregatedProperties);
return aggregatedProperties;
}
use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.
the class CoreKeyGroupByCombiner method findTop.
/**
* Sets the topKey and topValue based on the top key of the source.
*/
private void findTop() {
// check if aggregation is needed
if (super.hasTop()) {
workKey.set(super.getTopKey());
if (workKey.isDeleted()) {
return;
}
final byte[] columnFamily = workKey.getColumnFamilyData().getBackingArray();
final String group;
try {
group = elementConverter.getGroupFromColumnFamily(columnFamily);
} catch (AccumuloElementConversionException e) {
throw new RuntimeException(e);
}
final Iterator<Properties> iter = new KeyValueIterator(getSource(), group, elementConverter, schema, view);
final Properties aggregatedProperties = reduce(group, workKey, iter);
// Remove any group by properties from the aggregated properties
// as they should be held constant.
final Set<String> groupBy = view.getElementGroupBy(group);
if (null == groupBy) {
final Set<String> schemaGroupBy = schema.getElement(group).getGroupBy();
if (null != schemaGroupBy) {
aggregatedProperties.remove(schemaGroupBy);
}
} else {
aggregatedProperties.remove(groupBy);
}
try {
final Properties properties = elementConverter.getPropertiesFromColumnQualifier(group, workKey.getColumnQualifierData().getBackingArray());
properties.putAll(elementConverter.getPropertiesFromColumnVisibility(group, workKey.getColumnVisibilityData().getBackingArray()));
properties.putAll(aggregatedProperties);
topValue = elementConverter.getValueFromProperties(group, properties);
topKey = new Key(workKey.getRowData().getBackingArray(), columnFamily, elementConverter.buildColumnQualifier(group, properties), elementConverter.buildColumnVisibility(group, properties), elementConverter.buildTimestamp(properties));
} catch (AccumuloElementConversionException e) {
throw new RuntimeException(e);
}
while (iter.hasNext()) {
iter.next();
}
}
}
Aggregations