-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.scl
More file actions
72 lines (57 loc) · 3.33 KB
/
example.scl
File metadata and controls
72 lines (57 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This is a comment, it's ignored when running SCL
# If you get stuck when using the Playground, use Ctrl + Space for a hint
# Steps in SCL start with a dash '-' or a pipeline '|'. Just like bullet
# points in a list or arrays in YAML:
- <sum> = 1 + 1
- Print <sum>
# Variables in SCL are defined using angle brackets <>
# This is a variable, a data placeholder:
- <greeting> = 'hello'
# Steps are 'units of work' or actions in an application
# This is a step that will make the value of <greeting> upper case
- <greeting> = ChangeCase of: <greeting> to: 'Upper'
# Here is a step that will print the value to the 'Output' tab:
- Print <greeting>
# And this is a step that will log the value to the 'Log' tab.
# Logging in Sequence is highly configurable, instead of the 'Log' tab
# it could go to a file, a database, an Elastic instance, etc.
- Log <greeting>
# Data in SCL is represented as Entities which can be defined using round brackets ().
# An entity is a collection of property names and values, or key-value pairs. The
# property name precedes a colon ':' and the property value follows - name: 'value'.
- <entity> = (name: 'value1' key: 'value2')
# To get a property value from an entity, use the EntityGetValue step:
- <value> = EntityGetValue Entity: <entity> Property: 'name'
- Print <value> # will print 'value1'
# EntityGetValue also has a shorthand notation - the period '.'
- Print <entity>.name
# Lists (or Arrays as we call them) in SCL can be defined using a comma, or
# square brackets []. Here is a list of entities:
- <list> = (a: 1 b: 'two'), (a: 3 b: 'four'), (a: 5 c: 'six')
# To access items in a list, use ArrayElementAtIndex step, or the square bracket
# shorthand []:
- Print ArrayElementAtIndex <list> 2 # prints (a: 3 b: 'four')
- Print <list>[2] # does exactly the same and prints (a: 3 b: 'four')
# Many steps are available to work with entities and arrays.
- Print EntityGetProperties <entity> # will print out a list of properties: ['name', 'key']
- Print ArrayLength <list> # will print out 3
# There are also many steps available to work with text/strings. An example:
- Print StringReplace In: 'A long sentence' Find: 'long' Replace: 'short'
# The pipe character | is used to chain steps into sequences. The output of the
# previous step is used as the input for the next. Here is a sequence of steps
# that takes the list of entites, converts into JSON and writes it to a file:
- <list> | ToJsonArray | FileWrite Path: 'my-list.json'
# Sequence is designed to be extensible via connectors. The playground has the
# File System and Structured Data connectors installed (many others are available).
# The Strutured Data connector has steps to convert entities To/From various data
# formats. Here is a sequence of steps that reads the json file, converts it to
# entities, maps the properties to different names, and export to a CSV file:
- <myfile> = 'my-list.json'
- <mynewfile> = StringReplace In: <myfile> Find: 'json' Replace: 'csv'
- FileRead <myfile> | FromJsonArray | EntityMapProperties To: (
'ColA': 'a' # Property 'a' will be renamed to 'ColA'
'ColB': [ 'b', 'c' ] # Both 'b' and 'c' get renamed to 'ColB'
) | ToCSV | FileWrite <mynewfile>
# Steps and parameters in SCL can have one or more aliases. Above, 'FileRead' is
# used, but here is the same step, but using its alias 'ReadFromFile':
- ReadFromFile <mynewfile> | Print