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
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|