Search in sources :

Example 6 with Properties

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));
}
Also used : Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 7 with Properties

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));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 8 with Properties

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]);
}
Also used : PropertiesTuple(uk.gov.gchq.gaffer.data.element.PropertiesTuple) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 9 with Properties

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;
}
Also used : Properties(uk.gov.gchq.gaffer.data.element.Properties) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Example 10 with Properties

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();
        }
    }
}
Also used : SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) Properties(uk.gov.gchq.gaffer.data.element.Properties) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Aggregations

Properties (uk.gov.gchq.gaffer.data.element.Properties)31 Test (org.junit.Test)16 Value (org.apache.accumulo.core.data.Value)11 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)8 Key (org.apache.accumulo.core.data.Key)7 Edge (uk.gov.gchq.gaffer.data.element.Edge)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 Element (uk.gov.gchq.gaffer.data.element.Element)3 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)3 File (java.io.File)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 Random (java.util.Random)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2