Skip to content

Commit

Permalink
Gh-502: Document GafferPop NamedOperationService (#511)
Browse files Browse the repository at this point in the history
* update limitations and add named op service info

* add info on TSTV
  • Loading branch information
cn337131 authored Jun 14, 2024
1 parent 1a476f4 commit 3aa3e02
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 7 deletions.
10 changes: 4 additions & 6 deletions docs/user-guide/query/gremlin/gremlin-limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ Current TinkerPop features not present in the GafferPop implementation:

Current known limitations or bugs:

- Proper user authentication is only available if using a Gremlin server and
the `GafferPopAuthoriser` class.
- Proper [user authentication](../../../administration-guide/gaffer-deployment/gremlin.md#user-authentication)
is only available if using a Gremlin server and the `GafferPopAuthoriser` class.
- Performance compared to standard Gaffer `OperationChain`s will likely be
slower as multiple Gaffer `Operations` may utilised to perform one Gremlin
step.
- The ID of an Edge follows a specific format that is made up of its source and
destination IDs like `[source, dest]`. To use this in a seeded query you must
format it like `g.E("[source, dest]")` or a list like
`g.E(["[source1, dest1]","[source2, dest2]"])`
- Edge IDs in GafferPop are not the same as in standard Gremlin. Instead of `g.E(11)`
edge IDs take the format `g.E("[source, dest]")` or `g.E("[source, label, dest]")`.
- The entity group `id` is reserved for an empty group containing only the
vertex ID, this is currently used as a workaround for other limitations.
- Chaining `hasLabel()` calls together like `hasLabel("label1").hasLabel("label2")`
Expand Down
70 changes: 69 additions & 1 deletion docs/user-guide/query/gremlin/gremlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ a table of how different parts are mapped is as follows:
| Vertex | Vertex with default label of `id` |
| Entity | Vertex |
| Edge | Edge |
| Edge ID | A list with the source and destination of the Edge e.g. `[dest, source]` |

In Gafferpop Edge ID's must be made up of a list containing either source and destination
IDs, e.g. `[source, dest]`, or source, label and destination, e.g. `[source, label, dest]`.
In a seeded query these should be formatted like so `g.E("[source, dest]")` or
`g.E(["[source1, dest1]","[source2, label, dest2]"])`.

Note that if using TypeSubTypeValue for seeds or property values these must be in the
format `t:type|st:subtype|v:value`.

## Custom Features

Expand All @@ -259,6 +266,67 @@ standard Tinkerpop framework that you can utilise in your queries. These
are likely specific to how a Gaffer graph operates and may not be available
in other graph technologies that support Gremlin queries.

### NamedOperations in Gremlin

The [GafferPopNamedOperationService](https://gchq.github.io/Gaffer/uk/gov/gchq/gaffer/tinkerpop/service/GafferPopNamedOperationService.html)
allows for the running of Gaffer [Named Operations](../../../administration-guide/named-operations.md) using Tinkerpop.
Users can run Named Operations and add new Named Operations, deleting Named Operations is not currently possible with Tinkerpop.

!!! example ""
Add a simple Named Operation that returns a count of all elements in your graph.

=== "Gremlin"

```python
operation = gc.OperationChain(
operations=[
gc.GetAllElements(),
gc.Count()
]
).to_json_str()

params = {"add": {"name": "CountAllElements", "opChain": operation}}

g.call("namedoperation", params).to_list()
```

=== "Java"

```java
final AddNamedOperation operation = new AddNamedOperation.Builder()
.operationChain(new OperationChain.Builder()
.first(new GetAllElements()
.then(new Count<>())
.build())
.build())
.name("CountAllElements")
.build();

Map<String, String> addParams = new HashMap<>();
addParams.put("name", "CountAllElements");
addParams.put("opChain", operation.getOperationChainAsString());
Map<String, Map <String, String>> params = Collections.singletonMap("add", addParams);

g.call("namedoperation", params).toList();
```

Users can also run any existing or added Named Operations that are stored in the cache.

!!! example ""

=== "Gremlin"

```python
g.call("namedoperation", {"execute": "CountAllElements"}).to_list()
```

=== "Java"

```java
Map<String, String> params = Collections.singletonMap("execute", "CountAllElements")
g.call("namedoperation", params).toList();
```

### Adding Options to Queries

In standard Gremlin syntax it is possible to add additional key value variables
Expand Down

0 comments on commit 3aa3e02

Please sign in to comment.