Node¶
- class sycamore.plan_nodes.Node(children: list[Node | None], materialize: dict = {}, parallelism: int | None = None, **resource_args)[source]¶
A Node is the abstract base unit of a Sycamore Transform, which allows DocSets to transform themselves into end results. Sycamore processes this as a directed tree graph, which allows transforms to be linked to each other and then implemented
- finalize() None[source]¶
Override this method to run something at the end of execution after all documents have been returned.
- get_plan_nodes(node_type: type[_NODE_T], *, order: NodeTraverseOrder = NodeTraverseOrder.AFTER) list[_NODE_T][source]¶
Returns a list of all nodes of a certain type in the plan.
- Parameters:
node_type -- The type of node to return. e.g. set to Materialize to get all the Materialize nodes.
order -- Order to do the traversal. AFTER = fifo, BEFORE = lifo
- prepare() Callable | None[source]¶
Override this method to run something at the beginning of execution after rules have been applied. The entire tree will be traversed in before mode and then any returned callables will be called in the order they were returned. Each callable can return another callable.
- traverse(obj: NodeTraverse | None = None, before: Callable[[Node], Node] | None = None, visit: Callable[[Node], None] | None = None, after: Callable[[Node], Node] | None = None) Node[source]¶
Traverse the node tree, functions will be converted to an object. See NodeTraverse for the semantics.
- class sycamore.plan_nodes.NodeTraverse(before: Callable[[Node], Node] | None = None, visit: Callable[[Node], None] | None = None, after: Callable[[Node], Node] | None = None)[source]¶
NodeTraverse allows for complicated traversals
For simple use cases, call node.traverse({before,visit,after}=fn)
before is called before traversing children.
after is called after traversing children.
visit is called over each node in an unspecified order, and is easier to use since the function returns nothing.
once is called one time at the very start, and enables multi-pass transforms.
- enum sycamore.plan_nodes.NodeTraverseOrder(value)[source]¶
Valid values are as follows:
- BEFORE = <NodeTraverseOrder.BEFORE: 1>¶
- AFTER = <NodeTraverseOrder.AFTER: 2>¶
- sycamore.plan_nodes.print_plan(node: ~sycamore.plan_nodes.Node, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None[source]¶
Utility function for printing plans.
Prints the node and all its children. Indentation is used to indicate the parent-child relation, e.g.
- RootNode
- InternalNode1
LeafNode1
- InternalNode2
LeafNode2