Search in sources :

Example 61 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AbstractGetIterableOperationTest method shouldCopyFieldsFromGivenOperationWhenConstructing.

@Test
public void shouldCopyFieldsFromGivenOperationWhenConstructing() {
    // Given
    final GetIterableOperation<ElementSeed, ?> operationToCopy = mock(GetIterableOperation.class);
    final View view = mock(View.class);
    final GetOperation.IncludeEdgeType includeEdges = GetOperation.IncludeEdgeType.ALL;
    final boolean includeEntities = true;
    final boolean populateProperties = true;
    final CloseableIterable<ElementSeed> input = mock(CloseableIterable.class);
    given(operationToCopy.getView()).willReturn(view);
    given(operationToCopy.getInput()).willReturn(input);
    // When
    final GetIterableOperationImpl<ElementSeed, Element> operation = new GetIterableOperationImpl<>(operationToCopy);
    // Then
    assertSame(view, operation.getView());
    assertSame(input, operation.getInput());
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetIterableOperationImpl(uk.gov.gchq.gaffer.operation.impl.GetIterableOperationImpl) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 62 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class ExamplesServiceTest method shouldCreateViewForEdges.

@Test
public void shouldCreateViewForEdges() {
    final View.Builder builder = service.generateViewBuilder();
    final View view = builder.build();
    assertNotNull(view);
    final ViewValidator viewValidator = new ViewValidator();
    final boolean validate = viewValidator.validate(view, schema, false);
    assertTrue(validate);
}
Also used : ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 63 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GetDataFrameOfElementsExample method getDataFrameOfElementsWithEdgeGroup.

public void getDataFrameOfElementsWithEdgeGroup(final SQLContext sqlc, final Graph graph) throws OperationException {
    ROOT_LOGGER.setLevel(Level.INFO);
    log("#### " + getMethodNameAsSentence(0) + "\n");
    printGraph();
    ROOT_LOGGER.setLevel(Level.OFF);
    final GetDataFrameOfElements operation = new GetDataFrameOfElements.Builder().view(new View.Builder().edge("edge").build()).sqlContext(sqlc).build();
    final Dataset<Row> df = graph.execute(operation, new User("user01"));
    // Show
    String result = df.showString(100, 20);
    ROOT_LOGGER.setLevel(Level.INFO);
    printJava("GetDataFrameOfElements operation = new GetDataFrameOfElements.Builder()\n" + "                .view(new View.Builder()\n" + "                        .entity(\"edge\")\n" + "                        .build()).\n" + "                .sqlContext(sqlc)\n" + "                .build();\n" + "Dataset<Row> df = getGraph().execute(operation, new User(\"user01\"));\n" + "df.show();");
    log("The results are:");
    log("```");
    log(result.substring(0, result.length() - 2));
    log("```");
    ROOT_LOGGER.setLevel(Level.OFF);
    // Restrict to edges involving given vertices
    final Dataset<Row> seeded = df.filter("src = 1 OR src = 3");
    result = seeded.showString(100, 20);
    ROOT_LOGGER.setLevel(Level.INFO);
    printJava("df.filter(\"src = 1 OR src = 3\").show();");
    log("The results are:");
    log("```");
    log(result.substring(0, result.length() - 2));
    log("```");
    ROOT_LOGGER.setLevel(Level.OFF);
    // Filter by property
    final Dataset<Row> filtered = df.filter("count > 1");
    result = filtered.showString(100, 20);
    ROOT_LOGGER.setLevel(Level.INFO);
    printJava("df.filter(\"count > 1\").show();");
    log("The results are:");
    log("```");
    log(result.substring(0, result.length() - 2));
    log("```");
    ROOT_LOGGER.setLevel(Level.OFF);
}
Also used : GetDataFrameOfElements(uk.gov.gchq.gaffer.spark.operation.dataframe.GetDataFrameOfElements) User(uk.gov.gchq.gaffer.user.User) Row(org.apache.spark.sql.Row) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 64 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloStoreRelationTest method testBuildScanFullView.

@Test
public void testBuildScanFullView() throws OperationException, StoreException {
    final Schema schema = getSchema();
    final View view = getViewFromSchema(schema);
    testBuildScanWithView("testBuildScanFullView", view, e -> true);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 65 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AccumuloStoreRelationTest method testBuildScanRestrictViewByProperty.

@Test
public void testBuildScanRestrictViewByProperty() throws OperationException, StoreException {
    final List<ConsumerFunctionContext<String, FilterFunction>> filters = new ArrayList<>();
    filters.add(new ConsumerFunctionContext<>(new IsMoreThan(5, false), new ArrayList<>(Arrays.asList("property1"))));
    final View view = new View.Builder().edge(GetDataFrameOfElementsHandlerTest.EDGE_GROUP, new ViewElementDefinition.Builder().postAggregationFilterFunctions(filters).build()).build();
    final Predicate<Element> returnElement = (Element element) -> element.getGroup().equals(GetDataFrameOfElementsHandlerTest.EDGE_GROUP) && ((Integer) element.getProperty("property1")) > 5;
    testBuildScanWithView("testBuildScanRestrictViewByProperty", view, returnElement);
}
Also used : ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Aggregations

View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)107 Test (org.junit.Test)70 Element (uk.gov.gchq.gaffer.data.element.Element)42 User (uk.gov.gchq.gaffer.user.User)38 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)32 HashSet (java.util.HashSet)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 Graph (uk.gov.gchq.gaffer.graph.Graph)20 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)19 ArrayList (java.util.ArrayList)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 Edge (uk.gov.gchq.gaffer.data.element.Edge)13 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)12 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)11 SQLContext (org.apache.spark.sql.SQLContext)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8