norikra-udf-uri_parser 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84040cec8187bf2c449640917eaa8df8e51f9003
4
+ data.tar.gz: 3a6331305b82d9640448ba8c6cf7c9a0692c6543
5
+ SHA512:
6
+ metadata.gz: 8c0e5a916b24cf31812e830c976a80cd971769c7b7011a1df1f546d7ad8cbbce05fa91a276417d228b3ab3c311dd46dd001a563a99f155abd385dfa8184e230e
7
+ data.tar.gz: 93c178ae6dab24d1481c7ca8e295e70e1543eb951fb5d7230c2bccf1369773475484a7a423d03ef0c26c8077e5a59d672891412b23ffda2e8c477ab1dae9ff11
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.16
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby-19mode
4
+ jdk:
5
+ - oraclejdk8
6
+ - oraclejdk7
7
+ - openjdk7
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # Norikra::Udf::UriParser
2
+
3
+ This is [Norikra](http://norikra.github.io/) UDF.
4
+
5
+ `splituri` UDF return value corresponds to specified element in uri string like `http://example.com/hoge`.
6
+
7
+ `splitquery` UDF return value corresponds to target key in query string like `hoge=foo`.
8
+
9
+ [![Build Status](https://travis-ci.org/mia-0032/norikra-udf-uri_parser.svg)](https://travis-ci.org/mia-0032/norikra-udf-uri_parser)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'norikra-udf-uri_parser'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install norikra-udf-uri_parser
26
+
27
+ ## Usage
28
+
29
+ ```sql
30
+ SELECT
31
+ -- path is like "/hoge?foo=bar"
32
+ splitquery(splituri(path, 'query'), 'foo') AS val
33
+ FROM access_log
34
+ ```
35
+
36
+ This query returns below.
37
+
38
+ ```javascript
39
+ {
40
+ "val":"bar"
41
+ }
42
+ ```
43
+
44
+ ### splituri(expression, string)
45
+
46
+ Second argument accepts `scheme`,`userinfo`,`host`,`port`,`path`,`opaque`,`query`,`fragment`.
47
+
48
+ #### Example queries:
49
+
50
+ ##### 1. Using path field.
51
+
52
+ ```sql
53
+ SELECT
54
+ -- path is like "/hoge?foo=bar#top"
55
+ splituri(path, 'scheme') AS scheme,
56
+ splituri(path, 'userinfo') AS userinfo,
57
+ splituri(path, 'host') AS host,
58
+ splituri(path, 'port') AS port,
59
+ splituri(path, 'path') AS path,
60
+ splituri(path, 'opaque') AS opaque,
61
+ splituri(path, 'query') AS query,
62
+ splituri(path, 'fragment') AS fragment
63
+ FROM access_log
64
+ ```
65
+
66
+ This query returns below.
67
+
68
+ ```javascript
69
+ {
70
+ "port":"",
71
+ "host":"",
72
+ "scheme":"",
73
+ "query":"foo=bar",
74
+ "opaque":"",
75
+ "path":"/hoge",
76
+ "userinfo":"",
77
+ "fragment":"top"
78
+ }
79
+ ```
80
+
81
+ ##### 2. Using URL filed.
82
+
83
+ ```sql
84
+ SELECT
85
+ -- referer is like "http://example.com/hoge?foo=bar#top"
86
+ splituri(referer, 'scheme') AS scheme,
87
+ splituri(referer, 'userinfo') AS userinfo,
88
+ splituri(referer, 'host') AS host,
89
+ splituri(referer, 'port') AS port,
90
+ splituri(referer, 'path') AS path,
91
+ splituri(referer, 'opaque') AS opaque,
92
+ splituri(referer, 'query') AS query,
93
+ splituri(referer, 'fragment') AS fragment
94
+ FROM access_log
95
+ ```
96
+
97
+ This query returns below.
98
+
99
+ ```javascript
100
+ {
101
+ "port":"",
102
+ "host":"example.com",
103
+ "scheme":"http",
104
+ "query":"foo=bar",
105
+ "opaque":"",
106
+ "path":"/hoge",
107
+ "userinfo":"",
108
+ "fragment":"top"
109
+ }
110
+ ```
111
+
112
+ ### splitquery(expression, string)
113
+
114
+ Second argument is the key that you want to get the value.
115
+
116
+ #### Example queries:
117
+
118
+ ##### 1. key=value parameter.
119
+
120
+ ```sql
121
+ SELECT
122
+ -- query is like "foo1=bar1&foo2=bar2&foo3=bar3"
123
+ splitquery(query, 'foo1') AS foo1,
124
+ splitquery(query, 'foo2') AS foo2,
125
+ splitquery(query, 'foo3') AS foo3
126
+ FROM access_log
127
+ ```
128
+
129
+ This query returns below.
130
+
131
+ ```javascript
132
+ {
133
+ "foo3":"bar3",
134
+ "foo2":"bar2",
135
+ "foo1":"bar1"
136
+ }
137
+ ```
138
+
139
+ ##### 2. key\[\]=values parameter.
140
+
141
+ ```sql
142
+ SELECT
143
+ -- query is like "foo[]=bar1&foo[]=bar2&foo[]=bar3"
144
+ splitquery(query, 'foo[]') AS foo
145
+ FROM access_log
146
+ ```
147
+
148
+ This query returns below.
149
+
150
+ ```javascript
151
+ {
152
+ "foo":[
153
+ "bar1",
154
+ "bar2",
155
+ "bar3"
156
+ ]
157
+ }
158
+ ```
159
+
160
+ ##### 3. Only key parameter.
161
+
162
+ ```sql
163
+ SELECT
164
+ -- query is like "test&foo1=bar1&foo2=bar2"
165
+ splitquery(query, 'test') AS test,
166
+ splitquery(query, 'other') AS other
167
+ FROM access_log
168
+ ```
169
+
170
+ This query returns below.
171
+
172
+ ```javascript
173
+ {
174
+ "other":null,
175
+ "test":""
176
+ }
177
+ ```
178
+
179
+ ## TODO
180
+
181
+ - Add method returns all query value as hash. (ex. `splitquery("foo=bar&buzz=123")` return `{"foo":"bar","buzz":123}`)
182
+
183
+ ## Contributing
184
+
185
+ 1. Fork it ( https://github.com/mia-0032/norikra-udf-uri_parser/fork )
186
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
187
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
188
+ 4. Push to the branch (`git push origin my-new-feature`)
189
+ 5. Create a new Pull Request
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]
Binary file
@@ -0,0 +1,55 @@
1
+ require 'cgi'
2
+ require 'java'
3
+ require 'uri'
4
+
5
+ java_package 'jp.ys.mia.norikra.udf'
6
+
7
+ class UriParser
8
+ @@elements = {
9
+ :scheme => 0,
10
+ :userinfo => 1,
11
+ :host => 2,
12
+ :port => 3,
13
+ :path => 5,
14
+ :opaque => 6,
15
+ :query => 7,
16
+ :fragment => 8
17
+ }
18
+
19
+ def self.split_uri(uri, element_key)
20
+ element_key = element_key.to_sym
21
+ unless @@elements.has_key?(element_key)
22
+ return nil
23
+ end
24
+
25
+ begin
26
+ parsed_uri = URI.split(uri)
27
+ rescue URI::InvalidURIError => e
28
+ return nil
29
+ end
30
+
31
+ result = parsed_uri[@@elements[element_key]]
32
+ if result.nil?
33
+ ''
34
+ else
35
+ result
36
+ end
37
+ end
38
+
39
+ def self.split_query(query_text, key)
40
+ query = CGI::parse(query_text)
41
+
42
+ unless query.has_key?(key)
43
+ return nil
44
+ end
45
+
46
+ case query[key].length
47
+ when 0 then
48
+ ''
49
+ when 1 then
50
+ query[key][0]
51
+ else
52
+ query[key]
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ require 'java'
2
+ require 'norikra/udf'
3
+
4
+ module Norikra
5
+ module UDF
6
+ class SplitUri < Norikra::UDF::SingleRow
7
+ def self.init
8
+ require 'norikra-udf-uri_parser.jar'
9
+ end
10
+
11
+ def definition
12
+ ["splituri", "jp.ys.mia.norikra.udf.UriParser", "split_uri"]
13
+ end
14
+ end
15
+
16
+ class SplitQuery < Norikra::UDF::SingleRow
17
+ def self.init
18
+ require 'norikra-udf-uri_parser.jar'
19
+ end
20
+
21
+ def definition
22
+ ["splitquery", "jp.ys.mia.norikra.udf.UriParser", "split_query"]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "norikra-udf-uri_parser"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Yoshihiro MIYAI"]
9
+ spec.email = ["msparrow17@gmail.com"]
10
+ spec.summary = %q{Norikra UDF splituri() and splitquery().}
11
+ spec.description = %q{Parse URI and query and return value specified key.}
12
+ spec.homepage = "https://github.com/mia-0032/norikra-udf-uri_parser"
13
+ spec.license = "GPL v2"
14
+
15
+ spec.platform = "java"
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib","jar"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ spec.add_runtime_dependency "norikra", "~> 1.0.8"
25
+ end
26
+
@@ -0,0 +1,64 @@
1
+ require 'norikra/udf_spec_helper'
2
+
3
+ include Norikra::UDFSpecHelper
4
+
5
+ require 'norikra/udf/uri_parser'
6
+
7
+ describe Norikra::UDF::SplitUri do
8
+ udf_function Norikra::UDF::SplitUri
9
+
10
+ it 'returns value corresponds to target element if url given' do
11
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "scheme")).to eql("http")
12
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "userinfo")).to eql("")
13
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "host")).to eql("example.com")
14
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "port")).to eql("")
15
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "path")).to eql("/hogehoge")
16
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "opaque")).to eql("")
17
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "query")).to eql("foo=bar")
18
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar#frgmt", "fragment")).to eql("frgmt")
19
+
20
+ expect(fcall(:splituri, "http://hoge-san:password@example.com/hogehoge?foo=bar", "userinfo")).to eql("hoge-san:password")
21
+ expect(fcall(:splituri, "http://example.com:80/hogehoge?foo=bar", "port")).to eql("80")
22
+ expect(fcall(:splituri, "mailto:nospam@localhost", "opaque")).to eql("nospam@localhost")
23
+ end
24
+
25
+ it 'returns value corresponds to target element if path given' do
26
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "scheme")).to eql("")
27
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "userinfo")).to eql("")
28
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "host")).to eql("")
29
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "port")).to eql("")
30
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "path")).to eql("/hogehoge")
31
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "opaque")).to eql("")
32
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "query")).to eql("foo=bar")
33
+ expect(fcall(:splituri, "/hogehoge?foo=bar", "fragment")).to eql("")
34
+ end
35
+
36
+ it 'returns nil if invalid element specified.' do
37
+ expect(fcall(:splituri, "http://example.com/hogehoge?foo=bar", "test")).to be_nil
38
+ end
39
+
40
+ it 'returns nil if invalid uri specified.' do
41
+ expect(fcall(:splituri, "http://example com/hogehoge?foo=bar", "host")).to be_nil
42
+ end
43
+ end
44
+
45
+ describe Norikra::UDF::SplitQuery do
46
+ udf_function Norikra::UDF::SplitQuery
47
+
48
+ it 'returns value corresponds to target key' do
49
+ expect(fcall(:splitquery, "hoge=foo", "hoge")).to eql("foo")
50
+ expect(fcall(:splitquery, "hoge1=foo&hoge2=bar", "hoge1")).to eql("foo")
51
+ expect(fcall(:splitquery, "hoge[]=foo&hoge[]=bar", "hoge[]")).to match_array(["foo", "bar"])
52
+ end
53
+
54
+ it 'returns nil if query does not contain target key' do
55
+ expect(fcall(:splitquery, "", "hoge")).to be_nil
56
+ expect(fcall(:splitquery, "hoge=foo", "hoge1")).to be_nil
57
+ expect(fcall(:splitquery, "hoge1=foo&hoge2=bar", "hoge3")).to be_nil
58
+ end
59
+
60
+ it 'returns empty string if target key does not have value' do
61
+ expect(fcall(:splitquery, "hoge", "hoge")).to eql('')
62
+ expect(fcall(:splitquery, "hoge1=foo&hoge2=bar&hoge3", "hoge3")).to eql('')
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norikra-udf-uri_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: java
6
+ authors:
7
+ - Yoshihiro MIYAI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 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: '10.0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '10.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: 3.1.0
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.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: 1.0.8
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.0.8
67
+ prerelease: false
68
+ type: :runtime
69
+ description: Parse URI and query and return value specified key.
70
+ email:
71
+ - msparrow17@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .ruby-version
78
+ - .travis.yml
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - jar/norikra-udf-uri_parser.jar
83
+ - java/.gitignore
84
+ - lib/esper_plugin/uri_parser.rb
85
+ - lib/norikra/udf/uri_parser.rb
86
+ - norikra-udf-uri_parser.gemspec
87
+ - spec/uri_parser_spec.rb
88
+ homepage: https://github.com/mia-0032/norikra-udf-uri_parser
89
+ licenses:
90
+ - GPL v2
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ - jar
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.1.9
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Norikra UDF splituri() and splitquery().
113
+ test_files:
114
+ - spec/uri_parser_spec.rb