Search in sources :

Example 11 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class GetWalksIT method shouldGetPathsWithLoops_2.

@Test
public void shouldGetPathsWithLoops_2() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation, operation, operation).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AEDAE,AEDAB");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Test(org.junit.Test)

Example 12 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class GetWalksIT method shouldGetPaths.

@Test
public void shouldGetPaths() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 13 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class GetWalksIT method shouldNotFilterAnyWalksWhenAllContainProperty.

@Test
public void shouldNotFilterAnyWalksWhenAllContainProperty() throws Exception {
    final Iterable<Walk> walks = getWalksThatPassPredicateTest(new CollectionContains(1));
    assertThat(getPaths(walks)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) CollectionContains(uk.gov.gchq.koryphe.impl.predicate.CollectionContains) Test(org.junit.Test)

Example 14 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class GetWalksIT method shouldGetPathsWithLoops_3.

@Test
public void shouldGetPathsWithLoops_3() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE_3, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation, operation, operation).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AAAAA");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 15 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project gaffer-doc by gchq.

the class OperationExample method printResult.

public <RESULT_TYPE> void printResult(final RESULT_TYPE result) {
    print("Result:");
    print("\n{% codetabs name=\"Java\", type=\"java\" -%}");
    if (result instanceof Iterable) {
        for (final Object item : (Iterable) result) {
            if (item instanceof Walk) {
                final Walk walk = (Walk) item;
                print(Walk.class.getName() + walk.getVerticesOrdered().stream().map(Object::toString).collect(Collectors.joining(" --> ", "[ ", " ]")));
            } else {
                print(item.toString());
            }
        }
    } else if (result instanceof Map) {
        final Map<?, ?> resultMap = (Map) result;
        for (final Map.Entry<?, ?> entry : resultMap.entrySet()) {
            print(entry.getKey() + ":");
            if (entry.getValue() instanceof Iterable) {
                for (final Object item : (Iterable) entry.getValue()) {
                    print("    " + item.toString());
                }
            } else {
                print("    " + entry.getValue().toString());
            }
        }
    } else if (result instanceof Stream) {
        final Stream stream = (Stream) result;
        stream.forEach(item -> print(item.toString()));
    } else if (result instanceof Object[]) {
        final Object[] array = (Object[]) result;
        for (int i = 0; i < array.length; i++) {
            print(array[i].toString());
        }
    } else if (result instanceof JavaRDD) {
        final List<Element> elements = ((JavaRDD) result).collect();
        for (final Element e : elements) {
            print(e.toString());
        }
    } else if (result instanceof Dataset) {
        final Dataset<Row> dataset = ((Dataset) result);
        final String resultStr = dataset.showString(100, 20);
        print(resultStr.substring(0, resultStr.length() - 2));
    } else if (result instanceof Schema) {
        print(DocUtil.getJson(result));
    } else if (null != result) {
        print(result.toString());
    } else {
        throw new RuntimeException("Operation result was null");
    }
    try {
        final String json = DocUtil.getFullJson(result);
        print(WalkthroughStrSubstitutor.JSON_CODE_MARKER);
        print(json);
    } catch (final Exception e) {
    // ignore error - just don't display the json
    }
    print("{%- endcodetabs %}\n");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Dataset(org.apache.spark.sql.Dataset) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) IOException(java.io.IOException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) JavaRDD(org.apache.spark.api.java.JavaRDD) Stream(java.util.stream.Stream) Map(java.util.Map)

Aggregations

Walk (uk.gov.gchq.gaffer.data.graph.Walk)36 Test (org.junit.Test)25 GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)19 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 Test (org.junit.jupiter.api.Test)7 Set (java.util.Set)6 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)5 CollectionContains (uk.gov.gchq.koryphe.impl.predicate.CollectionContains)5 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)5 HashMap (java.util.HashMap)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 Map (uk.gov.gchq.gaffer.operation.impl.Map)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 List (java.util.List)2