Sha256: 3726a0295f62b611be3a3f2c5345ccd249961122860b464e6bf4e28b9a250832

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# Norikra::Udf::Lookup

Norikra UDF to lookup external data source. (Currently, only TSV file)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'norikra-udf-lookup'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install norikra-udf-lookup

## Usage


### lookup_tsv(string, string, string)

Parameters are: TSV file path, key to lookup, return value if the key was not found.

Lookup key in TSV file and return corresponding value.

For example, create such file with "key<tab>value" pairs.

```
% cat /tmp/lookuptest.tsv 
1       aaa
2       bbb
3       ccc
```

Register query with this UDF.

```
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
```

Send some events.

```
% 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
```

Then, you will get there records.

```
{"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"}
```

## Copyright

* Copyright (c) 2015- OGIBAYASHI Hironori
* License
    * GPL v2

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
norikra-udf-lookup-0.0.2-java README.md
norikra-udf-lookup-0.0.1-java README.md