etl_lib.task.GDSTask module

class GDSTask(context, func)[source]

Bases: Task

__init__(context, func)[source]

Function that uses the gds client to perform tasks. See the following example:

def gds_fun(etl_context):

gds = etl_context.neo4j.gds gds.graph.drop(“neo4j-offices”, failIfMissing=False) g_office, project_result = gds.graph.project(“neo4j-offices”, “City”, “FLY_TO”) mutate_result = gds.pageRank.write(g_office, tolerance=0.5, writeProperty=”rank”) return TaskReturn(success=True, summery=transform_dict(mutate_result.to_dict()))

Notes: Do NOT use etl_context.neo4j.gds with a context manager. The GDS client closes the underlying

connection when exiting the context.

Parameters:
  • context – The ETLContext to use. Provides the gds client to the func via etl_context.neo4j.gds()

  • func – a function that expects a param etl_context and returns a TaskReturn object.

run_internal(**kwargs)[source]

Place to provide the logic to be performed.

This base class provides all the housekeeping and reporting, so that implementation must/should not need to care about them. Exceptions should not be captured by implementations. They are handled by this base class.

Parameters:

kwargs – will be passed to run_internal

Return type:

TaskReturn

Returns:

An instance of TaskReturn.

transform_dict(input_dict)[source]

Recursively transforms the input dictionary by converting any dictionary or list values to string representations.

Helpful to transform a gds call return into a storable representation param: input_dict (dict): The input dictionary with values that can be of any type.

Returns:

A new dictionary with transformed values.

Return type:

dict