Spectre Flow Code Examples
This topic presents examples and code snippets of Spectre Flow scripts.
The following example shows a rotate process in action. This rotate process uses automatic rows to transform 12 revenue columns (one for each month) into 12 rows using an automatic range. To learn more about the Spectre Flow object, see Spectre Flow Rotate Process Object
flow {
text-input "Text-1" {
file "/data/rotate-test.txt"
}
rotate "Rotate-1" {
source "Text-1"
dimension-column "Month"
value-column "Revenue"
auto-rows from-inclusive="Rev01-2024"to-inclusive="Rev12-2024"
}
text-output "Text-2" {
source "Calc-1"
file "rotate-test.txt"
}
}
For an input of:
The rotated output is:
The following example shows a rotate process in action. This rotate process uses manual column entry to determine how to transform 12 revenue columns (one for each month) into 12 rows. To learn more about the Spectre Flow object, see Spectre Flow Rotate Process Object
flow {
text-input "Text-1" {
file "/data/rotate-test.txt"
}
rotate "Rotate-1" {
source "Text-1"
dimension-column "Month"
value-column "Revenue"
row-out "01-2024" "Rev01-2024"
row-out "02-2024" "Rev02-2024"
row-out "03-2024" "Rev03-2024"
row-out "04-2024" "Rev04-2024"
row-out "05-2024" "Rev05-2024"
row-out "06-2024" "Rev06-2024"
row-out "07-2024" "Rev07-2024"
row-out "08-2024" "Rev08-2024"
row-out "09-2024" "Rev09-2024"
row-out "10-2024" "Rev10-2024"
row-out "11-2024" "Rev11-2024"
row-out "12-2024" "Rev12-2024"
}
text-output "Text-2" {
source "Calc-1"
file "rotated-manual.txt"
}
}
For an input of:
The rotated output is:
The following example shows an unrotate process in action. For a data set with a year, an award type, and a column for first and last names, the unrotate column condenses the award type column and creates columns for the first and last names of actors and actresses. This effectively halves the number of rows in the output data set.
flow {
text-input "Text-1" {
file "/data/oscar-rotated.txt"
column "Year" {
type "string"
}
column "Award" {
type "string"
}
column "First Name" {
type "string"
}
column "Last Name" {
type "string"
}
}
unrotate "Unrotate-1" {
source "Text-1"
key "Award"
dimension "Year"
value "First Name"
value "Last Name"
out-name "{key} {value}"
}
cbase-output "cBase-1" {
source "Unrotate-1"
file "unrotated.cbase"
}
}
For an input of:
The unrotated output is:
A merge process is ideal for situations where you have an existing data set and an updated version of that data set that may contain new rows or rows that match existing rows but have updated data. In this merge example, the new data set has a new row as well as updated existing rows.
flow {
text-input "Text-1" {
file "/data/merge-old.txt"
delimiter "\t"
}
text-input "Text-2" {
file "/data/merge-new.txt"
delimiter "\t"
}
merge "Merge-1" {
source "Text-1" "Text-2"
key "Class ID"
}
text-output "Text-3" {
source "Merge-1"
file "/data/merged-revenue.txt"
}
}
Given an "old data" input of:
Given a "new data" input of:
The resulting merged data output is: