-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
❯ riot-file -h localhost -p 6379 import https://redis-developer.github.io/riot/beers.csv --filter "style == 'American IPA'" --header hmset --keyspace beer --keys id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
❯ riot-file -h localhost -p 6379 import https://redis-developer.github.io/riot/airports.csv --regex "Tz=(?<region>\w+)\/(?<city>\w+)" --header hmset --keyspace airport --keys AirportID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/redislabs/riot/processor/FilteringProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.redislabs.riot.processor; | ||
|
||
import org.springframework.batch.item.ItemProcessor; | ||
import org.springframework.expression.Expression; | ||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
import org.springframework.expression.spel.support.StandardEvaluationContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class FilteringProcessor implements ItemProcessor<Map<String, Object>, Map<String, Object>> { | ||
|
||
private final StandardEvaluationContext context; | ||
private final List<Expression> expressions; | ||
|
||
public FilteringProcessor(List<String> filters) { | ||
this.context = new StandardEvaluationContext(); | ||
context.setPropertyAccessors(Collections.singletonList(new MapAccessor())); | ||
SpelExpressionParser parser = new SpelExpressionParser(); | ||
this.expressions = new ArrayList<>(); | ||
for (String filter : filters) { | ||
expressions.add(parser.parseExpression(filter)); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> process(Map<String, Object> item) throws Exception { | ||
for (Expression expression : expressions) { | ||
if (Boolean.FALSE.equals(expression.getValue(context, item))) { | ||
return null; | ||
} | ||
} | ||
return item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
{app-name} can process records with field expressions. | ||
The following processors can be applied to records in that order: | ||
|
||
You can specify field expressions to produce key/value pairs using the https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions[Spring Expression Language] (SpEL): `field1=<exp>`, `field2=<exp>`, ... | ||
* Filters | ||
* Transforms | ||
* Regular expressions | ||
For example the expression `--spel field1=' generates a field named `field1` with always the same value `foo`: | ||
==== Filter | ||
|
||
The input record is accessed through its field names (e.g. `field3=field1+field2`). | ||
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]+'"` | ||
|
||
==== Transform | ||
|
||
Produce key/value pairs using SpEL: `field1=<exp>`, `field2=<exp>`, ... | ||
|
||
For example `--spel field1=' 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, 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` | ||
|
||
==== Regex | ||
|
||
Extract patterns from source fields using regular expressions: | ||
|
||
`--regex "name=(?<first>\w+)\/(?<last>\w+)"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters