Search in sources :

Example 36 with Element

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

the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement.

@Test
public void shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement() {
    // Given
    final Schema schema = mock(Schema.class);
    final String group = TestGroups.EDGE;
    final Element elm = mock(Element.class);
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter filter = mock(ElementFilter.class);
    final boolean includeIsA = false;
    final ElementValidator validator = new ElementValidator(schema, includeIsA);
    given(elm.getGroup()).willReturn(group);
    given(schema.getElement(group)).willReturn(elementDef);
    given(elementDef.getValidator(includeIsA)).willReturn(filter);
    given(filter.filter(elm)).willReturn(true);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertTrue(isValid);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.Test)

Example 37 with Element

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

the class ElementValidatorTest method shouldReturnFalseWhenNoSchemaElementDefinition.

@Test
public void shouldReturnFalseWhenNoSchemaElementDefinition() {
    // Given
    final Schema schema = mock(Schema.class);
    final String group = TestGroups.EDGE;
    final Element elm = mock(Element.class);
    final boolean includeIsA = true;
    final ElementValidator validator = new ElementValidator(schema, includeIsA);
    given(elm.getGroup()).willReturn(group);
    given(schema.getElement(group)).willReturn(null);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertFalse(isValid);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Example 38 with Element

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

the class StoreTest method shouldFullyLoadLazyElement.

@Test
public void shouldFullyLoadLazyElement() throws StoreException {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    final LazyEntity lazyElement = mock(LazyEntity.class);
    final Entity entity = mock(Entity.class);
    final Store store = new StoreImpl();
    given(lazyElement.getGroup()).willReturn(TestGroups.ENTITY);
    given(lazyElement.getElement()).willReturn(entity);
    store.initialise(schema, properties);
    // When
    final Element result = store.populateElement(lazyElement);
    // Then
    assertSame(entity, result);
    verify(lazyElement).getGroup();
    verify(lazyElement).getProperty(TestPropertyNames.PROP_1);
    verify(lazyElement).getIdentifier(IdentifierType.VERTEX);
}
Also used : LazyEntity(uk.gov.gchq.gaffer.data.element.LazyEntity) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) LazyEntity(uk.gov.gchq.gaffer.data.element.LazyEntity) Test(org.junit.Test)

Example 39 with Element

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

the class LoadAndQuery1 method run.

public CloseableIterable<Edge> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [generate] Create some edges from the data file using our data generator class
    // ---------------------------------------------------------
    final List<Element> elements = new ArrayList<>();
    final DataGenerator1 dataGenerator = new DataGenerator1();
    for (final String s : DataUtils.loadData(getData())) {
        elements.add(dataGenerator.getElement(s));
    }
    // ---------------------------------------------------------
    log("Elements generated from the data file.");
    for (final Element element : elements) {
        log("GENERATED_EDGES", element.toString());
    }
    log("");
    // [graph] Create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] Add the edges to the graph
    // ---------------------------------------------------------
    final AddElements addElements = new AddElements.Builder().elements(elements).build();
    graph.execute(addElements, user);
    // ---------------------------------------------------------
    log("The elements have been added.\n");
    // [get] Get all the edges that contain the vertex "1"
    // ---------------------------------------------------------
    final GetEdges<EntitySeed> query = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
    final CloseableIterable<Edge> results = graph.execute(query, user);
    // ---------------------------------------------------------
    log("All edges containing the vertex 1. The counts have been aggregated.");
    for (final Element e : results) {
        log("GET_RELATED_EDGES_RESULT", e.toString());
    }
    return results;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) DataGenerator1(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator1) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 40 with Element

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

the class AccumuloStoreRelationTest method testBuildScanSpecifyColumnsAndFiltersFullView.

@Test
public void testBuildScanSpecifyColumnsAndFiltersFullView() throws OperationException, StoreException {
    final Schema schema = getSchema();
    final View view = getViewFromSchema(schema);
    final String[] requiredColumns = new String[1];
    requiredColumns[0] = "property1";
    final Filter[] filters = new Filter[1];
    filters[0] = new GreaterThan("property1", 4);
    final Predicate<Element> returnElement = (Element element) -> ((Integer) element.getProperty("property1")) > 4;
    testBuildScanSpecifyColumnsAndFiltersWithView("testBuildScanSpecifyColumnsAndFiltersFullView", view, requiredColumns, filters, returnElement);
}
Also used : Filter(org.apache.spark.sql.sources.Filter) GreaterThan(org.apache.spark.sql.sources.GreaterThan) 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) 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