The Low-level API is used to manually construct static data flow graphs by creating nodes. These graphs are then submitted to a Driver to generate and execute tasks. This API uses a built-in scheduler and offers more performance optimizations and richer configuration options compared to the High-level API, but it only supports one-time execution.
Key components include:
Context: Manages the environment for node creation.DataSourceNode: Represents the source of data.DataSetPartitionNode: Handles partitioning of datasets.SqlEngineNode: Executes SQL operations.LogicalPlan: Encapsulates the constructed graph.Driver: Executes the LogicalPlan.
from smallpond.logical.dataset import ParquetDataSet
from smallpond.logical.node import Context, DataSourceNode, DataSetPartitionNode, SqlEngineNode, LogicalPlan
from smallpond.execution.driver import Driver
from typing import List
def my_pipeline(input_paths: List[str], npartitions: int):
ctx = Context()
dataset = ParquetDataSet(input_paths)
node = DataSourceNode(ctx, dataset)
node = DataSetPartitionNode(ctx, (node,), npartitions=npartitions)
node = SqlEngineNode(ctx, (node,), "SELECT * FROM {0}")
return LogicalPlan(ctx, node)
if __name__ == "__main__":
driver = Driver()
driver.add_argument("-i", "--input_paths", nargs="+")
driver.add_argument("-n", "--npartitions", type=int, default=10)
plan = my_pipeline(**driver.get_arguments())
driver.run(plan)