Skip to content

Add Step DSL (Source/Flow/Merge/Split/Sink) for Spark jobs #313

Closed

Description

@em3s

Background

Workflow DSL (#310) covers job-to-job relationships only. The data flow inside a single Spark job needs its own abstraction. This task implements the Step model for Spark — Source / Flow / Merge / Split / Sink composition, both as a Scala DSL and as inline YAML via StepsRunnerJob. Other job kinds (e.g., bash) are out of scope.

Task

  • Step sealed trait: Source (0→1) / Flow (1→1) / Merge (N→1) / Split (1→M) / Sink (1→0)
  • Type-state Plan DSL: ~>, +, .as, fanOut, port selector for Split
  • Executor: memoization, fanOut cache, Split port memo, plan-time validation
  • StepsRunnerJob for inline YAML chains
  • Built-ins: FileSource, SampleSource, SqlMerge, CacheFlow, FileSink, ShowSink
  • Tests

Done When

  • A Spark job can be expressed in Scala via Source ~> Flow ~> Sink with type-state safety (a chain without a Sink fails to compile).
  • A Spark job can be expressed in YAML via kind: spark, mainClass: StepsRunnerJob, and an inline steps: list.
  • Memoization is verifiable: a shared upstream feeding multiple sinks runs only once within a run.
  • fanOut runs each branch against a cached upstream and unpersists after.
  • A Split step produces M named outputs from one input, addressable via as: {port: label} (YAML) or forked("port") (Scala); the split body runs once per execution.
  • All listed plan-time validations reject invalid graphs before execution.

Notes

Step signatures

Kind Signature In Out
Source read(): DataFrame 0 1
Flow apply(in: DataFrame): DataFrame 1 1
Merge apply(inputs: Seq[(label, DataFrame)]): DataFrame N 1
Split split(in: DataFrame): Map[String, DataFrame] 1 M
Sink write(df: DataFrame): Unit 1 0

A Merge receives labeled inputs, so consumers like SqlMerge use each label as the temp view name. The default label for a single-input chain is "_0". A Split declares output ports (string keys) addressed by downstream via as: {port: label} or forked("port").

Scala DSL

class JoinJob extends Job[JoinCfg] {
  override def plan(cfg: JoinCfg): Plan.Closed = {
    val users  = FileSource("users.parquet").as("u")
    val events = FileSource("events.parquet").as("e")

    (users + events) ~>
      SqlMerge("SELECT u.name, e.kind FROM u JOIN e ON u.id = e.user_id") ~>
      ShowSink()
  }
}
Operator Meaning
~> pipe
+ combine for multi-input Merge
.as("name") label this output (also the SQL view name)
fanOut(...) broadcast: a shared upstream feeds multiple Sink branches with the same data
forked("port") select an output port of a Split

YAML inline — StepsRunnerJob

jobs:
  pi:
    kind: spark
    artifact: "com.kakao.actionbase:pipeline:0.x"
    mainClass: StepsRunnerJob
    args:
      steps:
        - step: SampleSource
          args: { n: 1000000, columns: [x, y] }
        - step: SqlMerge
          args:
            query: "SELECT 4.0*SUM(CASE WHEN x*x+y*y<=1 THEN 1 ELSE 0 END)/COUNT(*) AS pi FROM _0"
        - step: ShowSink
Field Meaning
step class name (short / sub-package / FQN)
args bound to case class fields
as output label. String for Source/Flow/Merge; map {port: label} for Split
inputs upstream labels; empty → previous step (linear chain, label "_0")

Related: #310 (workflow DSL), #311 (initial PR — closed in favor of split).

Activity

  1. added
    enhancement
    on May 10, 2026
  2. changed the title [-]ADR: Step model for Spark jobs[/-] [+]Add Step DSL (Source/Transform/Sink) for Spark jobs[/+] on May 10, 2026
  3. self-assigned this
    on May 13, 2026
  4. em3s commented on May 13, 2026

    @em3s
    ContributorAuthor

    Spec revised: Transform → Flow / Merge / Split

    After implementing the initial Source/Transform/Sink in #314 and dogfooding it on a real ALS i2i workload in #325, two limitations surfaced:

    1. "Transform" was generic relative to its N→1 shape. A 1→1 SQL projection and a JOIN read identically under one name.
    2. N→1 alone can't express multi-output. In Add ALS i2i similarity as the first experimental workload on the Step DSL #325, ALS naturally produces both item and user factors but the spec forced us to ship one or fit twice. Same story for train/val split, model + metrics, etc.

    Resolution: split Transform into Flow (1→1) and Merge (N→1), add Split (1→M) as a sibling. Source/Sink unchanged. N→M decomposes as Merge → Split — each node stays single-sequence; the pairs Source↔Sink and Merge↔Split also cohere semantically (Transform/Splitter didn't).

    Renames

    • Transform trait → Flow + Merge
    • SqlTransform → SqlMerge; CacheTransform → CacheFlow; AlsTransform → AlsFlow; TopKSimilarityTransform → TopKSimilarityFlow
    • New Split trait + future built-ins AlsFactorSplit, RatioSplit

    Plan

    1. Rename PR (Transform → Flow/Merge, class renames).
    2. Split PR (Split trait, Plan.Forked, port selector, YAML as: {port: label}).
    3. Multi-output built-ins + rebase Add ALS i2i similarity as the first experimental workload on the Step DSL #325 onto new names.

    Pre-release — no published API contract, so the rename is safe in-place.

  5. changed the title [-]Add Step DSL (Source/Transform/Sink) for Spark jobs[/-] [+]Add Step DSL (Source/Flow/Merge/Split/Sink) for Spark jobs[/+] on May 13, 2026
  6. em3s commented on May 20, 2026

    @em3s
    ContributorAuthor

    Naming, revisited: keep Flow/Merge/Split, group them under Transform

    Superseding the rename in the previous comment. The arity split itself stands — Flow (1→1) / Merge (N→1) / Split (1→M) remain distinct traits, so both earlier concerns are still met: arity is visible in the type (SqlTransform extends Merge), and multi-output is expressed by Split.

    What changes from the previous plan: instead of making the three siblings of Source/Sink, a sealed parent Transform is added over them, so the type hierarchy and the package layout both read as the classic three-phase pipeline:

    Step
    ├ Source            (0→1)   steps.source
    ├ Transform                 steps.transform
    │   ├ Flow  (1→1)
    │   ├ Merge (N→1)
    │   └ Split (1→M)
    └ Sink              (1→0)   steps.sink
    

    Built-ins follow <function>Transform, with arity carried by the trait they extend:

    Trade-off, stated plainly: a built-in's name no longer encodes its arity (you read SqlTransform, not SqlMerge) — that now lives in the type signature / extends clause. We take that in exchange for the Source→Transform→Sink symmetry and the type↔package mirror.

    Landed in #314; #325 rebases onto these names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions