Expression Input
Expression Output
Your expression must return a tuple matching the targeted index unit data model. For more
information, see Information Intelligence | Collaborative Data Intelligence | Data Perspective Studio | Data Perspective Studio | Appendix - Data Queries | Expression Language | Expression Language Principles.
The Return type object shows the attributes defined for the index unit
Class that you selected as target in the
Destination tab to complete the expression automatically with the
fields required for the expression output.
Note:
The attribute order does not matter. Only attribute names are relevant. For example,
{x: 123, y:456} is totally equivalent to {y:456,
x:123}.
Supported Types for the Output Tuple Elements
| Type |
Support |
Null |
Yes |
String |
Yes |
TextMatch |
Yes |
Boolean |
Yes |
Decimal<precision> |
Yes |
Float |
Yes |
Integer |
Yes |
Range |
No |
Date |
Yes |
DateTime |
Yes |
LocalDateTime |
Yes |
ZoneOffset |
No |
Period |
Yes |
Duration |
Yes |
Instant |
No |
TimeSeries |
Yes |
Embedding |
Yes |
Type |
No |
Unit |
No |
Binary |
No |
Geometry |
No |
Function |
No |
Comparable |
No |
Any |
No |
List<E> |
Yes |
Tuple<K1: V1, K2: V2, ...> |
No |
Set<E> |
Yes |
Map<K, V> |
Yes |
Item<pkg.class> |
No |
Examples
Parsing Dates and Time
Input data:
a_date, a_datetime, a_time
01/01/2020, 01/01/2020 20:15:36, 20:15:36
01/01/1970, 01/01/1970 00:01:01, 00:01:01
29/12/1969, 29/12/1969 23:59:59, 23:59:59
You can parse dates with a date format other than ISO 6801, with an expression like:
{a_date: Date.parse(text: record.a_date, format: "dd/MM/yyyy"),
a_datetime: LocalDateTime.parse(text: record.a_datetime, format: "dd/MM/yyyy HH:mm:ss"),
a_time: LocalDateTime.parse(text: "01/01/1970 "+record.a_time, format: "dd/MM/yyyy HH:mm:ss")}
Parsing Lists
Input data:
name, neighbors, neighbors_distance
alice, bob|camille, 123;456
bob, david|camille|alice, 147;258;369
camille, ,
david, emilie, 741
emilie, bob|david, 159;753
You can process this data with the following expression:
{...record, neighbors: record.neighbors IS NULL ? [] AS List<String>:
record.neighbors.split("|"), neighbors_distance: record.neighbors_distance IS NULL ? [] AS List<Integer> :
record.neighbors_distance.split(";").map(function: x => Integer.parse(value: x))}
Parsing Lists with Trimming and Unquoting
Input data:
name, neighbors
alice, "bob"| camille
bob, david | "camille" | alice
camille,
david, "emilie"
emilie, "bob"| david
You can process this data with the following expression:
{...record, neighbors: record.neighbors IS NULL ? [] AS List<String> : record.neighbors.split("|").
map(s => s.trim()).map(s => s.endsWith("\"") AND s.startsWith("\"") ? s.substring(1, - 1) : s )}
Simple Cleaning
Input data:
name, age, status
Alice, 20, Single
Bob, 40, married
Camille, 70, Widow
David, 42, single
Emilie, 25, not married
Example of cleaning expression for this CSV file:
{...record, status: record.status.toLowerCase().replace("not married", "single")}
Json Expression Input Type Examples
The examples below show Json input expressions for
Index Tabular Data pipelines.
Reading CSV Input as Json
Input data: name, age, status
Alice, 20, Single
Bob, 40, married
Camille, 70, Widow
David, 42, single
Emilie, 25, not married
You can process this data by writing the record object as a JSON
object instead of a tuple with the following
expression: {name: record["name"] AS String, age: Integer.parse(record["age"] AS String) status: record["status"] AS string}
Note:
By default, every field is inferred as a String for CSV inputs,
which means that you must parse the age manually.
Transforming CSV Files with Different Schemas in a Single Class
Input data: Two CSV files representing marital status in two different ways, that is,
one uses a string and the other one uses a Boolean.
- CSV 1:
name,status
Anna,Married
Bob,Single
Carol,Married
- CSV 2:
name,maried
David,true
Elise,false
Fred,false
You can process this data with the following expression: {
uri:fileInfo.filename + ":" + fileInfo.lineNumber,
name: record["name"] as STRING,
married: record["married"] IS NOT NULL ? record["married"] AS String == "true" : record["Status"] AS String == "Married"
}
Output: {name: "Anne", married: true}
{name: "Bob", married: false}
{name: "Carol", married: true}
{name: "David", married: true}
{name: "Elise", married: false}
{name: "Fred", married: false}
Processing Multiple CSV Files with Different Schemas
Input data:
- CSV 1:
a
1
2
3
- CSV 2:
b
one
two
three
- CSV 3:
c
true
false
false
You can process this data with the following expression to ingest the 3 different
classes: {
uri:fileInfo.filename + ":" + fileInfo.lineNumber,
class: record["a"] IS NOT NULL? "list.Int": record["b"] IS NOT NULL ? "list.String": record["c"] IS NOT NULL? "list.Bool":"unknown.Class",
stringValue: record["b"].toString(),
boolValue: record["c"] AS String == "true",
intValue: Integer.parse(record["a"] AS String)
}
In the expression above, one class is named list.Int with a single
intValue integer field, the second class is named
list.String with a single stringValue field, and the
third class is named list.Bool with a single boolValue
field.
Output:
- In the
list.Int class:{intValue: 1}
{intValue: 2}
{intvalue: 3}
- In the
list.String class:{stringValue: "one"}
{stringValue: "two"}
{stringValue: "three"}
- In the
list.Bool class:{boolValue: true}
{boolValue: false}
{boolValue: false}
|