datapipeline 2.0.0: Gem aus dem Projekt etl herausgelöst
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# Nur neue Buchungsbewegungen exportieren, Zeile für Zeile (Streaming)
|
||||
# Ein zweiter Lauf ohne neue Daten schreibt nichts.
|
||||
#
|
||||
# bin/etl run examples/bewegungen_inkrementell.rb [--out=tmp]
|
||||
#
|
||||
require 'fileutils'
|
||||
require 'datapipeline'
|
||||
|
||||
DATA = File.expand_path('data', __dir__)
|
||||
out = DataPipeline.params.fetch(:out, 'tmp')
|
||||
FileUtils.mkdir_p(out)
|
||||
|
||||
DataPipeline.new do
|
||||
streamed
|
||||
|
||||
# höchste id des letzten erfolgreichen Laufs, gespeichert in tmp/.state.json
|
||||
stand = watermark :bewegungen, column: 'id', file: "#{out}/.state.json", initial: 0
|
||||
|
||||
# bei einer Datenbank gehört der Filter ins SQL: where id > $1, params: [stand.value]
|
||||
read container(:json, file: "#{DATA}/bewegungen.ndjson")
|
||||
filter { |row| row['id'] > stand.value.to_i }
|
||||
map { |row| row.merge('soll_haben' => row['betrag'].negative? ? 'H' : 'S', 'betrag' => row['betrag'].abs) }
|
||||
|
||||
write container(:json,
|
||||
file: "#{out}/bewegungen_#{Time.now.strftime('%Y%m%d_%H%M%S')}.ndjson"
|
||||
)
|
||||
|
||||
on_finish { |stats| puts "neu: #{stats.written}, Stand jetzt: #{stand.current}" }
|
||||
end.run
|
||||
Reference in New Issue
Block a user