SpEL Cheat Sheet
Expressions and types
Expressions used in Nussknacker are primarily written using SpEL (Spring Expression language) - simple, yet powerful expression language. SpEL is based on Java (reference documentation), but no prior Java knowledge is needed to use it.
The easiest way to learn SpEL is looking at examples which are further down this page. Some attention should be paid to data types, described in more detail in the next section, as depending on the context in which data are processed or displayed, different data type schemes are in use.
Check out SpEL overview for the overview of how SpEL is used by Nussknacker.
Data types and structures
The data types are used primarily for:
- validation - e.g. to detect attempt to use incorrect data type, for example numeric field instead of a string, or checking if field used in expression exists at all.
- code completion - suggestions appearing in UI when editing expressions.
Types of events in the Kafka streams or data returned by enrichers can be often discovered from some sort of schema registry, for example Confluent Schema Registry, SQL table schema or description of REST API. Nussknacker can also infer types of variables defined by user.
The data types used in the execution engine, SpEL expressions and data structures are Java based. These are also the data type names that appear in code completion hints. In most cases Nussknacker can automatically convert between Java data types and JSON and Avro formats. JSON will be used for REST API enrichers, while AVRO should be first choice for format of Kafka messages. The rules Nussknacker uses to convert between different data type systems can be found here - in most cases this information will not be needed during scenario authoring.
Below is the list of the most common data types. In Java types column package names are omitted for brevity,
they are usually java.lang
(primitives), java.util
(List, Map) and java.time
Basic (primitive data types)
Java type | Comment |
---|---|
null | |
String | UTF-8 |
Boolean | |
Integer | 32bit |
Long | 64bit |
Float | single precision |
Double | double precision |
BigDecimal | enable computation without rounding errors |
UUID | uuid |
More information about how to declare each type in Avro is in Avro documentation, especially about Avro logical types.
Records/objects/maps
In Nussknacker, the following data types share common processing characteristics:
object
in JSONrecord
ormap
in AvroMap
and POJO in Java
In many cases Nussknacker can convert between them automatically.
For the user, the most significant difference is (using Avro terminology)
between record
and map
. Both can describe following JSON structure:
input = { name: 'John', surname: 'Doe'}
The main difference is that in case of record
Nussknacker "knows" which fields (name
and surname
)
are available and suggests and validates fields and their types.
For example, #input.name
is valid, while #input.noname
or #input.name > 0
as field name or type do not match.
On the other hand, map
describes "generic" structure - Nussknacker tacitly assumes it can contain any field, but only of certain type (e.g. we can have a "map of Strings", "map of Integers" etc. If this type is Unknown
the values might be of any type).
Nussknacker usually infers structure of record from external source (e.g. Avro schema), but it can also detect it from map literals.
Arrays/lists
In Nussknacker (e.g. in code completion) JSON / Avro arrays are referred to as Lists
;
also in some context Collection
can be met (it's Java API for handling lists, sets etc.).
Date/Time
See Handling data/time for detailed description of how to deal with date and time in Nussknacker.