Search in sources :

Example 21 with Value

use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.

the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptDeduplicatedEdges.

@Test
public void shouldOnlyAcceptDeduplicatedEdges() throws OperationException, AccumuloElementConversionException {
    // Given
    final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
    final Map<String, String> options = new HashMap<String, String>() {

        {
            put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
            put(AccumuloStoreConstants.DEDUPLICATE_UNDIRECTED_EDGES, "true");
        }
    };
    filter.validateOptions(options);
    // value should not be used
    final Value value = null;
    // When / Then
    for (final Element element : ELEMENTS) {
        final Pair<Key> keys = converter.getKeysFromElement(element);
        // First key is deduplicated, but only edges should be excepted
        assertEquals("Failed for element: " + element.toString(), element instanceof Edge, filter.accept(keys.getFirst(), value));
        if (null != keys.getSecond()) {
            // self elements are not added the other way round
            assertEquals("Failed for element: " + element.toString(), false, filter.accept(keys.getSecond(), value));
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteEntityRangeElementPropertyFilterIterator(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityRangeElementPropertyFilterIterator) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 22 with Value

use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty.

@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty() throws AccumuloElementConversionException {
    Properties properties = new Properties();
    properties.put(AccumuloPropertyNames.PROP_1, 5);
    properties.put(AccumuloPropertyNames.PROP_2, null);
    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(5, deSerialisedProperties.get(AccumuloPropertyNames.PROP_1));
    assertNull(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 23 with Value

use of org.apache.accumulo.core.data.Value 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 24 with Value

use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.

the class AccumuloStore method insertGraphElements.

protected void insertGraphElements(final Iterable<Element> elements) throws StoreException {
    // Create BatchWriter
    final BatchWriter writer = TableUtils.createBatchWriter(this);
    // too high a latency, etc.
    if (elements != null) {
        for (final Element element : elements) {
            final Pair<Key> keys;
            try {
                keys = keyPackage.getKeyConverter().getKeysFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error("Failed to create an accumulo key from element of type " + element.getGroup() + " when trying to insert elements");
                continue;
            }
            final Value value;
            try {
                value = keyPackage.getKeyConverter().getValueFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error("Failed to create an accumulo value from element of type " + element.getGroup() + " when trying to insert elements");
                continue;
            }
            final Mutation m = new Mutation(keys.getFirst().getRow());
            m.put(keys.getFirst().getColumnFamily(), keys.getFirst().getColumnQualifier(), new ColumnVisibility(keys.getFirst().getColumnVisibility()), keys.getFirst().getTimestamp(), value);
            try {
                writer.addMutation(m);
            } catch (final MutationsRejectedException e) {
                LOGGER.error("Failed to create an accumulo key mutation");
                continue;
            }
            // If the GraphElement is an Edge then there will be 2 keys.
            if (keys.getSecond() != null) {
                final Mutation m2 = new Mutation(keys.getSecond().getRow());
                m2.put(keys.getSecond().getColumnFamily(), keys.getSecond().getColumnQualifier(), new ColumnVisibility(keys.getSecond().getColumnVisibility()), keys.getSecond().getTimestamp(), value);
                try {
                    writer.addMutation(m2);
                } catch (final MutationsRejectedException e) {
                    LOGGER.error("Failed to create an accumulo key mutation");
                }
            }
        }
    } else {
        throw new GafferRuntimeException("Could not find any elements to add to graph.", Status.BAD_REQUEST);
    }
    try {
        writer.close();
    } catch (final MutationsRejectedException e) {
        LOGGER.warn("Accumulo batch writer failed to close", e);
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)

Example 25 with Value

use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.

the class ElementConverterFunction method call.

@Override
public Iterator<Tuple2<Key, Value>> call(final Element e) throws Exception {
    final List<Tuple2<Key, Value>> tuples = new ArrayList<>(2);
    final Pair<Key> keys = converterBroadcast.value().getKeysFromElement(e);
    final Value value = converterBroadcast.value().getValueFromElement(e);
    tuples.add(new Tuple2<>(keys.getFirst(), value));
    final Key second = keys.getSecond();
    if (second != null) {
        tuples.add(new Tuple2<>(second, value));
    }
    return tuples.listIterator();
}
Also used : Tuple2(scala.Tuple2) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Aggregations

Value (org.apache.accumulo.core.data.Value)83 Key (org.apache.accumulo.core.data.Key)68 Test (org.junit.Test)38 Edge (uk.gov.gchq.gaffer.data.element.Edge)30 HashMap (java.util.HashMap)24 Text (org.apache.hadoop.io.Text)24 Element (uk.gov.gchq.gaffer.data.element.Element)23 Mutation (org.apache.accumulo.core.data.Mutation)21 Authorizations (org.apache.accumulo.core.security.Authorizations)20 Scanner (org.apache.accumulo.core.client.Scanner)19 Entry (java.util.Map.Entry)15 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)13 BatchWriter (org.apache.accumulo.core.client.BatchWriter)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)11 Connector (org.apache.accumulo.core.client.Connector)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)11 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)11 Range (org.apache.accumulo.core.data.Range)9 Properties (uk.gov.gchq.gaffer.data.element.Properties)9