dashbitco/flow

Session windows are mentioned as supported but are not

wrgoldstein opened this issue · 1 comments

The documentation in lib/flow/window.ex#L31 lists Session windows as a supported window type, but they were removed in 0.14:

This release also deprecates Flow.Window.session/3 as developers can trivially roll their own with more customization power and flexibility using emit_and_reduce/3 and on_trigger/2.

Should we remove the reference to session windows being supported, or add documentation on how to implement a session window using emit_and_reduce/3 and on_trigger/2?

I'll include an example here, in case it is helpful to anyone:

iex> data = [
...>   {"elixir", 1_000},
...>   {"erlang", 60_000},
...>   {"elixir", 3_200_000},
...>   {"erlang", 4_000_000},
...>   {"elixir", 4_100_000},
...>   {"erlang", 6_000_000}
...> ]
iex> flow = Flow.from_enumerable(data) |> Flow.partition(key: fn {k, _} -> k end, stages: 2)
iex> flow =
...>   Flow.emit_and_reduce(flow, fn -> %{} end, fn {word, time}, acc ->
...>     {count, prev_time} = Map.get(acc, word, {1, time})
...>
...>     if time - prev_time > 1_000_000 do
...>       {[{word, {count, prev_time}}], Map.put(acc, word, {1, time})}
...>     else
...>       {[], Map.update(acc, word, {1, time}, fn {count, _} -> {count + 1, time} end)}
...>     end
...>   end)
iex> flow = Flow.on_trigger(flow, fn acc -> {Enum.to_list(acc), :unused} end)
iex> Enum.to_list(flow)
[
  {"erlang", {1, 60000}},
  {"erlang", {2, 6000000}},
  {"elixir", {1, 1000}},
  {"elixir", {2, 4000000}}
]

A PR that updates the docs and adds an example would be very welcome!