Search in sources :

Example 1 with Schema

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

the class AccumuloKeyValueReducer method setup.

@Override
protected void setup(final Context context) {
    try {
        schema = Schema.fromJson(context.getConfiguration().get(AddElementsFromHdfsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise schema from JSON", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(context.getConfiguration().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 IllegalArgumentException("Failed to create accumulo element converter from class", 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 2 with Schema

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

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations.

@Test
public void shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations() throws Exception {
    final Schema schema = getSchemaWithVisibilities();
    final View view = new View.Builder().build();
    final Set<String> expectedResultsPublicNotPrivate = new HashSet<>();
    final Set<String> expectedResultsPrivate = new HashSet<>();
    for (final Element element : DATA_WITH_VISIBILITIES) {
        expectedResultsPrivate.add(element.toString());
        if (element.getProperty("visibility").equals("public")) {
            expectedResultsPublicNotPrivate.add(element.toString());
        }
    }
    final Set<String> privateAuth = new HashSet<>();
    privateAuth.add("public");
    privateAuth.add("private");
    final Set<String> publicNotPrivate = new HashSet<>();
    publicNotPrivate.add("public");
    final User userWithPrivate = new User("user1", privateAuth);
    final User userWithPublicNotPrivate = new User("user1", publicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPublicNotPrivate, "instance5", expectedResultsPublicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPrivate, "instance6", expectedResultsPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPublicNotPrivate, "instance7", expectedResultsPublicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPrivate, "instance8", expectedResultsPrivate);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Schema

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

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobWithView.

@Test
public void shouldReturnCorrectDataToMapReduceJobWithView() throws Exception {
    final Schema schema = getSchema();
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    final Set<String> expectedResults = new HashSet<>();
    for (final Element element : DATA) {
        if (element.getGroup().equals(TestGroups.EDGE)) {
            expectedResults.add(element.toString());
        }
    }
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, view, new User(), "instance3", expectedResults);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA, view, new User(), "instance4", expectedResults);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Schema

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

the class AddElementsFromHdfsIT method createGraph.

private Graph createGraph(final Class<? extends AccumuloKeyPackage> keyPackageClass) throws StoreException {
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    properties.setKeyPackageClass(keyPackageClass.getName());
    properties.setInstance("instance_" + keyPackageClass.getName());
    final AccumuloStore store = new MockAccumuloStore();
    store.initialise(schema, properties);
    store.updateConfiguration(createLocalConf(), new View(), new User());
    return new Graph.Builder().store(store).build();
}
Also used : User(uk.gov.gchq.gaffer.user.User) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 5 with Schema

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

the class BloomFilterIT method setup.

@Before
public void setup() {
    Schema schema = new Schema.Builder().type(TestTypes.PROP_INTEGER, Integer.class).vertexSerialiser(new JavaSerialiser()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(AccumuloPropertyNames.INT, TestTypes.PROP_INTEGER).build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(AccumuloPropertyNames.INT, TestTypes.PROP_INTEGER).build()).build();
    byteEntityRangeFactory = new ByteEntityRangeFactory(schema);
    byteEntityElementConverter = new ByteEntityAccumuloElementConverter(schema);
    Gaffer1RangeFactory = new ClassicRangeFactory(schema);
    gafferV1ElementConverter = new ClassicAccumuloElementConverter(schema);
}
Also used : ByteEntityRangeFactory(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityRangeFactory) ClassicRangeFactory(uk.gov.gchq.gaffer.accumulostore.key.core.impl.classic.ClassicRangeFactory) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ClassicAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.classic.ClassicAccumuloElementConverter) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) Before(org.junit.Before)

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