norikra-udf-mock 0.0.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/README.md +29 -0
- data/Rakefile +27 -0
- data/jar/.touched +0 -0
- data/jar/norikra-udf-mock.jar +0 -0
- data/java/is/tagomor/norikra/udf/AggregationSingleMock.java +39 -0
- data/java/is/tagomor/norikra/udf/AggregationSingleMockFactory.java +49 -0
- data/java/is/tagomor/norikra/udf/SingleRowMock.java +12 -0
- data/lib/norikra/udf/mock.rb +24 -0
- data/norikra-udf-mock.gemspec +24 -0
- data/spec/mock_spec.rb +46 -0
- metadata +125 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7.4
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Norikra::Udf::Woothee
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'norikra-udf-woothee'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install norikra-udf-woothee
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
|
+
t.rspec_opts = ["-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_files('esper-*.jar').first
|
16
|
+
classpath = "-classpath java:#{jarfiles.join(':')}"
|
17
|
+
|
18
|
+
FileList['java/**/*.java'].each do |fn|
|
19
|
+
sh "env LC_ALL=C javac #{classpath} #{fn}"
|
20
|
+
end
|
21
|
+
sh "env LC_ALL=C jar -cf jar/#{jarname} -C java ."
|
22
|
+
end
|
23
|
+
|
24
|
+
task :test => [:compile, :spec]
|
25
|
+
task :default => :test
|
26
|
+
|
27
|
+
task :all => [:compile, :spec, :build]
|
data/jar/.touched
ADDED
File without changes
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
package is.tagomor.norikra.udf;
|
2
|
+
|
3
|
+
import com.espertech.esper.epl.agg.aggregator.AggregationMethod;
|
4
|
+
|
5
|
+
// import java.util.Map;
|
6
|
+
|
7
|
+
public class AggregationSingleMock implements AggregationMethod {
|
8
|
+
// private final static long = 16777216;
|
9
|
+
private long counter;
|
10
|
+
|
11
|
+
public AggregationSingleMock() {
|
12
|
+
counter = 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
public Class getValueType() {
|
16
|
+
return Long.class;
|
17
|
+
}
|
18
|
+
|
19
|
+
public void enter(Object value) {
|
20
|
+
if (value == null)
|
21
|
+
return;
|
22
|
+
|
23
|
+
counter += value.toString().length();
|
24
|
+
}
|
25
|
+
|
26
|
+
public void leave(Object value) {
|
27
|
+
counter -= value.toString().length();
|
28
|
+
}
|
29
|
+
|
30
|
+
public Object getValue() {
|
31
|
+
return counter;
|
32
|
+
}
|
33
|
+
|
34
|
+
public void clear() {
|
35
|
+
counter = 0;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
package is.tagomor.norikra.udf;
|
2
|
+
|
3
|
+
import com.espertech.esper.client.hook.AggregationFunctionFactory;
|
4
|
+
import com.espertech.esper.epl.agg.service.AggregationValidationContext;
|
5
|
+
import com.espertech.esper.epl.agg.aggregator.AggregationMethod;
|
6
|
+
|
7
|
+
// import java.util.Map;
|
8
|
+
|
9
|
+
public class AggregationSingleMockFactory implements AggregationFunctionFactory {
|
10
|
+
/*
|
11
|
+
The aggregation function factory instance receives the aggregation function name via set setFunctionName method.
|
12
|
+
*/
|
13
|
+
public void setFunctionName(String functionName) {
|
14
|
+
// no action taken
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
An aggregation function factory must provide an implementation of the validate method
|
19
|
+
that is passed a AggregationValidationContext validation context object.
|
20
|
+
Within the validation context you find the result type of each of the parameters expressions
|
21
|
+
to the aggregation function as well as information about constant values and data window use.
|
22
|
+
Please see the JavaDoc API documentation for a comprehensive list of validation context information.
|
23
|
+
|
24
|
+
Since the example concatenation function requires string types, it implements a type check:
|
25
|
+
*/
|
26
|
+
public void validate(AggregationValidationContext validationContext) {
|
27
|
+
if ((validationContext.getParameterTypes().length != 1) ||
|
28
|
+
(validationContext.getParameterTypes()[0] != String.class)) {
|
29
|
+
throw new IllegalArgumentException("aggregation single mock requires a single parameter of type String");
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
/*
|
34
|
+
In order for the engine to validate the type returned by the aggregation function against
|
35
|
+
the types expected by enclosing expressions, the getValueType must return the result type
|
36
|
+
of any values produced by the aggregation function:
|
37
|
+
*/
|
38
|
+
public Class getValueType() {
|
39
|
+
return Long.class;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
Finally the factory implementation must provide a newAggregator method that returns instances
|
44
|
+
of AggregationMethod. The engine invokes this method for each new aggregation state to be allocated.
|
45
|
+
*/
|
46
|
+
public AggregationMethod newAggregator() {
|
47
|
+
return new AggregationSingleMock();
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'norikra/udf'
|
3
|
+
|
4
|
+
module Norikra
|
5
|
+
module UDF
|
6
|
+
class PassThrough < Norikra::UDF::SingleRow
|
7
|
+
def self.init
|
8
|
+
require 'norikra-udf-mock.jar'
|
9
|
+
end
|
10
|
+
def definition
|
11
|
+
["passThrough", "is.tagomor.norikra.udf.SingleRowMock", "passThrough"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class CountLength < Norikra::UDF::AggregationSingle
|
16
|
+
def self.init
|
17
|
+
require 'norikra-udf-mock.jar'
|
18
|
+
end
|
19
|
+
def definition
|
20
|
+
["countLength", "is.tagomor.norikra.udf.AggregationSingleMockFactory"]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "norikra-udf-mock"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["TAGOMORI Satoshi"]
|
7
|
+
spec.email = ["tagomoris@gmail.com"]
|
8
|
+
spec.description = %q{UDF mocks for Norikra development}
|
9
|
+
spec.summary = %q{Norikra UDF mock}
|
10
|
+
spec.homepage = "https://github.com/tagomoris/norikra-udf-mock"
|
11
|
+
spec.license = "GPLv2"
|
12
|
+
spec.platform = "java" #Gem::Platform::JAVA
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib", "jar"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "norikra", ">= 0.0.8"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/mock_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'norikra/udf_spec_helper'
|
2
|
+
|
3
|
+
include Norikra::UDFSpecHelper
|
4
|
+
|
5
|
+
require 'norikra/udf/mock'
|
6
|
+
|
7
|
+
describe Norikra::UDF::PassThrough do
|
8
|
+
udf_function Norikra::UDF::PassThrough
|
9
|
+
|
10
|
+
it 'returns argument itself' do
|
11
|
+
source = "xxx yyy zzz"
|
12
|
+
r = fcall(:passThrough, source)
|
13
|
+
expect(r).to eql(source)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Norikra::UDF::CountLength do
|
18
|
+
udf_function Norikra::UDF::CountLength, :valueType => java.lang.Long, :parameters => [[java.lang.String]]
|
19
|
+
|
20
|
+
it 'returns Long' do
|
21
|
+
expect(fcall(:countLength, :getValueType)).to eql(java.lang.Long.java_class)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'counts sum of length of Strings' do
|
25
|
+
f = function(:countLength)
|
26
|
+
|
27
|
+
f._call(:enter, "01234")
|
28
|
+
f._call(:enter, "56789")
|
29
|
+
f._call(:enter, "01234")
|
30
|
+
f._call(:enter, "56789")
|
31
|
+
v = f.getValue
|
32
|
+
expect(v).to eql(20)
|
33
|
+
f._call(:clear)
|
34
|
+
expect(f._call(:getValue)).to eql(0)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can decrements count with leave' do
|
38
|
+
expect(fcall(:countLength, :getValue)).to eql(0)
|
39
|
+
fcall(:countLength, :enter, "01234")
|
40
|
+
expect(fcall(:countLength, :getValue)).to eql(5)
|
41
|
+
fcall(:countLength, :leave, "0123")
|
42
|
+
expect(fcall(:countLength, :getValue)).to eql(1)
|
43
|
+
fcall(:countLength, :clear)
|
44
|
+
expect(fcall(:countLength, :getValue)).to eql(0)
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: norikra-udf-mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- TAGOMORI Satoshi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: norikra
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.0.8
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.8
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.3'
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.3'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
none: false
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
none: false
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
description: UDF mocks for Norikra development
|
79
|
+
email:
|
80
|
+
- tagomoris@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .ruby-version
|
87
|
+
- Gemfile
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- jar/.touched
|
91
|
+
- jar/norikra-udf-mock.jar
|
92
|
+
- java/is/tagomor/norikra/udf/AggregationSingleMock.java
|
93
|
+
- java/is/tagomor/norikra/udf/AggregationSingleMockFactory.java
|
94
|
+
- java/is/tagomor/norikra/udf/SingleRowMock.java
|
95
|
+
- lib/norikra/udf/mock.rb
|
96
|
+
- norikra-udf-mock.gemspec
|
97
|
+
- spec/mock_spec.rb
|
98
|
+
homepage: https://github.com/tagomoris/norikra-udf-mock
|
99
|
+
licenses:
|
100
|
+
- GPLv2
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
- jar
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
none: false
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
none: false
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.24
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Norikra UDF mock
|
124
|
+
test_files:
|
125
|
+
- spec/mock_spec.rb
|