Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lpgauth/swirl

High-Performance Erlang Stream Processor
https://github.com/lpgauth/swirl

erlang flow high-performance stream-processing

Last synced: 25 days ago
JSON representation

High-Performance Erlang Stream Processor

Awesome Lists containing this project

README

        

# swirl

High Performance Erlang Stream Processor

### Requirements

* Erlang 22.0 +

### Environment variables


Name
Type
Default
Description


mappers_max
pos_integer()
100
maximum number of mappers


reducers_max
pos_integer()
100
maximum number of reducers

## Examples

#### Starting a flow

```erlang
ok = application:start(swirl),

FlowMod = swirl_flow_example,
FlowOpts = [
{stream_names, [delivery]},
{stream_filter, "exchange_id = 3 AND bidder_id IS NOT NULL"}
],
MapperNodes = [node()],
ReducerNode = node(),
{ok, Flow} = swirl_flow:start(FlowMod, FlowOpts, MapperNodes, ReducerNode),

StreamName = delivery,
Event = #{exchange_id => 1, bidder_id => 10},

swirl_stream:emit(StreamName, Event),

ok = swirl_flow:stop(Flow)
```

#### Implementing a flow

```erlang
-module(swirl_flow_example).
-include_lib("swirl/include/swirl.hrl").

-behavior(swirl_flow).
-export([
map/3,
reduce/3,
output/4
]).

%% swirl_flow callbacks
map(StreamName, Event, _MapperOpts) ->
Type = ?L(type, Event),
ExchangeId = ?L(exchange_id, Event),
BidderId = ?L(bidder_id, Event),

Key = {Type, StreamName, ExchangeId, BidderId},
CounterIncrements = {1, 10},

{Key, CounterIncrements}.

reduce(_Flow, Row, _ReducerOpts) ->
Row.

output(_Flow, _Period, Rows, OutputOpts) ->
%% do something with the output
io:format("rows: ~p~n", [Rows]),
```

#### Stream Filter

```erlang
exchange_id = 3 AND bidder_id IS NOT NULL
flight_id in (10, 12, 23) OR tag_id = 20
buyer_id notnull AND seller_id > 103
```

#### Swirl QL

variables:

```
atom()
```
values:

```
integer() | float() | binary()
```
boolean operators:

```
'and' | 'or'
```
comparison operators:

```
'<' | '<=' | '=' | '>=' | '>' | '<>'
```
inclusion operators:

```
in | notin
```
null operators:

```
null | notnull
```

## TODO
* node discovery
* boolean expression indexing

## Tests

```makefile
make dialyzer
make elvis
make eunit
make xref
```

## License

```license
The MIT License (MIT)

Copyright (c) 2013-2024 Louis-Philippe Gauthier

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```