Skip to content

Commit

Permalink
docs of result set as primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
wey-gu committed May 28, 2024
1 parent fa480a1 commit c777db7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@ Session Pool comes with the following assumptions:

For more details, see [SessionPoolExample.py](example/SessionPoolExample.py).

## Example: Server-Side evaluated parameters
## Example: Server-Side Evaluated Parameters

To enable parameterize the query, see this example:

> Note not all tokes of a query could be paramterized, you could verify it with iPython quickly.
To enable parameterization of the query, refer to the following example:

> Note: Not all tokens of a query can be parameterized. You can quickly verify which ones can be with iPython.
```python
params = {
"p1": 3,
Expand All @@ -145,6 +144,9 @@ resp = client.execute_parameter(
)
```

For further information, consult [Params.py](example/Params.py).


## Example: Extracting Edge and Vertex Lists from Query Results

For graph visualization purposes, the following code snippet demonstrates how to effortlessly extract lists of edges and vertices from any query result by utilizing the `ResultSet.dict_for_vis()` method.
Expand Down Expand Up @@ -232,6 +234,23 @@ The dict/JSON structure with `dict_for_vis()` is as follows:

</details>

## Example: Retrieve Primitive Typed Results

The executed result is typed as `ResultSet`, and you can inspect its structure using `dir()`.

For each data cell in the `ResultSet`, you can use `.cast()` to retrieve raw wrapped data (with sugar) such as a Vertex (Node), Edge (Relationship), Path, Value (Int, Float, etc.). Alternatively, you can use `.cast_primitive()` to obtain values in primitive types like dict, int, or float, depending on your needs.

For more details, refer to [FromResp.py](example/FromResp.py).

Additionally, `ResultSet.as_primitive()` provides a convenient method to convert the result set into a list of dictionaries (similar to JSONL format) containing primitive values for each row.

```python
result = session.execute('<your query>')

result_dict = result.as_primitive()
print(result_dict)
```

## Example: Fetching Query Results into a Pandas DataFrame

> For `nebula3-python>=3.6.0`:
Expand Down
2 changes: 1 addition & 1 deletion nebula3/gclient/net/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _build_byte_param(params: dict) -> dict:
for k, v in params.items():
if isinstance(v, Value):
byte_params[k] = v
elif type(v).startswith("nebula3.common.ttypes"):
elif str(type(v)).startswith("nebula3.common.ttypes"):
byte_params[k] = v
elif isinstance(v, list):
byte_list = []
Expand Down

0 comments on commit c777db7

Please sign in to comment.