6. Using PGQL results¶
Retrieving results after executing a PGQL query can be done using the following methods of the PgqlResultSet class.
Please note that this functionality is different from the one included in OPG4Py package. For more details look into the PGQL documentation.
- class pypgx.api.PgqlResultSet(graph, java_pgql_result_set)
Result set of a pattern matching query.
Note: retrieving results from the server is not thread-safe.
- Parameters
graph (Optional[PgxGraph]) –
- Return type
None
- absolute(row)
Move the cursor to the given row number in this ResultSet object.
If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set. The first row is 1, so absolute(1) moves the cursor to the first row.
If the row number is negative, the cursor moves to the given row number with respect to the end of the result set. So absolute(-1) moves the cursor to the last row.
- Parameters
row (int) – Row to move to
- Returns
True if the cursor is moved to a position in the ResultSet object; False if the cursor is moved before the first or after the last row
- Return type
bool
- after_last()
Place the cursor after the last row
- Return type
None
- before_first()
Set the cursor before the first row
- Return type
None
- close()
Free resources on the server taken up by this frame.
- Return type
None
- first()
Move the cursor to the first row in the result set
- Returns
True if the cursor points to a valid row; False if the result set does not have any results
- Return type
bool
- get(element)
Get the value of the designated element by element index or name
- Parameters
element (Union[str, int]) – Integer or string representing index or name
- Returns
Content of cell
- Return type
Any
- get_boolean(element)
Get the value of the designated element by element index or name as a Boolean
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Boolean
- Return type
bool
- get_date(element)
Get the value of the designated element by element index or name as a datetime Date
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.date
- Return type
datetime.date
- get_double(element)
Get the value of the designated element by element index or name as a Float
This method is for precision, as a Java floats and doubles have different precisions
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Float
- Return type
float
- get_edge(element)
Get the value of the designated element by element index or name as a PgxEdge
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
PgxEdge
- Return type
- get_float(element)
Get the value of the designated element by element index or name as a Float
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Float
- Return type
float
- get_integer(element)
Get the value of the designated element by element index or name as an Integer
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Integer
- Return type
int
- get_legacy_datetime(element)
Get the value of the designated element by element index or name as a Datetime. Works with most time and date type cells. If the date is not specified, default is set to to Jan 1 1970.
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_list(element)
Get the value of the designated element by element index or name as a List
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
List
- Return type
Optional[List[str]]
- get_long(element)
Get the value of the designated element by element index or name as a Long
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Long
- Return type
int
- get_point2d(element)
Get the value of the designated element by element index or name as a 2D tuple
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
(X, Y)
- Return type
Tuple[float, float]
- get_row(row)
Get row from result_set. This method may change result_set cursor.
- Parameters
row (int) – Row index
- Return type
Any
- get_slice(start, stop, step=1)
Get slice from result_set. This method may change result_set cursor.
- Parameters
start (int) – Start index
stop (int) – Stop index
step (int) – Step size
- Return type
List[list]
- get_string(element)
Get the value of the designated element by element index or name as a String
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
String
- Return type
str
- get_time(element)
Get the value of the designated element by element index or name as a datetime Time
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.time
- Return type
datetime.time
- get_time_with_timezone(element)
Get the value of the designated element by element index or name as a datetime Time that includes timezone
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.time
- Return type
datetime.time
- get_timestamp(element)
Get the value of the designated element by element index or name as a Datetime
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_timestamp_with_timezone(element)
Get the value of the designated element by element index or name as a Datetime
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_vertex(element)
Get the value of the designated element by element index or name as a PgxVertex
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
PgxVertex
- Return type
- get_vertex_labels(element)
Get the value of the designated element by element index or name a list of labels
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
list
- Return type
List[str]
- last()
Move the cursor to the first row in the result set
- Returns
True if the cursor points to a valid row; False if the result set does not have any results
- Return type
bool
- next()
Move the cursor forward one row from its current position
- Returns
True if the cursor points to a valid row; False if the new cursor is positioned after the last row
- Return type
bool
- previous()
Move the cursor to the previous row from its current position
- Returns
True if the cursor points to a valid row; False if the new cursor is positioned before the first row
- Return type
bool
- print(file=None, num_results=1000, start=0)
Print the result set.
- Parameters
file (Optional[TextIO]) – File to which results are printed (default is
sys.stdout
)num_results (int) – Number of results to be printed
start (int) – Index of the first result to be printed
- Return type
None
- relative(rows)
Move the cursor a relative number of row with respect to the current position. A negative number will move the cursor backwards.
Note: Calling relative(1) is equal to next() and relative(-1) is equal to previous. Calling relative(0) is possible when the cursor is positioned at a row, not when it is positioned before the first or after the last row. However, relative(0) will not update the position of the cursor.
- Parameters
rows (int) – Relative number of rows to move from current position
- Returns
True if the cursor is moved to a position in the ResultSet object; False if the cursor is moved before the first or after the last row
- Return type
bool
- to_frame()
Copy the content of this result set into a new PgxFrames
- Returns
a new PgxFrame containing the content of the result set
- Return type
- to_pandas()
Convert to pandas DataFrame.
This method may change result_set cursor.
This method requires pandas.
- Returns
PgqlResultSet as a Pandas Dataframe