********************** User-Defined Functions ********************** This tutorial shows how to add user-defined functions (UDF) to PGX and how to use them in PGQL and Green-Marl. The examples will focus on Java and JavaScript UDFs. Using UDFs in PGX ----------------- After configuring the UDFs, they can now be used in PGX and the next two sections will show how they can be utilized in `PGQL` and `Green-Marl` (not available in all releases). First we start PGX in local mode: .. code-block:: python :linenos: session = pypgx.get_session(session_name="my-session") Next, let us load a graph into memory that we can use in the subsequent examples. .. code-block:: python :linenos: connections_graph = session.read_graph_with_properties( "examples/graphs/connections.csv.json" ) UDFs in PGQL ~~~~~~~~~~~~ PGQL can call UDFs directly using the ``namespace`` and ``function_name``. Note that the namespace is required, otherwise the function will be interpreted as a built-in function. UDFs can be used in any part of the PGQL query, e.g. the following query utilizes them in the `SELECT` clause. .. code-block:: python :linenos: result_set = connections_graph.query_pgql( """ SELECT DISTINCT udfTutorial.format(v.name, v.country), udfTutorial.toHexString(e.weight) FROM MATCH (v) -[e]-> (u) """ )