Search in sources :

Example 41 with Element

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

the class GetDataFrameOfElementsHandlerTest method getElementsForUserDefinedConversion.

private static List<Element> getElementsForUserDefinedConversion() {
    final List<Element> elements = new ArrayList<>();
    final Entity entity = new Entity(ENTITY_GROUP);
    entity.setVertex("A");
    final FreqMap freqMap = new FreqMap();
    freqMap.put("W", 10L);
    freqMap.put("X", 100L);
    entity.putProperty("freqMap", freqMap);
    final HyperLogLogPlus hllpp = new HyperLogLogPlus(5, 5);
    hllpp.offer("AAA");
    entity.putProperty("hllpp", hllpp);
    entity.putProperty("myProperty", new MyProperty(10));
    elements.add(entity);
    final Edge edge = new Edge(EDGE_GROUP);
    edge.setSource("B");
    edge.setDestination("C");
    edge.setDirected(true);
    final FreqMap freqMap2 = new FreqMap();
    freqMap2.put("Y", 1000L);
    freqMap2.put("Z", 10000L);
    edge.putProperty("freqMap", freqMap2);
    final HyperLogLogPlus hllpp2 = new HyperLogLogPlus(5, 5);
    hllpp2.offer("AAA");
    hllpp2.offer("BBB");
    edge.putProperty("hllpp", hllpp2);
    edge.putProperty("myProperty", new MyProperty(50));
    elements.add(edge);
    return elements;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 42 with Element

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

the class GetDataFrameOfElementsHandlerTest method getElementsWithNonStandardProperties.

private static List<Element> getElementsWithNonStandardProperties() {
    final List<Element> elements = new ArrayList<>();
    final Entity entity = new Entity(ENTITY_GROUP);
    entity.setVertex("A");
    final FreqMap freqMap = new FreqMap();
    freqMap.put("W", 10L);
    freqMap.put("X", 100L);
    entity.putProperty("freqMap", freqMap);
    final HyperLogLogPlus hllpp = new HyperLogLogPlus(5, 5);
    hllpp.offer("AAA");
    entity.putProperty("hllpp", hllpp);
    elements.add(entity);
    final Edge edge = new Edge(EDGE_GROUP);
    edge.setSource("B");
    edge.setDestination("C");
    edge.setDirected(true);
    final FreqMap freqMap2 = new FreqMap();
    freqMap2.put("Y", 1000L);
    freqMap2.put("Z", 10000L);
    edge.putProperty("freqMap", freqMap2);
    final HyperLogLogPlus hllpp2 = new HyperLogLogPlus(5, 5);
    hllpp2.offer("AAA");
    hllpp2.offer("BBB");
    edge.putProperty("hllpp", hllpp2);
    elements.add(edge);
    return elements;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 43 with Element

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

the class GetDataFrameOfElementsHandlerTest method getElements.

static List<Element> getElements() {
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < NUM_ELEMENTS; i++) {
        final Entity entity = new Entity(ENTITY_GROUP);
        entity.setVertex("" + i);
        entity.putProperty("columnQualifier", 1);
        entity.putProperty("property1", i);
        entity.putProperty("property2", 3.0F);
        entity.putProperty("property3", 4.0D);
        entity.putProperty("property4", 5L);
        entity.putProperty("count", 6L);
        final Edge edge1 = new Edge(EDGE_GROUP);
        edge1.setSource("" + i);
        edge1.setDestination("B");
        edge1.setDirected(true);
        edge1.putProperty("columnQualifier", 1);
        edge1.putProperty("property1", 2);
        edge1.putProperty("property2", 3.0F);
        edge1.putProperty("property3", 4.0D);
        edge1.putProperty("property4", 5L);
        edge1.putProperty("count", 100L);
        final Edge edge2 = new Edge(EDGE_GROUP);
        edge2.setSource("" + i);
        edge2.setDestination("C");
        edge2.setDirected(true);
        edge2.putProperty("columnQualifier", 6);
        edge2.putProperty("property1", 7);
        edge2.putProperty("property2", 8.0F);
        edge2.putProperty("property3", 9.0D);
        edge2.putProperty("property4", 10L);
        edge2.putProperty("count", i * 200L);
        elements.add(edge1);
        elements.add(edge2);
        elements.add(entity);
    }
    return elements;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 44 with Element

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

the class GetJavaRDDOfAllElementsHandlerTest method checkGetAllElementsInJavaRDDWithVisibility.

@Test
public void checkGetAllElementsInJavaRDDWithVisibility() throws OperationException, IOException {
    final Graph graph1 = new Graph.Builder().addSchema(getClass().getResourceAsStream("/schema/dataSchemaWithVisibility.json")).addSchema(getClass().getResourceAsStream("/schema/dataTypes.json")).addSchema(getClass().getResourceAsStream("/schema/storeTypes.json")).storeProperties(getClass().getResourceAsStream("/store.properties")).build();
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < 1; i++) {
        final Entity entity = new Entity(TestGroups.ENTITY);
        entity.setVertex("" + i);
        entity.putProperty("visibility", "public");
        final Edge edge1 = new Edge(TestGroups.EDGE);
        edge1.setSource("" + i);
        edge1.setDestination("B");
        edge1.setDirected(false);
        edge1.putProperty(TestPropertyNames.COUNT, 2);
        edge1.putProperty("visibility", "private");
        final Edge edge2 = new Edge(TestGroups.EDGE);
        edge2.setSource("" + i);
        edge2.setDestination("C");
        edge2.setDirected(false);
        edge2.putProperty(TestPropertyNames.COUNT, 4);
        edge2.putProperty("visibility", "public");
        elements.add(edge1);
        elements.add(edge2);
        elements.add(entity);
    }
    final User user = new User("user", Collections.singleton("public"));
    graph1.execute(new AddElements(elements), user);
    final SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("testCheckGetCorrectElementsInJavaRDDForEntitySeed").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").set("spark.kryo.registrator", "uk.gov.gchq.gaffer.spark.serialisation.kryo.Registrator").set("spark.driver.allowMultipleContexts", "true");
    final JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
    // Create Hadoop configuration and serialise to a string
    final Configuration configuration = new Configuration();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    configuration.write(new DataOutputStream(baos));
    final String configurationString = new String(baos.toByteArray(), CommonConstants.UTF_8);
    // Create user with just public auth, and user with both private and public
    final Set<String> publicNotPrivate = new HashSet<>();
    publicNotPrivate.add("public");
    final User userWithPublicNotPrivate = new User("user1", publicNotPrivate);
    final Set<String> privateAuth = new HashSet<>();
    privateAuth.add("public");
    privateAuth.add("private");
    final User userWithPrivate = new User("user2", privateAuth);
    // Calculate correct results for 2 users
    final Set<Element> expectedElementsPublicNotPrivate = new HashSet<>();
    final Set<Element> expectedElementsPrivate = new HashSet<>();
    for (final Element element : elements) {
        expectedElementsPrivate.add(element);
        if (element.getProperty("visibility").equals("public")) {
            expectedElementsPublicNotPrivate.add(element);
        }
    }
    // Check get correct edges for user with just public
    GetJavaRDDOfAllElements rddQuery = new GetJavaRDDOfAllElements.Builder().javaSparkContext(sparkContext).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    JavaRDD<Element> rdd = graph1.execute(rddQuery, userWithPublicNotPrivate);
    if (rdd == null) {
        fail("No RDD returned");
    }
    final Set<Element> results = new HashSet<>(rdd.collect());
    assertEquals(expectedElementsPublicNotPrivate, results);
    // Check get correct edges for user with both private and public
    rddQuery = new GetJavaRDDOfAllElements.Builder().javaSparkContext(sparkContext).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    rdd = graph1.execute(rddQuery, userWithPrivate);
    if (rdd == null) {
        fail("No RDD returned");
    }
    results.clear();
    results.addAll(rdd.collect());
    assertEquals(expectedElementsPrivate, results);
    sparkContext.stop();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Configuration(org.apache.hadoop.conf.Configuration) DataOutputStream(java.io.DataOutputStream) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GetJavaRDDOfAllElements(uk.gov.gchq.gaffer.spark.operation.javardd.GetJavaRDDOfAllElements) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Graph(uk.gov.gchq.gaffer.graph.Graph) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Edge(uk.gov.gchq.gaffer.data.element.Edge) SparkConf(org.apache.spark.SparkConf) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with Element

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

the class GetJavaRDDOfAllElementsHandlerTest method checkGetAllElementsInJavaRDD.

@Test
public void checkGetAllElementsInJavaRDD() throws OperationException, IOException {
    final Graph graph1 = new Graph.Builder().addSchema(getClass().getResourceAsStream("/schema/dataSchema.json")).addSchema(getClass().getResourceAsStream("/schema/dataTypes.json")).addSchema(getClass().getResourceAsStream("/schema/storeTypes.json")).storeProperties(getClass().getResourceAsStream("/store.properties")).build();
    final List<Element> elements = new ArrayList<>();
    final Set<Element> expectedElements = new HashSet<>();
    for (int i = 0; i < 10; i++) {
        final Entity entity = new Entity(TestGroups.ENTITY);
        entity.setVertex("" + i);
        final Edge edge1 = new Edge(TestGroups.EDGE);
        edge1.setSource("" + i);
        edge1.setDestination("B");
        edge1.setDirected(false);
        edge1.putProperty(TestPropertyNames.COUNT, 2);
        final Edge edge2 = new Edge(TestGroups.EDGE);
        edge2.setSource("" + i);
        edge2.setDestination("C");
        edge2.setDirected(false);
        edge2.putProperty(TestPropertyNames.COUNT, 4);
        elements.add(edge1);
        elements.add(edge2);
        elements.add(entity);
        expectedElements.add(edge1);
        expectedElements.add(edge2);
        expectedElements.add(entity);
    }
    final User user = new User();
    graph1.execute(new AddElements(elements), user);
    final SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("testCheckGetCorrectElementsInJavaRDDForEntitySeed").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").set("spark.kryo.registrator", "uk.gov.gchq.gaffer.spark.serialisation.kryo.Registrator").set("spark.driver.allowMultipleContexts", "true");
    final JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
    // Create Hadoop configuration and serialise to a string
    final Configuration configuration = new Configuration();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    configuration.write(new DataOutputStream(baos));
    final String configurationString = new String(baos.toByteArray(), CommonConstants.UTF_8);
    // Check get correct edges for "1"
    final GetJavaRDDOfAllElements rddQuery = new GetJavaRDDOfAllElements.Builder().javaSparkContext(sparkContext).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    final JavaRDD<Element> rdd = graph1.execute(rddQuery, user);
    if (rdd == null) {
        fail("No RDD returned");
    }
    final Set<Element> results = new HashSet<>(rdd.collect());
    assertEquals(expectedElements, results);
    sparkContext.stop();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Configuration(org.apache.hadoop.conf.Configuration) DataOutputStream(java.io.DataOutputStream) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GetJavaRDDOfAllElements(uk.gov.gchq.gaffer.spark.operation.javardd.GetJavaRDDOfAllElements) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Graph(uk.gov.gchq.gaffer.graph.Graph) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Edge(uk.gov.gchq.gaffer.data.element.Edge) SparkConf(org.apache.spark.SparkConf) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12