Working With Lynx
Lynx is Edlink's own CSV parsing language. It is used to work with tabular data coming from CSV files or Edlink's dataset.
Here are a couple of examples of places that Lynx is used in the Edlink platform:
- Mapping CSV data to entity properties for SFTP or CSV data sources.
- Matching entities for the purpose of enriching sources.
The most basic command in Lynx is a column name. A column name acts as a getter function where Lynx will extract the value of that column as it iterates through every row.
For more complex functionality Lynx also includes a set of functions. Lynx functions have names that comprise of all uppercased letters: ARRAY(), ID(), etc.
These functions can take 3 type of arguments:
- column names.
- basic data types: strings, numbers, booleans.
- outputs of other functions.
This page contains the following sections:
Column Names
When you pass a column name to a Lynx function, that Lynx function will be passed that column's value for every row being iterated.
Lynx interprets strings without double quotes as column names. Everything except [], (), and , is allowed in a column name.
The following example creates an array with a single value for every row in the data. That single value is the row's value under the role column.
ARRAY(role)
In case a column name includes invalid characters or has the same name as one of the Lynx functions, you need to escape the column name. To escape a column name, wrap it in single quotes:
ARRAY('role[]')
Virtually everything is allowed in an escaped column name. If you need to include a single quote in your column name, you can escape it with another single quote:
ARRAY('role O''Neil')
Basic Data Types
Lynx functions can also take the following basic data types:
- string:
"Hello World", a string must be wrapped in double quotes. - number:
123.45 - boolean:
TRUEorFALSE
Example:
ARRAY("student", 123.45, TRUE)
Functions
Date Functions
DATE()
DATE("YYYY-MM-DD")
Attempts to resolve a date from a string. If the string is not a valid date, it will return undefined.
Number Functions
Represents a string.
Number
123.45
Represents a number.
Boolean
TRUE or FALSE
Represents a boolean value of true or false.
Column
ANY_COLUMN_NAME
Represents the value of a column in the current row. Everything except [], (), and , is allowed in a column name.
Escaped Column
'ANY_COLUMN_NAME'
Represents the value of a column in the current row. Virtually everything is allowed in an escaped column name. If you need to include a single quote in your column name, you can escape it with another single quote. For example, O'Neil would be represented as 'O''Neil'.
If Function
IF(condition, trueValue, falseValue)
Evaluates and returns trueValue if condition is truthy, otherwise evaluates and returns falseValue.
Equals Function
EQ(arg1, arg2)
Returns TRUE if arg1 is equal to arg2, otherwise returns FALSE.
Split Function
SPLIT(string, delimiter)
Splits a string into an array of strings using the specified delimiter.
Join Function
JOIN(array, delimiter)
Joins an array of strings into a single string using the specified delimiter.
Reverse Function
REVERSE(array)
Reverses the items in an array.
Concat Function
CONCAT(arg1, arg2, ...)
Concatenates the arguments into a single string.
Trim Function
TRIM(string)
Removes whitespace from the beginning and end of a string.
Coalesce Function
COALESCE(arg1, arg2, ...)
Returns the first argument that is not undefined or null.
Switch Function
SWITCH(condition, case1, value1, case2, value2, ...)
Evaluates the first case whose condition is truthy and returns its value. If no case is truthy, returns null.
Object Function
OBJECT(key1, value1, ...)
Returns an object with the argument pairs as keys and values.
JSON Function
JSON(arg)
Parse a JSON string into an object.
Integer Function
INT(arg)
Parse a string into an integer.
FLOAT()
FLOAT(arg)
Parse a string into a float.
String Functions
CONCAT()
CONCAT(arg1, arg2, ...)
Concatenates the arguments into a single string.
ENDS()
ENDS(string, suffix)
Returns TRUE if string ends with suffix, otherwise returns FALSE.
LOWER()
LOWER(string)
Converts a string to lowercase.
REGEX()
REGEX(pattern)
Creates a regular expression from a string pattern. Can be used in conjunction with functions like REPLACE and SPLIT.
REPLACE()
REPLACE(string, search, replace)
Replaces all instances of search with replace in string.
SPLIT()
SPLIT(string, delimiter)
Splits a string into an array of strings using the specified delimiter.
STARTS()
STARTS(string, prefix)
Returns TRUE if string starts with prefix, otherwise returns FALSE.
SUBSTRING()
SUBSTRING(string, start, end)
Returns a substring of string from start to end.
TRIM()
TRIM(string)
Removes whitespace from the beginning and end of a string.
UPPER()
UPPER(string)
Converts a string to uppercase.
Array Functions
ARRAY()
ARRAY(arg1, arg2, ...)
Returns an array of the arguments passed in.
The following example creates an array with a single value for every row in the data. That single value is the row's value under the role column.
ARRAY(role)
The following example creates an array with 2 values using strings:
ARRAY("student", "teacher")
INTERSECT()
INTERSECT(array1, array2)
Returns an array of the items that are in both array1 and array2.
JOIN()
JOIN(array, delimiter)
Joins an array of strings into a single string using the specified delimiter.
LEFT()
LEFT(array|string, length)
Returns an array or string containing the first length items of array|string.
LENGTH()
LENGTH(arg)
Returns the length of a string or array.
POP()
POP(array)
Removes the last item from an array and returns it.
PUSH()
PUSH(array, value)
Adds a value to the end of an array.
REVERSE()
REVERSE(array)
Reverses the items in an array.
RIGHT()
RIGHT(array|string, length)
Returns an array or string containing the last length items of array|string.
SHIFT()
SHIFT(array)
Removes the first item from an array and returns it.
SLICE()
SLICE(array, start, end)
Returns an array containing the items of array from start to end.
UNSHIFT()
UNSHIFT(array, value)
Adds a value to the beginning of an array.
Conditional Functions
AND()
AND(arg1, arg2, ...)
Returns TRUE if all arguments are truthy, otherwise returns FALSE.
COALESCE()
COALESCE(arg1, arg2, ...)
Returns the first argument that is not undefined or null.
EQ()
EQ(arg1, arg2)
Returns TRUE if arg1 is equal to arg2, otherwise returns FALSE.
GREATER()
GREATER(arg1, arg2)
Returns TRUE if arg1 is greater than arg2, otherwise returns FALSE.
IF()
IF(condition, trueValue, falseValue)
Evaluates and returns trueValue if condition is truthy, otherwise evaluates and returns falseValue.
LESS()
LESS(arg1, arg2)
Returns TRUE if arg1 is less than arg2, otherwise returns FALSE.
NOT()
NOT(arg1, arg2, ...)
Returns TRUE if all arguments are falsy, otherwise returns FALSE
OR()
OR(arg1, arg2, ...)
Returns TRUE if any argument is truthy, otherwise returns FALSE.
SWITCH()
SWITCH(condition, case1, value1, case2, value2, ...)
Evaluates the first case whose condition is truthy and returns its value. If no case is truthy, returns null.
Object Functions
OBJECT()
OBJECT(key1, value1, ...)
Returns an object with the argument pairs as keys and values.
JSON()
JSON(arg)
Parse a JSON string into an object.
LOOKUP()
LOOKUP(value, key|index)
This function works on both objects and arrays. If the value is an object, it will return the value of the key in the object. If the value is an array, it will return the value at the index in the array.
Identifier Functions
ID()
ID(type)
Locates and returns the value of the identifier with the specified type. If no identifier is found, returns null. List of valid identifiers.
Function Examples
Create an array using the value in the column role:
ARRAY(role)
Create an array using the value in the column role and make it lowercase:
ARRAY(LOWER(role))
Create an array using strings:
ARRAY("teacher", "student")
Create an array from the column roles whose values are comma separated strings
SPLIT(roles, ",")
Create a date using value from the column graduation_date:
DATE(graduation_date)
Create a date using value from a string:
DATE("8/14/2004")
Create display name by concatening the values of the firstname and lastname columns:
CONCAT(firstname, " ", lastname)
Return the value in the email address column if it ends with the correct domain otherwise return an empty string:
IF(ENDS(email address, "@ed.link"), email address, "")
Return the Edlink grade level based on the value from the column grade_level:
SWITCH(grade_level, "6", "06", "7", "07", "8", "08")
Return the Edlink role based on the value of the column title:
ARRAY(SWITCH(title, "Teacher", "teacher", "Principal", "administrator", "Counselor_Secondary", "staff"))
Return the Edlink race based on the value of the column Race:
ARRAY(SWITCH(Race, "W", "white", "B" , "black-or-african-american", "A", "asian"))
Return the Edlink race based on the value of the column Race, if no match is found return white:
COALESCE(SWITCH(Race, "B" , "black-or-african-american", "A", "asian"), "white")
Return true or false if the value of column ethnicity equals "hispanic"
IF(EQ(ethnicity, "hispanic"), TRUE, FALSE)
Return a roles array with a single value of administrator or staff depending on the value in the permission_level column:
ARRAY(IF(EQ(permission_level, "Administration"), "administrator", "staff"))
Extract teacher ID from the value of column TeacherID which is prefixed by the value of column SchoolID:
SUBSTRING(TeacherID, LENGTH(SchoolID), LENGTH(TeacherID))
Extract teacher ID from the value of column TeacherID which is prefixed by "id_":
POP(SPLIT(TeacherID, "_"))
Extract a person's first name from their email address listed in the email column whose format is firstname_lastname@domain:
SHIFT(SPLIT(SHIFT(SPLIT(email, "@")), "_"))