Node
flypipe.node.node
Nodes are the fundamental building block of Flypipe. Simply apply the node function as a decorator to a transformation function in order to declare the transformation as a Flypipe node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Type of the node transformation "pandas", "pandas_on_spark", "pyspark", "spark_sql" |
required |
description
|
(str, optional)
|
Description of the node. Defaults to |
required |
group
|
(str, optional)
|
Group the node falls under, nodes in the same group are clustered together in the Catalog UI. Defaults to |
required |
tags
|
(List[str], optional)
|
List of tags for the node. Defaults to |
required |
dependencies
|
(List[Node], optional)
|
List of other dependent nodes. Defaults to |
required |
output
|
(Schema, optional)
|
Defines the output schema of the node. Defaults to |
required |
spark_context
|
(bool, optional)
|
True, returns spark context as argument to the function. Defaults to |
required |
Examples
# Syntax
@node(
type="pyspark", "pandas_on_spark" or "pandas",
description="this is a description of what this node does",
tags=["a", "list", "of", "tags"],
dependencies=[other_node_1, other_node_2, ...],
output=Schema(
Column("col_name", String(), "a description of the column"),
),
spark_context = True or False
)
def your_function_name(other_node_1, other_node_2, ...):
# YOUR TRANSFORMATION LOGIC HERE
# use pandas syntax if type is `pandas` or `pandas_on_spark`
# use PySpark syntax if type is `pyspark`
return dataframe
# Node without dependency
from flypipe.node import node
from flypipe.schema import Schema, Column
from flypipe.schema.types import String
import pandas as pd
@node(
type="pandas",
description="Only outputs a pandas dataframe",
output=Schema(
t0.output.get("fruit"),
Column("flavour", String(), "fruit flavour")
)
)
def t1(df):
return pd.DataFrame({"fruit": ["mango"], "flavour": ["sweet"]})
# Node with dependency
from flypipe.node import node
from flypipe.schema import Schema, Column
from flypipe.schema.types import String
import pandas as pd
@node(
type="pandas",
description="Only outputs a pandas dataframe",
dependencies = [
t0.select("fruit").alias("df")
],
output=Schema(
t0.output.get("fruit"),
Column("flavour", String(), "fruit flavour")
)
)
def t1(df):
categories = {'mango': 'sweet', 'lemon': 'citric'}
df['flavour'] = df['fruit']
df = df.replace({'flavour': categories})
return df
Source code in flypipe/node.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |