OPG4Py Pgql¶
Python API for the PGQL-on-RDBMS client
- class opg4py.pgql.PgqlConnection(java_pgql_connection)¶
Bases:
object
Wrapper class for oracle.pg.rdbms.pgql.PgqlConnection
- close()¶
Free the resources of the internal JDBC connection.
- create_statement()¶
Creates a new PgqlStatement object, which is used to execute PGQL queries
- Returns
a new PgqlStatement object that can be used to perform PGQL queries
- static get_connection(java_sql_connection)¶
Factory method to get PgqlConnection instance.
- Parameters
java_sql_connection – a JDBC connection
- Returns
a PgqlConnection instance
- get_graph()¶
Get the graph name on which PGQL queries will be executed for this connection.
- Returns
the graph name for this connection
- get_jdbc_connection()¶
Get the JDBC connection that is used to execute PGQL queries
- Returns
the connection
- get_schema()¶
Get the schema name that will be used to execute PGQL queries with this connection. If the schema has not been set, the schema from JDBC connection is returned.
- Returns
the schema set for this connection
- Throws:
PgqlToSqlException - if a database access error occurs or this method is called on a closed connection
- prepare_statement(pgql)¶
Creates a new PgqlPreparedStatement object, which represents a pre-compiled PGQL statement.
- Parameters
pgql – the PGQL query to compile
- Returns
a new PgqlPreparedStatement object that can be used to efficiently execute the same query multiple times
- set_graph(graph)¶
Sets the graph name on which PGQL queries will be executed for this connection.
- Parameters
graph – the name of the graph
- set_schema(schema)¶
Sets the schema name that will be used to execute PGQL queries with this connection.
- Parameters
schema – the name of the schema
- class opg4py.pgql.PgqlPreparedStatement(java_pgql_prepared_statement)¶
Bases:
opg4py.pgql._pgql_statement.PgqlStatement
Wrapper class for oracle.pg.rdbms.pgql.PgqlPreparedStatement
- execute(parallel=0, dynamic_sampling=2, match_options=None, options=None)¶
Executes a PGQL Query, Modify or Create/Drop operation on this instance’s property graph.
Supported query options (matchOptions) are the same as those for executeQuery.
Supported modify options are:
STREAMING=T Use result sets instead of temporary tables to perform the update.
AUTO_COMMIT=F Do not commit after performing the modify operation.
DELETE_CASCADE=F Do not delete incoming/outgoing edges when deleting a vertex.
- Parameters
parallel – the degree of parallelism to use for query and update execution
dynamic_sampling – the value for dynamic sampling
match_options – additional options used to influence query translation and execution
options – additional options used to influence modify translation and execution
- Returns
True if the provided PGQL query is a select, false for other statements
- Throws:
PgqlToSqlException - if a server-side error occurs during translation or SQL execution oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- execute_query(timeout=0, parallel=0, dynamic_sampling=2, max_results=- 1, options=None)¶
Translates this instance’s PGQL statement into a SQL statement and executes the SQL against this instance’s property graph.
Supported query options are:
USE_RW=F Use CONNECT BY instead of recursive WITH for unbounded path traversals.
MAX_PATH_LEN=n Traverse at most n hops when evaluating unbounded path traversals.
EDGE_SET_PARTIAL=T Fetch properties for each start and end vertex found when reading edges from the query result.
- Parameters
timeout – the number of seconds for query execution to finish
parallel – the degree of parallelism to use for query execution
dynamic_sampling – the value for dynamic sampling
max_results – the maximum number of rows returned
options – additional options used to influence query translation and execution
- Returns
a PgqlResultSet object with the result of the provided PGQL query
- Throws:
PgqlToSqlException - if a server-side error occurs during translation or SQL execution oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- set_array(param_index, value)¶
Sets the designated parameter to the given Java List value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_boolean(param_index, value)¶
Sets the designated parameter to the given Java boolean value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_double(param_index, value)¶
Sets the designated parameter to the given Java double value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_float(param_index, value)¶
Sets the designated parameter to the given Java float value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_int(param_index, value)¶
Sets the designated parameter to the given Java int value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_long(param_index, value)¶
Sets the designated parameter to the given Java long value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_string(param_index, value)¶
Sets the designated parameter to the given Java String value.
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- set_timestamp(param_index, value)¶
Sets the designated parameter to the given Java Timestamp value.
Timestamp values are assumed to be in Coordinated Universal Time (UTC).
- Parameters
param_index – the first parameter is 1, the second is 2, …
- Param
value: the parameter value
- class opg4py.pgql.PgqlResultSet(java_pgql_result_set)¶
Bases:
object
Wrapper class for oracle.pg.rdbms.pgql.PgqlResultSet
- 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 – 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
- after_last()¶
Place the cursor after the last row
- before_first()¶
Set the cursor before the first row
- close()¶
Free resources on the server taken up by this result_set object.
- 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
- get(element)¶
Get the value of the designated element by element index or name
- Parameters
element – Integer or string representing index or name
- Returns
Content of cell
- get_boolean(element)¶
Get the value of the designated element by element index or name as a Boolean
- Parameters
element – Integer or String representing index or name
- Returns
Boolean
- get_date(element)¶
Get the value of the designated element by element index or name as a datetime Date
- Parameters
element – Integer or String representing index or name
- Returns
datetime.date
- get_float(element)¶
Get the value of the designated element by element index or name as a Float
- Parameters
element – Integer or String representing index or name
- Returns
Float
- get_integer(element)¶
Get the value of the designated element by element index or name as an Integer
- Parameters
element – Integer or String representing index or name
- Returns
Integer
- get_list(element)¶
Get the value of the designated element by element index or name as a List
- Parameters
element – Integer or String representing index or name
- Returns
List
- get_string(element)¶
Get the value of the designated element by element index or name as a String
- Parameters
element – Integer or String representing index or name
- Returns
String
- get_time(element)¶
Get the value of the designated element by element index or name as a datetime Time
- Parameters
element – Integer or String representing index or name
- Returns
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 – Integer or String representing index or name
- Returns
datetime.time
- get_timestamp(element)¶
Get the value of the designated element by element index or name as a Datetime
- Parameters
element – Integer or String representing index or name
- Returns
datetime.datetime
- get_timestamp_with_timezone(element)¶
Get the value of the designated element by element index or name as a Datetime that includes timezone
- Parameters
element – Integer or String representing index or name
- Returns
datetime.datetime
- get_value_type(element)¶
Get the type of value of the designated element by element index or name as an Integer
- Parameters
element – Integer or String representing index or name
- Returns
Integer
- get_vertex_labels(element)¶
Get the value of the designated element by element index or name as a list of labels
- Parameters
element – Integer or String representing index or name
- Returns
list
- last()¶
Move the cursor to the last 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
- 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
- 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
- print(file=None, num_results=1000, start=0)¶
Print the result set.
- Parameters
file – File to which results are printed (default is
sys.stdout
)num_results – Number of results to be printed
start – Index of the first result to be printed
- 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 – 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
- class opg4py.pgql.PgqlSqlQueryTrans(java_pgql_sql_query_trans)¶
Bases:
opg4py.pgql._pgql_sql_trans.PgqlSqlTrans
Wrapper class for oracle.pg.rdbms.pgql.PgqlSqlQueryTrans
- get_return_types()¶
Get an array of column descriptors for the result columns in the query result.
- Returns
result column descriptions
- get_sql_bv_list()¶
Get a list of Bind Values to be used with this SQL translation. The first element in the list should set at position 1 in a JDBC PreparedStatement created from this SQL translation.
- Returns
the list of bind values for this query translation
- get_sql_translation()¶
Get the SQL string for the PGQL to SQL translation.
- Returns
the SQL query string
- class opg4py.pgql.PgqlSqlTrans(java_pgql_sql_trans)¶
Bases:
object
Wrapper class for oracle.pg.rdbms.pgql.PgqlSqlTrans
- get_translation_type()¶
Get the type for the PGQL to SQL translation.
- Returns
a PgqlSqlTrans.TranslationType object with the SQL translation type
- class opg4py.pgql.PgqlStatement(java_pgql_statement)¶
Bases:
object
Wrapper class for oracle.pg.rdbms.pgql.PgqlStatement
- cancel()¶
Allows to cancel currently running execute operation. Note that cancel does not rollback already executed modifications.
Throws: oracle.pgql.lang.PgqlException - When an error occurs while canceling current operation.
- close()¶
Releases this PgqlStatment’s database and JDBC resources.
Closing this PgqlStatement will close all PgqlResultSets that were created from it.
Throws: oracle.pgql.lang.PgqlException
- execute(pgql, parallel=0, dynamic_sampling=2, match_options=None, options=None)¶
Executes a PGQL Query, Modify or Create/Drop operation on this instance’s property graph.
Supported query options (matchOptions) are the same as those for executeQuery.
Supported modify options are:
STREAMING=T Use result sets instead of temporary tables to perform the update.
AUTO_COMMIT=F Do not commit after performing the modify operation.
DELETE_CASCADE=F Do not delete incoming/outgoing edges when deleting a vertex.
- Parameters
pgql – the PGQL modify to execute
parallel – the degree of parallelism to use for query and update execution
dynamic_sampling – the value for dynamic sampling
match_options – additional options used to influence query translation and execution
options – additional options used to influence modify translation and execution
- Returns
True if the provided PGQL query is a select, false for other statements
- Throws:
PgqlToSqlException - if a server-side error occurs during translation or SQL execution oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- execute_query(pgql, timeout=0, parallel=0, dynamic_sampling=2, max_results=- 1, options=None)¶
Translates this instance’s PGQL statement into a SQL statement and executes the SQL against this instance’s property graph.
Supported query options are:
USE_RW=F Use CONNECT BY instead of recursive WITH for unbounded path traversals.
MAX_PATH_LEN=n Traverse at most n hops when evaluating unbounded path traversals.
EDGE_SET_PARTIAL=T Fetch properties for each start and end vertex found when reading edges from the query result.
- Parameters
pgql – the PGQL query to execute
timeout – the number of seconds for query execution to finish
parallel – the degree of parallelism to use for query execution
dynamic_sampling – the value for dynamic sampling
max_results – the maximum number of rows returned
options – additional options used to influence query translation and execution
- Returns
a PgqlResultSet object with the result of the provided PGQL query
- Throws:
PgqlToSqlException - if a server-side error occurs during translation or SQL execution oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- get_batch_size()¶
Get the number of commands that should be batched when executing updates :return: the update batch size
- get_fetch_size()¶
Get the the number of rows that should be fetched from the database when more rows are needed for a query result. :return: the query fetch size
- get_modify_count()¶
Get the number of rows that were modified by last execute operation :return: The number of rows modified
- get_result_set()¶
Retrieve the current result as a PgqlResultSet object.
This method should be called only once per result.
- Returns
Current result as a ResultSet object or null if the query is not a SELECT query
- set_batch_size(batch_size)¶
Set the number of commands that should be batched when executing updates :param batch_size: the update batch size
- set_fetch_size(fetch_size)¶
Set the the number of rows that should be fetched from the database when more rows are needed for a query result. :param fetch_size: the query fetch size
- translate_query(pgql, parallel=0, dynamic_sampling=2, max_results=- 1, options=None)¶
Translates this instance’s PGQL statement into a SQL statement.
Supported query options are:
USE_RW=F Use CONNECT BY instead of recursive WITH for unbounded path traversals.
MAX_PATH_LEN=n Traverse at most n hops when evaluating unbounded path traversals.
EDGE_SET_PARTIAL=T Fetch properties for each start and end vertex found when reading edges from the query result.
- Parameters
pgql – the PGQL query to translate
parallel – the degree of parallelism to use for query execution
dynamic_sampling – the value for dynamic sampling
max_results – the maximum number of rows returned
options – additional options used to influence query translation
- Returns
a PgqlSqlTrans object with the SQL translation and column metadata for the provided PGQL query
- Throws:
PgqlToSqlException - if a server-side error occurs during translation oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- translate_statement(pgql, parallel=0, dynamic_sampling=2, max_results=- 1, match_options=None, options=None)¶
Translates the given PGQL statement into a series of SQL statements.
- Parameters
pgql – the PGQL statement to translate
parallel – the degree of parallelism to use for query execution
dynamic_sampling – the value for dynamic sampling
max_results – the maximum number of rows returned
match_options – additional options used to influence query translation and execution
options – additional options used to influence DDL/DML translation and execution
- Returns
the SQL statements and metadata necessary to execute the provided SQL statement
- Throws:
PgqlToSqlException - if a server-side error occurs during translation oracle.pgql.lang.PgqlException - if a server-side error occurs or this method is called on a closed Statement
- opg4py.pgql.get_connection(usr, pwd, jdbc_url)¶
Get a DB connection.
- Parameters
usr – the DB user
pwd – the DB password
jdbc_url – the DB jdbc url
- Returns
A PgqlConnection