Skip to content

Commit

Permalink
re-order examples for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
cn337131 committed Dec 4, 2023
1 parent bb8fb8e commit 40de018
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 98 deletions.
156 changes: 78 additions & 78 deletions docs/user-guide/query/gaffer-syntax/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ associated with it. Then we can apply a filter to include only edges where the
In this scenario it is analogous to asking, *"Get all the `Created` edges on
node `John` that have a `weight` greater than 0.4"*.

=== "Java"

```java
// Define the View to use
final View viewWithFilters = new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.preAggregationFilter(new ElementFilter.Builder()
.select("weight")
.execute(new IsMoreThan(0.4))
.build())
.build())
.build();

// Create the operation to execute
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(viewWithFilters)
.build();

graph.execute(operation, user);
```

=== "JSON"

```json
Expand Down Expand Up @@ -128,28 +150,6 @@ associated with it. Then we can apply a filter to include only edges where the
)
```

=== "Java"

```java
// Define the View to use
final View viewWithFilters = new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.preAggregationFilter(new ElementFilter.Builder()
.select("weight")
.execute(new IsMoreThan(0.4))
.build())
.build())
.build();

// Create the operation to execute
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(viewWithFilters)
.build();

graph.execute(operation, user);
```

To form relevant filters and queries it is usually required that you know the
graph schema in use. The schema determines what properties and elements you can
reference in your queries and the general structure of the data in the graph.
Expand Down Expand Up @@ -203,6 +203,29 @@ properties are returned.
edges in the output, and specifically excluding the `age` property from any
returned `Person` entities.

=== "Java"

```java
// Define the View to use
final View viewWithFilters = new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.properties("hours")
.build())
.entities("Person", new ViewElementDefinition.Builder()
.excludeProperties("age")
.build())
.build();

// Create the operation to execute
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(viewWithFilters)
.build();

graph.execute(operation, user);
```


=== "JSON"

```json
Expand Down Expand Up @@ -253,28 +276,6 @@ properties are returned.
)
```

=== "Java"

```java
// Define the View to use
final View viewWithFilters = new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.properties("hours")
.build())
.entities("Person", new ViewElementDefinition.Builder()
.excludeProperties("age")
.build())
.build();

// Create the operation to execute
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(viewWithFilters)
.build();

graph.execute(operation, user);
```

## Transformation

It is possible to apply a transformation to the output of a query which then
Expand Down Expand Up @@ -302,6 +303,21 @@ and save the returned information into a new `minutes` transient property.
property we then use the `MultiplyBy` Koryphe function to transform a
property and project the result into a transient property named `"minutes"`.

=== "Java"

```java
final GetElements getEdgesWithMinutes = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.transientProperty("minutes", Integer.class)
.transformer(new MultiplyBy(60))
.build())
.build())
.build();

graph.execute(getEdgesWithMinutes, user);
```

=== "JSON"

Expand Down Expand Up @@ -362,22 +378,6 @@ and save the returned information into a new `minutes` transient property.
)
```

=== "Java"

```java
final GetElements getEdgesWithMinutes = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(new View.Builder()
.edge("Created", new ViewElementDefinition.Builder()
.transientProperty("minutes", Integer.class)
.transformer(new MultiplyBy(60))
.build())
.build())
.build();

graph.execute(getEdgesWithMinutes, user);
```

The `selection` in a transform is similar to the way we select properties and
identifiers in a filter and as demonstrated you can select (and also project)
any property but also any of these unique identifiers:
Expand Down Expand Up @@ -439,6 +439,24 @@ total for all the `added` property.
we have applied aggregation so the result will contain an element with
a `Sum` of all the `added` properties.

=== "Java"

```java
final GetElements getEdgesAggregated = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(new View.Builder()
.edge("Commit", new ViewElementDefinition.Builder()
.groupBy()
.aggregator(new ElementAggregator.Builder()
.select("added")
.execute(new Sum())
.build()))
.build())
.build();

graph.execute(getEdgesAggregated, user);
```
=== "JSON"

```json
Expand Down Expand Up @@ -495,24 +513,6 @@ total for all the `added` property.
)
```

=== "Java"

```java
final GetElements getEdgesAggregated = new GetElements.Builder()
.input(new EntitySeed("John"))
.view(new View.Builder()
.edge("Commit", new ViewElementDefinition.Builder()
.groupBy()
.aggregator(new ElementAggregator.Builder()
.select("added")
.execute(new Sum())
.build()))
.build())
.build();

graph.execute(getEdgesAggregated, user);
```

!!! tip
As with some of the other examples we again use a class from the Koryphe
module to help with the aggregation, please see the [reference
Expand Down
41 changes: 21 additions & 20 deletions docs/user-guide/query/gaffer-syntax/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ based on their ID. To do this we can use the `GetElements` operation and set the

Assuming the entity ID we wish to search from is `"v1"`.

=== "Java"

```java
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("v1"))
.build();

graph.execute(operation, user);
```

=== "JSON"

```json
Expand All @@ -67,15 +77,6 @@ based on their ID. To do this we can use the `GetElements` operation and set the
)
```

=== "Java"

```java
final GetElements operation = new GetElements.Builder()
.input(new EntitySeed("v1"))
.build();

graph.execute(operation, user);
```

This can then be expanded into a chain by using the output from the
`GetElements` operation as the input to the `Count` operation to give a total of
Expand All @@ -85,6 +86,17 @@ how many entities the `GetElements` returned.
As you can see we have used the `OperationChain` to run two operations in a
chain with the output of one being the input of the next.

=== "Java"

```java
OperationChain<Long> countElements = new OperationChain.Builder()
.first(new GetElements.Builder().input(new EntitySeed("v1")).build())
.then(new Count<>())
.build();

Long result = graph.execute(countElements, user);
```

=== "JSON"

```json
Expand Down Expand Up @@ -119,17 +131,6 @@ how many entities the `GetElements` returned.
)
```

=== "Java"

```java
OperationChain<Long> countElements = new OperationChain.Builder()
.first(new GetElements.Builder().input(new EntitySeed("v1")).build())
.then(new Count<>())
.build();

Long result = graph.execute(countElements, user);
```

To chain operations it's important to take note of what each operations input and
outputs are, say if you want to chain two together like the following:

Expand Down

0 comments on commit 40de018

Please sign in to comment.