Skip to content

Instantly share code, notes, and snippets.

@ogibayashi
Created July 31, 2015 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogibayashi/4c68bff95176beaaaaff to your computer and use it in GitHub Desktop.
Save ogibayashi/4c68bff95176beaaaaff to your computer and use it in GitHub Desktop.
Norikra上でマスタデータ等とJOINするのに使えるnorikra-udf-lookupを作った ref: http://qiita.com/ogibayashi/items/67b37904cae3b47cf407
gem 'norikra-udf-lookup'
$ gem install norikra-udf-lookup
% cat /tmp/lookuptest.tsv
1 aaa
2 bbb
3 ccc
SELECT
id, lookup_tsv('/tmp/lookuptest.tsv',id,'not found') as name, count(*) as cnt
FROM
test_stream.win:time_batch(1 min)
GROUP by id
% echo '{"id":"1"}' | norikra-client event send test_stream
% echo '{"id":"2"}' | norikra-client event send test_stream
% echo '{"id":"3"}' | norikra-client event send test_stream
% echo '{"id":"4"}' | norikra-client event send test_stream
% norikra-client event sweep
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"3","cnt":1,"name":"ccc"}
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"2","cnt":1,"name":"bbb"}
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"1","cnt":1,"name":"aaa"}
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"4","cnt":1,"name":"not found"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment