norikra-udf-lookup 0.0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +71 -0
- data/Rakefile +37 -0
- data/jar/.touched +0 -0
- data/jar/norikra-udf-lookup.jar +0 -0
- data/java/.touched +0 -0
- data/lib/esper_plugin/lookup.rb +20 -0
- data/lib/norikra/udf/lookup/version.rb +7 -0
- data/lib/norikra/udf/lookup.rb +22 -0
- data/norikra-udf-lookup.gemspec +34 -0
- data/spec/lookup_spec.rb +28 -0
- data/test/norikra/udf/lookup_test.rb +11 -0
- data/test/test_helper.rb +4 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b01908e0a86f828de588a4cf2e26418fecd3b298
|
4
|
+
data.tar.gz: 787fb9c26a32f6f85b2068325a1f5b17787f1b46
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 972032745ed7468d8fd84d8fa79352c1da3377e48b8f126c130c59b159c196a57473add7b0784540fbf2b50c44f1cb3fd91753aaed31b61a122125901b0c46ef
|
7
|
+
data.tar.gz: a2259e1a1dc74966a28e41550b71fad628a03325fbc00ec88cb5668a22b2d1104f207004ea7e3d0a2f0d2ed54ef714b384f26480686566748d70e46b149eeddc
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Norikra::Udf::Lookup
|
2
|
+
|
3
|
+
Norikra UDF to lookup external data source. (Currently, only TSV file)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'norikra-udf-lookup'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install norikra-udf-lookup
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
### lookup_tsv(string, string, string)
|
25
|
+
|
26
|
+
Parameters are: TSV file path, key to lookup, return value if the key was not found.
|
27
|
+
|
28
|
+
Lookup key in TSV file and return corresponding value.
|
29
|
+
|
30
|
+
For example, create such file with "key<tab>value" pairs.
|
31
|
+
|
32
|
+
```
|
33
|
+
% cat /tmp/lookuptest.tsv
|
34
|
+
1 aaa
|
35
|
+
2 bbb
|
36
|
+
3 ccc
|
37
|
+
```
|
38
|
+
|
39
|
+
Register query with this UDF.
|
40
|
+
|
41
|
+
```
|
42
|
+
SELECT
|
43
|
+
id, lookup_tsv('/tmp/lookuptest.tsv',id,'not found') as name, count(*) as cnt
|
44
|
+
FROM
|
45
|
+
test_stream.win:time_batch(1 min)
|
46
|
+
GROUP by id
|
47
|
+
```
|
48
|
+
|
49
|
+
Send some events.
|
50
|
+
|
51
|
+
```
|
52
|
+
% echo '{"id":"1"}' | norikra-client event send test_stream
|
53
|
+
% echo '{"id":"2"}' | norikra-client event send test_stream
|
54
|
+
% echo '{"id":"3"}' | norikra-client event send test_stream
|
55
|
+
% echo '{"id":"4"}' | norikra-client event send test_stream
|
56
|
+
```
|
57
|
+
|
58
|
+
Then, you will get there records.
|
59
|
+
|
60
|
+
```
|
61
|
+
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"3","cnt":1,"name":"ccc"}
|
62
|
+
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"2","cnt":1,"name":"bbb"}
|
63
|
+
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"1","cnt":1,"name":"aaa"}
|
64
|
+
{"time":"2015/07/28 12:13:24","query":"lookuptest","id":"4","cnt":1,"name":"not found"}
|
65
|
+
```
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
* Copyright (c) 2015- OGIBAYASHI Hironori
|
70
|
+
* License
|
71
|
+
* GPL v2
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
|
+
t.rspec_opts = ["-Ijar", "-Ilib", "-c", "-f progress"] # '--format specdoc'
|
6
|
+
t.pattern = 'spec/**/*_spec.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
task :compile do
|
10
|
+
require 'rubygems'
|
11
|
+
|
12
|
+
jarname = FileList['norikra-udf-*.gemspec'].first.gsub(/\.gemspec$/, '.jar')
|
13
|
+
|
14
|
+
jarfiles = FileList['jar/**/*.jar'].select{|f| not f.end_with?('/' + jarname)}
|
15
|
+
jarfiles << Gem.find_latest_files('esper-*.jar').first
|
16
|
+
|
17
|
+
java_classpath = "-classpath src:java:#{jarfiles.join(':')}"
|
18
|
+
FileList['src/**/*.java'].each do |fn|
|
19
|
+
sh "env LC_ALL=C javac -J-Duser.language=en #{java_classpath} -d java #{fn}"
|
20
|
+
end
|
21
|
+
|
22
|
+
jruby_classpath = "--classpath java:#{jarfiles.join(':')}"
|
23
|
+
FileList['lib/esper_plugin/**/*.rb'].each do |fn|
|
24
|
+
sh "env LC_ALL=C jrubyc --javac --target java #{jruby_classpath} #{fn}"
|
25
|
+
end
|
26
|
+
|
27
|
+
sh "env LC_ALL=C jar -J-Duser.language=en -cf jar/#{jarname} -C java ."
|
28
|
+
end
|
29
|
+
|
30
|
+
task :clean do
|
31
|
+
sh "rm -rf java/*"
|
32
|
+
end
|
33
|
+
|
34
|
+
task :test => [:compile, :spec]
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
task :all => [:clean, :compile, :spec, :build]
|
data/jar/.touched
ADDED
File without changes
|
Binary file
|
data/java/.touched
ADDED
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'java'
|
2
|
+
java_package 'jp.gr.java_conf.ogibayashi.norikra.udf'
|
3
|
+
|
4
|
+
class Lookup # FQDN: org.example.yourcompany.norikra.udf.MyUDF1
|
5
|
+
@@lookup_table = nil
|
6
|
+
|
7
|
+
def self.read_tsv(path)
|
8
|
+
data = File.open(path).readlines.map do |line|
|
9
|
+
line.chomp.split("\t")
|
10
|
+
end
|
11
|
+
Hash[data]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.lookup_tsv(path,key,default_value)
|
15
|
+
unless @@lookup_table
|
16
|
+
@@lookup_table = self.read_tsv(path)
|
17
|
+
end
|
18
|
+
@@lookup_table[key] || default_value
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'norikra/udf'
|
3
|
+
|
4
|
+
|
5
|
+
module Norikra
|
6
|
+
module UDF
|
7
|
+
|
8
|
+
class LookupTsv < Norikra::UDF::SingleRow
|
9
|
+
# class method
|
10
|
+
def self.init
|
11
|
+
require 'norikra-udf-lookup.jar'
|
12
|
+
end
|
13
|
+
|
14
|
+
# instance method
|
15
|
+
def definition
|
16
|
+
# function_name, Java Class Name (fqdn), static function name
|
17
|
+
["lookup_tsv", "jp.gr.java_conf.ogibayashi.norikra.udf.Lookup", "lookup_tsv"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'norikra/udf/lookup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "norikra-udf-lookup"
|
8
|
+
spec.version = Norikra::Udf::Lookup::VERSION
|
9
|
+
spec.authors = ["Hironori Ogibayashi"]
|
10
|
+
spec.email = ["ogibayashi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Norikra UDF to Lookup keys from a table}
|
13
|
+
spec.description = %q{Norikra UDF to Lookup keys from a table}
|
14
|
+
spec.homepage = "https://github.com/ogibayashi"
|
15
|
+
spec.platform = "java"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files`.split($/)
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.require_paths = ["lib","jar"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
31
|
+
spec.add_development_dependency "rake"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_runtime_dependency "norikra"
|
34
|
+
end
|
data/spec/lookup_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'norikra/udf_spec_helper'
|
2
|
+
include Norikra::UDFSpecHelper
|
3
|
+
require 'norikra/udf/lookup' # this is your UDF definition file
|
4
|
+
|
5
|
+
# for single row UDF
|
6
|
+
describe Norikra::UDF::LookupTsv do
|
7
|
+
udf_function Norikra::UDF::LookupTsv
|
8
|
+
TMP_TABLE_FILE = "/tmp/lookuptest.tsv"
|
9
|
+
|
10
|
+
before do
|
11
|
+
File.open(TMP_TABLE_FILE,"w"){ |f|
|
12
|
+
f.puts "key1\thoge"
|
13
|
+
f.puts "key2\tfoo"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'Key found' do
|
18
|
+
expect(fcall(:lookup_tsv, TMP_TABLE_FILE, "key1","notfound")).to eql("hoge")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'Key not found' do
|
22
|
+
expect(fcall(:lookup_tsv, TMP_TABLE_FILE, "key5","notfound")).to eql("notfound")
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
File.unlink(TMP_TABLE_FILE)
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: norikra-udf-lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Hironori Ogibayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.7'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: norikra
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :runtime
|
69
|
+
description: Norikra UDF to Lookup keys from a table
|
70
|
+
email:
|
71
|
+
- ogibayashi@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- jar/.touched
|
82
|
+
- jar/norikra-udf-lookup.jar
|
83
|
+
- java/.touched
|
84
|
+
- lib/esper_plugin/lookup.rb
|
85
|
+
- lib/norikra/udf/lookup.rb
|
86
|
+
- lib/norikra/udf/lookup/version.rb
|
87
|
+
- norikra-udf-lookup.gemspec
|
88
|
+
- spec/lookup_spec.rb
|
89
|
+
- test/norikra/udf/lookup_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
homepage: https://github.com/ogibayashi
|
92
|
+
licenses: []
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
- jar
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Norikra UDF to Lookup keys from a table
|
116
|
+
test_files:
|
117
|
+
- spec/lookup_spec.rb
|
118
|
+
- test/norikra/udf/lookup_test.rb
|
119
|
+
- test/test_helper.rb
|