diff --git a/core/src/main/java/com/redislabs/riot/KeyValueProcessingOptions.java b/core/src/main/java/com/redislabs/riot/KeyValueProcessingOptions.java index 67ae7bfc8..d9d6d9b35 100644 --- a/core/src/main/java/com/redislabs/riot/KeyValueProcessingOptions.java +++ b/core/src/main/java/com/redislabs/riot/KeyValueProcessingOptions.java @@ -18,20 +18,17 @@ public class KeyValueProcessingOptions { @Option(arity = "1..*", names = "--spel", description = "SpEL expression to produce a field", paramLabel = "") private Map spelFields = new HashMap<>(); - @Option(arity = "1..*", names = "--filter", description = "SpEL expression to filter records", paramLabel = "") - private List filters = new ArrayList<>(); @Option(arity = "1..*", names = "--var", description = "Register a variable in the SpEL processor context", paramLabel = "") private Map variables = new HashMap<>(); @Option(names = "--date", description = "Processor date format (default: ${DEFAULT-VALUE})", paramLabel = "") private String dateFormat = new SimpleDateFormat().toPattern(); @Option(arity = "1..*", names = "--regex", description = "Extract named values from source field using regex", paramLabel = "") private Map regexes = new HashMap<>(); + @Option(arity = "1..*", names = "--filter", description = "SpEL expression to filter records", paramLabel = "") + private List filters = new ArrayList<>(); public ItemProcessor, Map> processor(StatefulConnection connection) { List, Map>> processors = new ArrayList<>(); - if (!filters.isEmpty()) { - processors.add(new FilteringProcessor(filters)); - } if (!spelFields.isEmpty()) { processors.add(new SpelProcessor(connection, new SimpleDateFormat(dateFormat), variables, spelFields)); } @@ -40,6 +37,9 @@ public ItemProcessor, Map> processor(Statefu regexes.forEach((f, r) -> fields.put(f, RegexNamedGroupsExtractor.builder().regex(r).build())); processors.add(new MapProcessor(fields)); } + if (!filters.isEmpty()) { + processors.add(new FilteringProcessor(filters)); + } if (processors.isEmpty()) { return null; } diff --git a/docs/processing.adoc b/docs/processing.adoc index b66fcdc4d..3cc7b1d3c 100644 --- a/docs/processing.adoc +++ b/docs/processing.adoc @@ -1,31 +1,44 @@ The following processors can be applied to records in that order: -* Filters * Transforms * Regular expressions - -==== Filter - -Keep records that match a https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions[Spring Expression Language] (SpEL) boolean expression - -`--filter "name matches '[a-zA-Z\\s]+'"` +* Filters ==== Transform -Produce key/value pairs using SpEL: `field1=`, `field2=`, ... +Produce key/value pairs using https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions[Spring Expression Language] (SpEL): `field1=`, `field2=`, ... -For example `--spel field1=' generates a field named `field1` with always the same value `foo`. +For example `--spel "field1='foo'"` generates a field named `field1` with always the same value `foo`. Input fields are accessed by name (e.g. `field3=field1+field2`). The processor also exposes the following variables that can be called with the `#` prefix: -* `redis` : Redis connection to issue any command, e.g. `name=#redis.hgetall('person1').lastName` -* `date` : date parser/formatter, e.g. `epoch=#date.parse(mydate).getTime()` -* `index` : sequence number of the item being generated, e.g. `id=#index` +===== redis +Redis connection to issue any command: + +`--spel "name=#redis.hgetall('person1').lastName"` + +===== date +Date parser/formatter: + +`--spel "epoch=#date.parse(mydate).getTime()"` + +===== index +Sequence number of the item being generated: + +`--spel "id=#index"` ==== Regex Extract patterns from source fields using regular expressions: -`--regex "name=(?\w+)\/(?\w+)"` \ No newline at end of file +`--regex "name=(?\w+)\/(?\w+)"` + +==== Filter + +Keep records that match a SpEL boolean expression. + +`--filter "value matches '\\d+'"` will only keep records where the `value` field is a series of digits. + +