Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh-380: Update user guide querying section #393

Merged
merged 54 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6b66f75
Added in new user guide section
l46978 Sep 4, 2023
50e9955
Added new development guide structure
l46978 Sep 4, 2023
7a3feb5
Added in new reference structure
l46978 Sep 4, 2023
32588a1
Added new administration guide structure
l46978 Sep 4, 2023
5e4ce5d
Added new change notes structure
l46978 Sep 4, 2023
7e091a5
Corrected spelling mistakes
l46978 Sep 4, 2023
69028a3
Fixed paths and added gaffer docker doc
l46978 Sep 5, 2023
ea6cdbc
Added example deployment to developer docs
l46978 Sep 5, 2023
580e3d0
Initial querying pages
tb06904 Sep 5, 2023
aa85ef3
Moved old v2 docs to new structure
l46978 Sep 5, 2023
7481d8f
Removed unwanted pages and corrected paths
l46978 Sep 6, 2023
29bc5e7
Removed unwanted sections and files
l46978 Sep 7, 2023
efb9b92
Corrected all doc links
l46978 Sep 7, 2023
b617f46
Added Endpoints guide
l46978 Sep 7, 2023
89e5d44
Corrected site contents in index.md
l46978 Sep 7, 2023
25cdd45
add pages on filtering and operations
tb06904 Sep 7, 2023
3ade136
Merge branch 'v2docs' into 378-gaffer-documentation-restructure
l46978 Sep 8, 2023
267dfc6
Merge branch '378-gaffer-documentation-restructure' into gh-380-user-…
tb06904 Sep 8, 2023
d676b0c
add section on transformation
tb06904 Sep 8, 2023
7634811
add aggregation section
tb06904 Sep 11, 2023
0b283eb
tidy the import/export page
tb06904 Sep 12, 2023
e5a9ce3
Restructure the sections pages
tb06904 Sep 12, 2023
cd79232
add examples for java and python operations
tb06904 Sep 13, 2023
70c89a7
typos
tb06904 Sep 13, 2023
48e695a
Merge branch 'v2docs' into gh-380-user-guide-querying
tb06904 Sep 13, 2023
dd18afd
restructure and tidy
tb06904 Sep 13, 2023
4548ef8
added examples for other APIs
tb06904 Sep 14, 2023
2d49098
remove file from merge conflict
tb06904 Sep 14, 2023
3af9b72
address comments
tb06904 Sep 15, 2023
66102fc
fix dead links
tb06904 Sep 15, 2023
133e400
typo
tb06904 Sep 18, 2023
cd33a6d
Update docs/user-guide/apis/java-api.md
tb06904 Sep 19, 2023
23813ee
Update docs/user-guide/apis/python-api.md
tb06904 Sep 19, 2023
6e53b41
Update docs/user-guide/apis/python-api.md
tb06904 Sep 19, 2023
89ba0ff
Update docs/user-guide/apis/python-api.md
tb06904 Sep 19, 2023
a32c099
Update docs/user-guide/apis/python-api.md
tb06904 Sep 19, 2023
0003565
Update docs/user-guide/apis/python-api.md
tb06904 Sep 19, 2023
34ea6ba
Update docs/user-guide/apis/rest-api.md
tb06904 Sep 19, 2023
bd49b1b
Update docs/user-guide/apis/rest-api.md
tb06904 Sep 19, 2023
e4253a5
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
4ac7aff
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
b9d57ad
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
c5ef9ea
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
9db007b
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
c400aef
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
36f311d
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
0ae7942
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
c41ffd9
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
3547cfb
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
d942b6b
Update docs/user-guide/query/gaffer-syntax/filtering.md
tb06904 Sep 19, 2023
9e29a83
Update docs/user-guide/query/gaffer-syntax/operations.md
tb06904 Sep 19, 2023
5d04052
apply grammar suggestions
tb06904 Sep 19, 2023
0f40c01
Apply suggestions from code review
tb06904 Sep 21, 2023
a5e6110
fix typo
tb06904 Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/change-notes/migrating-from-v1-to-v2/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Now set in `serialiser`:
.library(myGraphLibrary)
.view(myView)
.addHook(customHook)
.build())
.build())
.addSchema(mySchema) // (1)!
.storeProperties(storeProperties) // (2)!
.build();
Expand Down
84 changes: 42 additions & 42 deletions docs/reference/operations-guide/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gets data from an endpoint. [Javadoc](https://gchq.github.io/Gaffer/uk/gov/gchq/
```

=== "JSON"

``` json
{
"class" : "GetFromEndpoint",
Expand All @@ -38,10 +38,10 @@ Gets data from an endpoint. [Javadoc](https://gchq.github.io/Gaffer/uk/gov/gchq/
```

=== "Python"

``` python
g.GetFromEndpoint(
endpoint="https://mydata.io:8443/mydata"
g.GetFromEndpoint(
endpoint="https://mydata.io:8443/mydata"
)
```

Expand All @@ -68,7 +68,7 @@ This operation requires Store configuration to be set before it can be used. See
```

=== "JSON"

``` json
{
"class" : "ScoreOperationChain",
Expand All @@ -89,34 +89,34 @@ This operation requires Store configuration to be set before it can be used. See
```

=== "Python"

``` python
g.ScoreOperationChain(
operation_chain=g.OperationChain(
operations=[
g.GetElements(),
g.NamedOperation(
operation_name="namedOp"
),
g.Limit(
result_limit=3,
truncate=True
)
]
)
g.ScoreOperationChain(
operation_chain=g.OperationChain(
operations=[
g.GetElements(),
g.NamedOperation(
operation_name="namedOp"
),
g.Limit(
result_limit=3,
truncate=True
)
]
)
)
```

Results:

=== "Java"

``` java
5
```

=== "JSON"

``` json
5
```
Expand All @@ -140,7 +140,7 @@ Here we have added a NamedOperation to the NamedOperationCache, with a custom sc
```

=== "JSON"

``` json
{
"class" : "ScoreOperationChain",
Expand All @@ -164,38 +164,38 @@ Here we have added a NamedOperation to the NamedOperationCache, with a custom sc
```

=== "Python"

``` python
g.ScoreOperationChain(
operation_chain=g.OperationChain(
operations=[
g.NamedOperation(
input=[
g.EntitySeed(
vertex=1
)
],
operation_name="1-hop"
),
g.Limit(
result_limit=3,
truncate=True
)
]
)
g.ScoreOperationChain(
operation_chain=g.OperationChain(
operations=[
g.NamedOperation(
input=[
g.EntitySeed(
vertex=1
)
],
operation_name="1-hop"
),
g.Limit(
result_limit=3,
truncate=True
)
]
)
)
```

Results:

=== "Java"

``` java
5
```

=== "JSON"

``` json
5
```
94 changes: 0 additions & 94 deletions docs/user-guide/api.md

This file was deleted.

59 changes: 59 additions & 0 deletions docs/user-guide/apis/java-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Using the Java API

As Gaffer is written in Java there is native support to allow use of all its
public classes. Using Gaffer via the Java interface does differ from the rest
API and `gafferpy` but is fully featured with extensive
[Javadocs](https://gchq.github.io/Gaffer/overview-summary.html). However, You
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
will of course need to be familiar with writing and running Java code in order
to utilise this form of the API.

## Querying a Graph

Using Java to Query a graph unlike the other APIs requires a reference to a
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
`Graph` object that essentially represents a graph.

With the other APIs you would connect directly to a running instance via the
rest interface; however, to do this with Java you would need to configure a
`Graph` object with a proxy store.
tb06904 marked this conversation as resolved.
Show resolved Hide resolved

!!! example ""
The following example uses the `ProxyStore.Builder()` to configure a `Graph`
to connect to the required address (in this case
`http://localhost:8080/rest/latest`).
tb06904 marked this conversation as resolved.
Show resolved Hide resolved

```java
Graph graph = new Graph.Builder()
.store(new ProxyStore.Builder()
.graphId(uniqueNameOfYourGraph)
.host("localhost")
.port(8080)
.contextRoot("rest/latest")
.build())
.build();
```

Once the connection to a graph is made you can run queries and operations on
it using the available classes and builders.

!!! example ""
The following operation chain gets all the elements in the graph then will
count them and store the result in a `Long`.

```java
OperationChain<Long> countAllElements = new OperationChain.Builder()
.first(new GetAllElements())
.then(new Count<>())
.build();

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

If you're interested in learning more about the `Graph` class please see the
[developers guide](../../development-guide/project-structure/components/graph.md)
on the subject.

!!! note
One other thing to note about the Java API is that the `execute()` method
requires you to have a `User`. This is part of the available fine grain
security Gaffer provides see the [admin guide](../../administration-guide/security/security-guide.md)
for more information.
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
75 changes: 75 additions & 0 deletions docs/user-guide/apis/python-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Using the Python API

This section covers an overview of the python API extension for Gaffer to
demonstrate how to get up and running to perform queries from Python code on an
existing running graph.

!!! tip
Please see the handy introduction on [what is python](../gaffer-basics/what-is-python.md)
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
if you are new to the language.

## What is the Python Extension?

Commonly referred to as `gafferpy` this is an API to gaffer that provides
similar querying capabilities to the rest API but from Python. Fundamentally it
wraps the rest API to use the same JSON under the hood this means you should be
able to access almost any features or end points available in the main rest API.

## Installation

Currently there isn't a release of `gafferpy` on pypi or other pip repository;
however, the source code can still be cloned from the [git repository](https://github.com/gchq/gaffer-tools/tree/develop/python-shell)
and installed via pip. Please see the readme in the `gafferpy` repository for
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
full instructions.

## How to Query a Graph

To get started with `gafferpy` you will need to import the module and connect to
an existing graph, the connection should be the same address as where the rest
API is running.

```python
from gafferpy import gaffer
from gafferpy import gaffer_connector
g_connector = gaffer_connector.GafferConnector("http://localhost:8080/rest/latest")
```

Once connected you can access and run the same endpoints and operations as you
would via the usual rest API but via their python classes. The endpoints are
accessed via the `GafferConnector` to allow you executing Operation chains to
perform queries on the graph.

!!! note
There may be of the features of the full rest API not be present in
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
`gafferpy` as always check the [reference guide](../../reference/intro.md)
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
first.

!!! example ""
A simple Operation can be called via the `execute_operation()` function. As
an example, the following will get all the elements in a graph:

```python
elements = g_connector.execute_operation(
operation = gaffer.GetAllElements()
)
```

!!! example ""
An Operation chain can be ran using the `execute_operation_chain()` function.
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
As an example, the following will get all the elements in a graph then
count them.

```python
count = g_connector.execute_operation_chain(
operation_chain = gaffer.OperationChain(
operations=[
gaffer.GetAllElements(),
gaffer.Count()
]
)
)
```

Along with running Operations you can of course optionally apply some filtering
provided by a `View`. There are more detail on both [filtering](../query/gaffer-syntax/filtering.md)
tb06904 marked this conversation as resolved.
Show resolved Hide resolved
and [operations](../query/gaffer-syntax/operations.md) on their respective pages.
Loading
Loading