Search in sources :

Example 66 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class AbstractElementFilter method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!super.validateOptions(options)) {
        return false;
    }
    if (!options.containsKey(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    }
    if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
    }
    validator = getElementValidator(options);
    final Schema schema;
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema from JSON", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new ElementFilterException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    return true;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementFilterException(uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException)

Example 67 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class RowIDAggregator method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
    }
    if (!options.containsKey(AccumuloStoreConstants.COLUMN_FAMILY)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.COLUMN_FAMILY);
    }
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    group = options.get(AccumuloStoreConstants.COLUMN_FAMILY);
    aggregator = schema.getElement(group).getAggregator();
    return true;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 68 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class SampleDataForSplitPointsMapper method setup.

protected void setup(final Context context) {
    super.setup(context);
    proportionToSample = context.getConfiguration().getFloat(SampleDataForSplitPointsJobFactory.PROPORTION_TO_SAMPLE, 0.001f);
    final Schema schema;
    try {
        schema = Schema.fromJson(context.getConfiguration().get(SampleDataForSplitPointsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise Store Schema from JSON", e);
    }
    final String converterClass = context.getConfiguration().get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    try {
        final Class<?> elementConverterClass = Class.forName(converterClass);
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new IllegalArgumentException("Element converter could not be created: " + converterClass, e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 69 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema 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 70 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema 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

Schema (uk.gov.gchq.gaffer.store.schema.Schema)86 Test (org.junit.Test)63 SQLContext (org.apache.spark.sql.SQLContext)14 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 User (uk.gov.gchq.gaffer.user.User)13 HashSet (java.util.HashSet)12 Filter (org.apache.spark.sql.sources.Filter)12 EqualTo (org.apache.spark.sql.sources.EqualTo)9 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)9 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 Store (uk.gov.gchq.gaffer.store.Store)9 Before (org.junit.Before)8 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)8 Graph (uk.gov.gchq.gaffer.graph.Graph)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5