DanGuge opened a new pull request, #2262:
URL: https://github.com/apache/incubator-hugegraph/pull/2262
<!--
Thank you very much for contributing to Apache HugeGraph, we are happy
that you want to help us improve it!
Here are some tips for you:
1. If this is your first time, please read the [contributing
guidelines](https://github.com/apache/hugegraph/blob/master/CONTRIBUTING.md)
2. If a PR fix/close an issue, type the message "close xxx" (xxx is the
link of related
issue) in the content, GitHub will auto link it (Required)
3. Name the PR title in "Google Commit Format", start with "feat | fix |
perf | refactor | doc | chore",
such like: "feat(core): support the PageRank algorithm" or "fix: wrong
break in the compute loop" (module is optional)
skip it if you are unsure about which is the best component.
4. One PR address one issue, better not to mix up multiple issues.
5. Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]` (or click
it directly after
published)
-->
## Purpose of the PR
- Add statistics infomation in oltp api response, including the number of
vertices and edges traversed at runtime, as well as the time the api takes to
execute
- Support full infomation about vertices and edges in oltp api response
<!--
Please explain more context in this section, clarify why the changes are
needed.
e.g:
- If you propose a new API, clarify the use case for a new API.
- If you fix a bug, you can clarify why it is a bug, and should be
associated with an issue.
-->
## Main Changes
<!-- Please clarify what changes you are proposing. The purpose of this
section is to outline the changes and how this PR fixes the issue. These change
logs are helpful for better ant faster reviews.)
For example:
- If you introduce a new feature, please show detailed design here or add
the link of design documentation.
- If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
- If there is a discussion in the mailing list, please add the link. -->
### Statistics information:
* add vertexIterCounter and edgeIterCounter in HugeTraverser.java to track
traversed vertices and edges at run time
* modify all oltp apis to add statistics information in response
* modify Serializer.java and JsonSerializer.java to support statistics
infomation serialization
### Full information about vertices and edges:
* add 'with_vertex' and 'with_edge' parameter option in oltp apis
* modify oltp apis to support vertex and edge information in api response
* add EdgeRecord in HugeTraverser.java to record edges at run time and
generate the edge information returned in api response
* modify Path and PathSet in HugeTraverser.java to support full edge
information storage
* modify all traversers to support track of edge information at run time
* modify Serializer.java and JsonSerializer.java to support full infomation
serialization about vertices and edges
### Implementation overview
* **N: No Need**
* **✓: Supported**
| | statistics | with_vertex | with_edge |
| ------------------------------- | ---------- | ----------- | --------- |
| Kout Get | **✓** | **N** | **N** |
| Kout Post | **✓** | **✓** | **✓** |
| Kneighbor Get | **✓** | **N** | **N** |
| Kneighbor Post | **✓** | **✓** | **✓** |
| Sameneighbors Get | **✓** | **N** | **N** |
| Sameneighbors Post | **✓** | **✓** | **N** |
| Jaccard Similarity Get | **✓** | **N** | **N** |
| Jaccard Similarity Post | **✓** | **N** | **N** |
| Shortest Path Get | **✓** | **✓** | **✓** |
| All Shortest Paths Get | **✓** | **✓** | **✓** |
| Weighted Shortest Path Get | **✓** | **✓** | **✓** |
| Single Source Shortest Path Get | **✓** | **✓** | **✓** |
| Multi Node Shortest Path Post | **✓** | **✓** | **✓** |
| Paths Get | **✓** | **N** | **N** |
| Paths Post | **✓** | **✓** | **✓** |
| Customized Paths Post | **✓** | **✓** | **✓** |
| Template Paths Post | **✓** | **✓** | **✓** |
| Crosspoints Get | **✓** | **N** | **N** |
| Customized Crosspoints Post | **✓** | **✓** | **✓** |
| Rings Get | **✓** | **✓** | **✓** |
| Rays Get | **✓** | **✓** | **✓** |
| Fusiform Similarity Post | **✓** | **N** | **N** |
## Verifying these changes
<!-- Please pick the proper options below -->
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [ ] Already covered by existing tests, such as *(please modify tests
here)*.
- [x] Need tests and can be verified as follows:
- Postman Test: the tests of `Kout Post` and `Single Source Shortest
Path Get` are shown below
### Initialize the Graph
* Initialze the graph according to the
[link](https://hugegraph.apache.org/docs/clients/restful-api/traverser/#32-detailed-explanation-of-traverser-api-1)
### Kout Post
* Method & Url
```
POST http://localhost:8080/graphs/{graph}/traversers/kout
```
#### with_vertex=false, with_edge=false
* Request Body
```json
{
"source": "1:marko",
"step": {
"direction": "BOTH",
"labels": ["knows", "created"],
"properties": {
"weight": "P.gt(0.1)"
},
"max_degree": 10000,
"skip_degree": 100000
},
"max_depth": 1,
"nearest": true,
"limit": 10000,
"with_vertex": false,
"with_path": true,
"with_edge": false
}
```
* Response Status
```
200
```
* Response Body
```json
{
"kout": [
"1:vadas",
"1:josh",
"2:lop"
],
"size": 3,
"paths": [
{
"objects": [
"1:marko",
"2:lop"
]
},
{
"objects": [
"1:marko",
"1:josh"
]
},
{
"objects": [
"1:marko",
"1:vadas"
]
}
],
"vertices": [
"1:marko",
"1:josh",
"1:vadas",
"2:lop"
],
"edges": [
"S1:marko>1>20160110>S1:vadas",
"S1:marko>2>>S2:lop",
"S1:marko>1>20130220>S1:josh"
],
"measure": {
"edge_iters": 3,
"vertice_iters": 1,
"cost": 72
}
}
```
<img width="1494" alt="image"
src="https://github.com/apache/incubator-hugegraph/assets/77946882/2c6e7ca8-afc6-42ef-a6db-d957b2f90879">
#### with_vertex=true, with_edge=true
* Request Body
```json
{
"source": "1:marko",
"step": {
"direction": "BOTH",
"labels": ["knows", "created"],
"properties": {
"weight": "P.gt(0.1)"
},
"max_degree": 10000,
"skip_degree": 100000
},
"max_depth": 1,
"nearest": true,
"limit": 10000,
"with_vertex": true,
"with_path": true,
"with_edge": true
}
```
* Response Status
```
200
```
* Response Body
```json
{
"kneighbor": [
"1:vadas",
"1:josh",
"2:lop",
"1:peter",
"2:ripple"
],
"size": 5,
"paths": [
{
"objects": [
"1:marko",
"2:lop"
]
},
{
"objects": [
"1:marko",
"2:lop",
"1:peter"
]
},
{
"objects": [
"1:marko",
"1:josh"
]
},
{
"objects": [
"1:marko",
"1:vadas"
]
},
{
"objects": [
"1:marko",
"1:josh",
"2:ripple"
]
}
],
"vertices": [
{
"id": "2:ripple",
"label": "software",
"type": "vertex",
"properties": {
"name": "ripple",
"lang": "java",
"price": 199
}
},
{
"id": "1:marko",
"label": "person",
"type": "vertex",
"properties": {
"name": "marko",
"age": 29,
"city": "Beijing"
}
},
{
"id": "1:josh",
"label": "person",
"type": "vertex",
"properties": {
"name": "josh",
"age": 32,
"city": "Beijing"
}
},
{
"id": "1:vadas",
"label": "person",
"type": "vertex",
"properties": {
"name": "vadas",
"age": 27,
"city": "Hongkong"
}
},
{
"id": "1:peter",
"label": "person",
"type": "vertex",
"properties": {
"name": "peter",
"age": 35,
"city": "Shanghai"
}
},
{
"id": "2:lop",
"label": "software",
"type": "vertex",
"properties": {
"name": "lop",
"lang": "java",
"price": 328
}
}
],
"edges": [
{
"id": "S1:josh>2>>S2:ripple",
"label": "created",
"type": "edge",
"outV": "1:josh",
"outVLabel": "person",
"inV": "2:ripple",
"inVLabel": "software",
"properties": {
"weight": 1.0,
"date": "20171210"
}
},
{
"id": "S1:marko>1>20160110>S1:vadas",
"label": "knows",
"type": "edge",
"outV": "1:marko",
"outVLabel": "person",
"inV": "1:vadas",
"inVLabel": "person",
"properties": {
"weight": 0.5,
"date": "20160110"
}
},
{
"id": "S1:marko>2>>S2:lop",
"label": "created",
"type": "edge",
"outV": "1:marko",
"outVLabel": "person",
"inV": "2:lop",
"inVLabel": "software",
"properties": {
"weight": 0.4,
"date": "20171210"
}
},
{
"id": "S1:marko>1>20130220>S1:josh",
"label": "knows",
"type": "edge",
"outV": "1:marko",
"outVLabel": "person",
"inV": "1:josh",
"inVLabel": "person",
"properties": {
"weight": 1.0,
"date": "20130220"
}
},
{
"id": "S1:peter>2>>S2:lop",
"label": "created",
"type": "edge",
"outV": "1:peter",
"outVLabel": "person",
"inV": "2:lop",
"inVLabel": "software",
"properties": {
"weight": 0.2,
"date": "20170324"
}
}
],
"measure": {
"edge_iters": 12,
"vertice_iters": 12,
"cost": 34
}
}
```
<img width="1486" alt="image"
src="https://github.com/apache/incubator-hugegraph/assets/77946882/85eec8e9-7e80-450c-9be6-06792dd4133c">
### Single Source Shortest Path Get
* Method & Url
```
http://localhost:8080/graphs/hugegraph/traversers/singlesourceshortestpath?source="1:marko"&with_vertex=false&with_edge=false&weight=weight
```
* Response Status
```
200
```
* Response Body
```json
{
"paths": {
"1:peter": {
"weight": 0.6000000000000001,
"vertices": [
"1:marko",
"2:lop",
"1:peter"
]
},
"2:lop": {
"weight": 0.4,
"vertices": [
"1:marko",
"2:lop"
]
},
"1:josh": {
"weight": 0.8,
"vertices": [
"1:marko",
"2:lop",
"1:josh"
]
},
"2:ripple": {
"weight": 1.8,
"vertices": [
"1:marko",
"2:lop",
"1:josh",
"2:ripple"
]
},
"1:vadas": {
"weight": 0.5,
"vertices": [
"1:marko",
"1:vadas"
]
}
},
"vertices": [
"1:peter",
"2:lop",
"1:josh",
"2:ripple",
"1:marko",
"1:vadas"
],
"edges": [
"S1:josh>2>>S2:ripple",
"S1:marko>1>20160110>S1:vadas",
"S1:josh>2>>S2:lop",
"S1:marko>2>>S2:lop",
"S1:peter>2>>S2:lop"
],
"measure": {
"edge_iters": 12,
"vertice_iters": 6,
"cost": 16
}
}
```
<img width="1483" alt="image"
src="https://github.com/apache/incubator-hugegraph/assets/77946882/e49b4dee-b795-4c75-bb37-7b2c104fa1c4">
* Method & Url
```
http://localhost:8080/graphs/hugegraph/traversers/singlesourceshortestpath?source="1:marko"&with_vertex=true&with_edge=true&weight=weight
```
* Response Status
```
200
```
* Response Body
```json
{
"paths": {
"1:peter": {
"weight": 0.6000000000000001,
"vertices": [
"1:marko",
"2:lop",
"1:peter"
]
},
"2:lop": {
"weight": 0.4,
"vertices": [
"1:marko",
"2:lop"
]
},
"1:josh": {
"weight": 0.8,
"vertices": [
"1:marko",
"2:lop",
"1:josh"
]
},
"2:ripple": {
"weight": 1.8,
"vertices": [
"1:marko",
"2:lop",
"1:josh",
"2:ripple"
]
},
"1:vadas": {
"weight": 0.5,
"vertices": [
"1:marko",
"1:vadas"
]
}
},
"vertices": [
{
"id": "1:peter",
"label": "person",
"type": "vertex",
"properties": {
"name": "peter",
"age": 35,
"city": "Shanghai"
}
},
{
"id": "2:lop",
"label": "software",
"type": "vertex",
"properties": {
"name": "lop",
"lang": "java",
"price": 328
}
},
{
"id": "1:josh",
"label": "person",
"type": "vertex",
"properties": {
"name": "josh",
"age": 32,
"city": "Beijing"
}
},
{
"id": "2:ripple",
"label": "software",
"type": "vertex",
"properties": {
"name": "ripple",
"lang": "java",
"price": 199
}
},
{
"id": "1:marko",
"label": "person",
"type": "vertex",
"properties": {
"name": "marko",
"age": 29,
"city": "Beijing"
}
},
{
"id": "1:vadas",
"label": "person",
"type": "vertex",
"properties": {
"name": "vadas",
"age": 27,
"city": "Hongkong"
}
}
],
"edges": [
{
"id": "S1:josh>2>>S2:ripple",
"label": "created",
"type": "edge",
"outV": "1:josh",
"outVLabel": "person",
"inV": "2:ripple",
"inVLabel": "software",
"properties": {
"weight": 1.0,
"date": "20171210"
}
},
{
"id": "S1:marko>1>20160110>S1:vadas",
"label": "knows",
"type": "edge",
"outV": "1:marko",
"outVLabel": "person",
"inV": "1:vadas",
"inVLabel": "person",
"properties": {
"weight": 0.5,
"date": "20160110"
}
},
{
"id": "S1:josh>2>>S2:lop",
"label": "created",
"type": "edge",
"outV": "1:josh",
"outVLabel": "person",
"inV": "2:lop",
"inVLabel": "software",
"properties": {
"weight": 0.4,
"date": "20091111"
}
},
{
"id": "S1:marko>2>>S2:lop",
"label": "created",
"type": "edge",
"outV": "1:marko",
"outVLabel": "person",
"inV": "2:lop",
"inVLabel": "software",
"properties": {
"weight": 0.4,
"date": "20171210"
}
},
{
"id": "S1:peter>2>>S2:lop",
"label": "created",
"type": "edge",
"outV": "1:peter",
"outVLabel": "person",
"inV": "2:lop",
"inVLabel": "software",
"properties": {
"weight": 0.2,
"date": "20170324"
}
}
],
"measure": {
"edge_iters": 12,
"vertice_iters": 12,
"cost": 2
}
}
```
<img width="1480" alt="image"
src="https://github.com/apache/incubator-hugegraph/assets/77946882/1cc33945-cf66-4e4b-99fe-5acae05c4710">
## Does this PR potentially affect the following parts?
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] Nope
- [ ] Dependencies (add/update license info) <!-- Don't forget to
add/update the info in "LICENSE" & "NOTICE" files (both in root & dist module)
-->
- [ ] Modify configurations
- [x] The public API
- [ ] Other affects (typed here)
## Documentation Status
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [x] `Doc - TODO` <!-- Your PR changes impact docs and you will update
later -->
- [ ] `Doc - Done` <!-- Related docs have been already added or updated -->
- [ ] `Doc - No Need` <!-- Your PR changes don't impact/need docs -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]