Data Pipeline Patterns
Batch Transform
A batch transform applies the same cleanup rule to each input value.
batch transform
The loop applies one transformation to every value in the batch.
scalar output
Joining the cleaned values keeps the replay output compact and readable.
Batch Transform
BatchTransform.java
Replay: real traced execution (multi-file project)
public class BatchTransform {
static int clamp(int value) {
if (value < 0) {
return 0;
}
return value;
}
public static void main(String[] args) {
int bonus = 1;
int[] rawScores = {7, -1, 10};
StringBuilder cleaned = new StringBuilder();
for (int i = 0; i < rawScores.length; i++) {
int value = clamp(rawScores[i] + bonus);
if (i > 0) {
cleaned.append(",");
}
cleaned.append(value);
}
System.out.println("scores=" + cleaned);
}
}
public class BatchTransform {
static int clamp(int value) {
if (value < 0) {
return 0;
}
return value;
}
public static void main(String[] args) {
int bonus = -2;
int[] rawScores = {7, -1, 10};
StringBuilder cleaned = new StringBuilder();
for (int i = 0; i < rawScores.length; i++) {
int value = clamp(rawScores[i] + bonus);
if (i > 0) {
cleaned.append(",");
}
cleaned.append(value);
}
System.out.println("scores=" + cleaned);
}
}
public class BatchTransform {
static int clamp(int value) {
if (value < 0) {
return 0;
}
return value;
}
public static void main(String[] args) {
int bonus = 4;
int[] rawScores = {7, -1, 10};
StringBuilder cleaned = new StringBuilder();
for (int i = 0; i < rawScores.length; i++) {
int value = clamp(rawScores[i] + bonus);
if (i > 0) {
cleaned.append(",");
}
cleaned.append(value);
}
System.out.println("scores=" + cleaned);
}
}
bonus ← 1, cleaned ← (empty)
9public static void main(String[] args) {10 int bonus→ 1 = 1; //@bonus=-2, 411 int[] rawScores = {7, -1, 10};12 StringBuilder cleaned→ (empty) = new StringBuilder();for (int i = 0; i < rawScores.length; i++)
pass 1 of 314for (int i0 = 0; i < rawScores.length3; i++) {15 int value = clamp(rawScores[i]7 + bonus1);16 if (i > 0) {All 3 passes — pass 1 is the card above pass irawScores[i]1 0 7 2 1 -1 3 2 10 static int clamp(int value)
pass 1 of 31public class BatchTransform {2 static int clamp(int value8) {3 if (value < 0) {4 return 0;5 }6 return value8;7 }All 3 passes — pass 1 is the card above pass value1 8 2 0 3 11 value ← 8
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 8 = clamp(rawScores[i]7 + bonus1);16 if (i > 0) {17 cleaned.append(",");18 }19 cleaned.append(value8);20}values this step0ivalue ← 0
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 0 = clamp(rawScores[i]-1 + bonus1);16 if (i > 0) {values this step1iif (i > 0)
pass 1 of 215int value = clamp(rawScores[i] + bonus);16if (i1 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value0);20}value ← 11
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 11 = clamp(rawScores[i]10 + bonus1);16 if (i > 0) {values this step2iif (i > 0)
pass 2 of 215int value = clamp(rawScores[i] + bonus);16if (i2 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value11);20}System.out.println("scores=" + cleaned);
22 System.out.println("scores=" + cleaned8,0,11);23}outputscores=8,0,11
bonus ← -2, cleaned ← (empty)
9public static void main(String[] args) {10 int bonus→ -2 = -2;11 int[] rawScores = {7, -1, 10};12 StringBuilder cleaned→ (empty) = new StringBuilder();for (int i = 0; i < rawScores.length; i++)
pass 1 of 314for (int i0 = 0; i < rawScores.length3; i++) {15 int value = clamp(rawScores[i]7 + bonus-2);16 if (i > 0) {All 3 passes — pass 1 is the card above pass irawScores[i]value1 0 7 — 2 1 -1 -3 3 2 10 — static int clamp(int value)
pass 1 of 31public class BatchTransform {2 static int clamp(int value5) {3 if (value < 0) {4 return 0;5 }6 return value5;7 }All 3 passes — pass 1 is the card above pass value1 5 2 -3 3 8 value ← 5
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 5 = clamp(rawScores[i]7 + bonus-2);16 if (i > 0) {17 cleaned.append(",");18 }19 cleaned.append(value5);20}values this step0iif (value < 0)
2static int clamp(int value) {3 if (value-3 < 0) {4 return 0;5 }value ← 0
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 0 = clamp(rawScores[i]-1 + bonus-2);16 if (i > 0) {values this step1iif (i > 0)
pass 1 of 215int value = clamp(rawScores[i] + bonus);16if (i1 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value0);20}value ← 8
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 8 = clamp(rawScores[i]10 + bonus-2);16 if (i > 0) {values this step2iif (i > 0)
pass 2 of 215int value = clamp(rawScores[i] + bonus);16if (i2 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value8);20}System.out.println("scores=" + cleaned);
22 System.out.println("scores=" + cleaned5,0,8);23}outputscores=5,0,8
bonus ← 4, cleaned ← (empty)
9public static void main(String[] args) {10 int bonus→ 4 = 4;11 int[] rawScores = {7, -1, 10};12 StringBuilder cleaned→ (empty) = new StringBuilder();for (int i = 0; i < rawScores.length; i++)
pass 1 of 314for (int i0 = 0; i < rawScores.length3; i++) {15 int value = clamp(rawScores[i]7 + bonus4);16 if (i > 0) {All 3 passes — pass 1 is the card above pass irawScores[i]1 0 7 2 1 -1 3 2 10 static int clamp(int value)
pass 1 of 31public class BatchTransform {2 static int clamp(int value11) {3 if (value < 0) {4 return 0;5 }6 return value11;7 }All 3 passes — pass 1 is the card above pass value1 11 2 3 3 14 value ← 11
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 11 = clamp(rawScores[i]7 + bonus4);16 if (i > 0) {17 cleaned.append(",");18 }19 cleaned.append(value11);20}values this step0ivalue ← 3
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 3 = clamp(rawScores[i]-1 + bonus4);16 if (i > 0) {values this step1iif (i > 0)
pass 1 of 215int value = clamp(rawScores[i] + bonus);16if (i1 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value3);20}value ← 14
14for (int i = 0; i < rawScores.length; i++) {15 int value→ 14 = clamp(rawScores[i]10 + bonus4);16 if (i > 0) {values this step2iif (i > 0)
pass 2 of 215int value = clamp(rawScores[i] + bonus);16if (i2 > 0) {17 cleaned.append(",");18}cleaned.append(value);
18 }19 cleaned.append(value14);20}System.out.println("scores=" + cleaned);
22 System.out.println("scores=" + cleaned11,3,14);23}outputscores=11,3,14