mohair 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -45,9 +45,10 @@ $ bundle exec bin/mohair -q "select * from sometable"
45
45
 
46
46
  ## TODO
47
47
 
48
- - group by
49
48
  - limit 10
50
49
  - asc/desc
50
+ - types: timestamp, float
51
+ - recursive representation of json with dot notation
51
52
  - 2i
52
53
  - query optimization
53
54
 
@@ -60,5 +61,5 @@ $ bundle exec bin/mohair -q "select * from sometable"
60
61
  5. Create new Pull Request
61
62
 
62
63
  ```
63
- $ bundle exec rake release
64
+ $ rake release
64
65
  ```
@@ -10,14 +10,14 @@ require "optparse"
10
10
  require "logger"
11
11
 
12
12
  LOG = Logger.new(STDERR)
13
- LOG.level = Logger::DEBUG # WARN, INFO, DEBUG, ...
13
+ LOG.level = Logger::INFO # WARN, INFO, DEBUG, ...
14
14
 
15
15
  module Mohair
16
16
 
17
17
  def self.usage
18
18
  print <<EOS
19
19
  usage:
20
- $ mohair -q "select foo, bar from bucket_name" [-i INDEX]
20
+ $ mohair -q "select foo, bar from bucket_name" [-i INDEX] [-s SERVER]
21
21
  $ mohair_dump <bucket_name> < sample_data.json
22
22
 
23
23
  insert, delete sentence is future work
@@ -30,13 +30,24 @@ EOS
30
30
 
31
31
  q = nil #query!!
32
32
  index = nil
33
+ host = 'localhost'
34
+ port = 8098
33
35
 
34
36
  opt = OptionParser.new
37
+ opt.on('-h', '--help'){ usage }
38
+ opt.on('-d', '--debug'){
39
+ LOG.level = Logger::DEBUG
40
+ }
41
+ opt.on('-v', '--version'){ usage }
35
42
  opt.on('-q Q'){|v| q = v}
36
43
  opt.on('-i INDEX'){|v| index = v}
37
- opt.on('-h', '--help'){ usage }
44
+ opt.on('-s SERVER'){|v|
45
+ host, port = v.split(':')
46
+ }
38
47
 
39
48
  opt.parse!(ARGV)
49
+
50
+ LOG.info("connecting #{host}:#{port}")
40
51
 
41
52
  parser = Sql::Parser.new
42
53
  sql_syntax_tree = parser.parse (q.strip)
@@ -52,7 +63,8 @@ EOS
52
63
  LOG.debug "reducer->\n"
53
64
  LOG.debug s.reducer
54
65
 
55
- client = Riak::Client.new(:protocol => "http")
66
+ client = Riak::Client.new(:protocol => "http",
67
+ :nodes => [{:host => host, :http_port => port}])
56
68
  bucket = Riak::MapReduce.new(client)
57
69
  .add(client.bucket(s.bucket))## keyfilsters and so on here
58
70
 
@@ -7,7 +7,9 @@ module Mohair
7
7
  @bucket_name = bucket_name
8
8
  end
9
9
  def insert_all objs
10
- @client = Riak::Client.new(:protocol => "http")
10
+ @client = Riak::Client.new(:protocol => "http",
11
+ :nodes => [
12
+ {:http_port => 10018}])
11
13
  bucket = @client.bucket(@bucket_name)
12
14
  if bucket.props["allow_mult"] then
13
15
  $stderr.puts "allow_mult should be false (how to handle siblilngs?)"
@@ -48,6 +48,7 @@ function(v){
48
48
  ret.__key = key;
49
49
  <%= where %>
50
50
  };
51
+ //ejsLog('/tmp/map_reduce.log', JSON.stringify(v))
51
52
  var raw_obj = JSON.parse(v.values[0].data);
52
53
  if(raw_obj instanceof Array){
53
54
  var ret0 = [];
@@ -6,7 +6,8 @@ module Mohair
6
6
  module Sql
7
7
  class Parser < Parslet::Parser
8
8
  rule(:integer) { match('[0-9]').repeat(1) }
9
- #rule(:float) { integer.repeat >> str('.') >> integer.maybe }
9
+ rule(:float) { integer.repeat >> str('.') >> integer.maybe }
10
+ #rule(:numeric) { integer | float | (str('-') >> numeric) }
10
11
 
11
12
  rule(:space) { match('\s').repeat(1) }
12
13
  rule(:space?) { space.maybe }
@@ -25,10 +26,17 @@ module Mohair
25
26
  #rule(:like) { str('like') >> space? }
26
27
  rule(:binop) { eq | neq | gt | lt | geq | leq | btw}
27
28
 
28
- rule(:string) { str('"') >> match('[a-zA-Z0-9]').repeat >> str('"') }
29
+ rule(:string) {
30
+ str('"') >>
31
+ (
32
+ str('\\') >> any |
33
+ str('"').absent? >> any
34
+ ).repeat >>
35
+ str('"')
36
+ }
29
37
 
30
38
  rule(:const) {
31
- integer | string
39
+ integer | float | string
32
40
  }
33
41
  rule(:term) { const | item }
34
42
 
@@ -6,7 +6,9 @@ module Mohair
6
6
  @select = build_columns tree[:select]
7
7
  @from = From.new tree[:from]
8
8
  @where = Where.new tree[:where]
9
- @group_by = Group.new tree[:group_by]
9
+ if tree[:group_by] then
10
+ @group_by = Group.new tree[:group_by]
11
+ end
10
12
  @agg = false
11
13
  end
12
14
 
@@ -110,43 +110,35 @@ module Mohair
110
110
  rhs = tree[:rhs]
111
111
  @op = tree[:op].to_s
112
112
 
113
- if lhs.class == Hash then
114
- @lhs = Condition.new lhs
115
- elsif (lhs.to_s =~ /^[0-9]+$/).nil? then
116
- @lhs = lhs.to_s
113
+ @lhs = objectize lhs
114
+ @rhs = objectize rhs
115
+ end
116
+
117
+ def objectize s
118
+ if s.class == Hash then
119
+ Condition.new s
120
+ elsif (s.to_s =~ /^[0-9]+$/).nil? then
121
+ s.to_s
117
122
  else
118
- @lhs = lhs.to_i
123
+ s.to_i
119
124
  end
125
+ end
120
126
 
121
- if rhs.class == Hash then
122
- @rhs = Condition.new rhs
123
- elsif (rhs.to_s =~ /^[0-9]+$/).nil? then
124
- @rhs = rhs.to_s
127
+ def jstify o
128
+ if o.class == Fixnum then
129
+ o
130
+ elsif o.class == Condition then
131
+ "( #{o.to_js} )"
132
+ elsif (o[0] == "\"" and o[-1] == "\"") then
133
+ o
125
134
  else
126
- @rhs = rhs.to_i
135
+ "obj.#{o}"
127
136
  end
128
137
  end
129
138
 
130
139
  def to_js
131
- lhs = rhs = nil
132
- if @rhs.class == Fixnum then
133
- rhs = @rhs
134
- elsif @rhs.class == Condition then
135
- rhs = "( #{@rhs.to_js} )"
136
- elsif (@rhs[0] == "\"" and @rhs[-1] == "\"") then
137
- rhs = @rhs
138
- else
139
- rhs = "obj.#{@rhs}"
140
- end
141
- if @lhs.class == Fixnum then
142
- lhs = @lhs
143
- elsif @lhs.class == Condition then
144
- lhs = "( #{@lhs.to_js} )"
145
- elsif (@lhs[0] == "\"" and @lhs[-1] == "\"") then
146
- lhs = @lhs
147
- else
148
- lhs = "obj.#{@lhs}"
149
- end
140
+ lhs = jstify @lhs
141
+ rhs = jstify @rhs
150
142
  " (#{lhs}) #{operator2str(@op)} (#{rhs}) "
151
143
  end
152
144
 
@@ -1,3 +1,3 @@
1
1
  module Mohair
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -30,6 +30,7 @@ class ParserTest < MiniTest::Unit::TestCase
30
30
  [
31
31
  'select',
32
32
  ' select a from b',
33
+ 'select a, b from c where a = "120.0, ~!@#$%^&*+_\}{\" asdfa"sf"',
33
34
  ].each do |bad_sql|
34
35
  assert_raises Parslet::ParseFailed do
35
36
  @parser.parse bad_sql
@@ -45,6 +46,10 @@ class ParserTest < MiniTest::Unit::TestCase
45
46
  'select a,b from c where 20 < a or b = 234',
46
47
  'select a, b from c where a = "oo"',
47
48
  'select a, b from c where a = "oo" and c > 235',
49
+ 'select a, b from c where a = "120.0, ~!@#$%^&*+_\}{\" asdfasf"',
50
+ #'select a from b where a > 20.0',
51
+ #'select a from b where a > 0.0',
52
+ #'select a from b where a > -0',
48
53
  ].each do |where_sql|
49
54
  s = @parser.parse where_sql
50
55
  assert_equal(expected = "select", actual = s[:op])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mohair
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - UENISHI Kota
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-25 00:00:00 Z
18
+ date: 2013-06-01 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: a new type of Riak client