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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations