Search in sources :

Example 21 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingEndProperty.

@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingEndProperty() throws AccumuloElementConversionException {
    Properties properties = new Properties();
    properties.put(AccumuloPropertyNames.PROP_1, 60);
    properties.put(AccumuloPropertyNames.PROP_2, 166);
    properties.put(AccumuloPropertyNames.PROP_3, 299);
    properties.put(AccumuloPropertyNames.PROP_4, 10);
    final Value value = converter.getValueFromProperties(TestGroups.EDGE, properties);
    final Properties deSerialisedProperties = converter.getPropertiesFromValue(TestGroups.EDGE, value);
    assertEquals(60, deSerialisedProperties.get(AccumuloPropertyNames.PROP_1));
    assertEquals(166, deSerialisedProperties.get(AccumuloPropertyNames.PROP_2));
    assertEquals(299, deSerialisedProperties.get(AccumuloPropertyNames.PROP_3));
    assertEquals(10, deSerialisedProperties.get(AccumuloPropertyNames.PROP_4));
}
Also used : Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 22 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldBuildTimestampFromProperty.

@Test
public void shouldBuildTimestampFromProperty() 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 propertyTimestamp = 10L;
    final Properties properties = new Properties() {

        {
            put(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
            put(AccumuloPropertyNames.PROP_1, 2);
            put(AccumuloPropertyNames.TIMESTAMP, propertyTimestamp);
        }
    };
    // When
    final long timestamp = converter.buildTimestamp(properties);
    // Then
    assertEquals(propertyTimestamp, 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 23 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValue.

@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValue() throws AccumuloElementConversionException {
    Properties properties = new Properties();
    properties.put(AccumuloPropertyNames.PROP_1, 60);
    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(60, deSerialisedProperties.get(AccumuloPropertyNames.PROP_1));
    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 24 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSkipNullPropertyValuesWhenCreatingAccumuloKey.

@Test
public void shouldSkipNullPropertyValuesWhenCreatingAccumuloKey() throws SchemaException, AccumuloElementConversionException, IOException {
    // Given
    final Edge edge = new Edge(TestGroups.EDGE);
    edge.setSource("1");
    edge.setDestination("2");
    edge.setDirected(true);
    edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, null);
    // When
    final Pair<Key> keys = converter.getKeysFromElement(edge);
    Properties properties = converter.getPropertiesFromColumnQualifier(TestGroups.EDGE, keys.getFirst().getColumnQualifierData().getBackingArray());
    // Then
    assertEquals(null, properties.get(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Also used : Properties(uk.gov.gchq.gaffer.data.element.Properties) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 25 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty.

@Test
public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() throws AccumuloElementConversionException {
    // Given

    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "map").property(TestPropertyNames.PROP_2, "map").build()).type("string", String.class).type("map", new TypeDefinition.Builder().clazz(FreqMap.class).aggregateFunction(new FreqMapAggregator()).serialiser(new FreqMapSerialiser()).build()).build();
    converter = createConverter(schema);
    final Entity entity = new Entity.Builder().vertex("vertex1").property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
    // When 1

    final Value value = converter.getValueFromProperties(TestGroups.ENTITY, entity.getProperties());
    // Then 1
    assertTrue(value.getSize() > 0);
    // When 2
    final Properties properties = converter.getPropertiesFromValue(TestGroups.ENTITY, value);
    // Then 2
    assertEquals(entity.getProperties(), properties);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FreqMapAggregator(uk.gov.gchq.gaffer.function.aggregate.FreqMapAggregator) Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) FreqMapSerialiser(uk.gov.gchq.gaffer.serialisation.FreqMapSerialiser) Test(org.junit.Test)

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