hipster_sql_to_hbase 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8f7de19de530e43d65fbb34022c20b589158c99
4
- data.tar.gz: 2f618ebe82db8ccc67f78a35448c981a50f1b97b
3
+ metadata.gz: 2a64e4c9a48c5328824939eb0c1e2f9298e8154c
4
+ data.tar.gz: 285e51b8f9508b1e657e9e6bbecca9c033a6291a
5
5
  SHA512:
6
- metadata.gz: af120d262c539e082624bf1af5addbdbc8e29dbfd01162530585ba30ffc88ee54e2b1d643d17b2c907b6e932ade7587e4b539adaf73e5c9cb29a4db09eec8acc
7
- data.tar.gz: 41223aa5cd25db917af38b0cc4766a4716a6026a21f44e9449ec1b959820fddc1243ec395992fd69bc9646047bb4c37c1439e3846c9254bad6addbbda2b7103d
6
+ metadata.gz: ff411219b4f4e9508346ead60e19bfb22905005584db758f1e16911755acfa3536e5995f478b587731704bf32e59516f3ab24f7efd496f7cc09358305bd945bd
7
+ data.tar.gz: f13efc205066e78011bc4e35728fcb5be5bb3126d5449b26853b01e9c284611c85e367ac376a41766e5d6830a4f2ecdcda0c33460279471aa58c063f06c95c39
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hipster_sql_to_hbase"
5
- s.version = "0.2.2"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jean Lescure"]
@@ -9,6 +9,7 @@ grammar SQL
9
9
  include SQLShowCreate
10
10
  include SQLCreateTable
11
11
  include SQLCreateIndex
12
+ include SQLUpdate
12
13
 
13
14
  rule sql_statement
14
15
  select_expression /
@@ -20,6 +21,7 @@ grammar SQL
20
21
  show_tables /
21
22
  show_create /
22
23
  create_table /
23
- create_index
24
+ create_index /
25
+ update
24
26
  end
25
27
  end
@@ -1,5 +1,4 @@
1
1
  grammar SQLInsert
2
- include SQLPrimitives
3
2
  include SQLRowSupport
4
3
  include SQLHelpers
5
4
 
@@ -4,7 +4,8 @@ grammar SQLRowSupport
4
4
  rule one_or_more_table_names
5
5
  table_name COMMA SPACES one_or_more_table_names {
6
6
  def eval
7
- [table_name.eval, one_or_more_table_names.eval]
7
+ result1, result2 = table_name.eval, one_or_more_table_names.eval
8
+ [result1, result2].flatten
8
9
  end
9
10
  }
10
11
  /
@@ -96,24 +97,12 @@ grammar SQLRowSupport
96
97
  end
97
98
 
98
99
  rule one_column_name_with_alias
99
- table_name DOT column_name SPACES "AS" SPACES alias_column_name {
100
- def eval
101
- {
102
- :column => column_name.eval,
103
- :alias_hash => {
104
- :column => column_name.eval,
105
- :alias => alias_column_name.eval
106
- }
107
- }
108
- end
109
- }
110
- /
111
- column_name SPACES "AS" SPACES alias_column_name {
100
+ one_column_name SPACES "AS" SPACES alias_column_name {
112
101
  def eval
113
102
  {
114
- :column => column_name.eval,
103
+ :column => one_column_name.eval,
115
104
  :alias_hash => {
116
- :column => column_name.eval,
105
+ :column => one_column_name.eval,
117
106
  :alias => alias_column_name.eval
118
107
  }
119
108
  }
@@ -12,8 +12,8 @@ grammar SQLSelect
12
12
  select
13
13
  from_or_empty
14
14
  where_tree
15
- limit_condition_or_empty
16
15
  order_by_condition_or_empty
16
+ limit_condition_or_empty
17
17
  {
18
18
  def query_type
19
19
  :select
@@ -24,16 +24,25 @@ grammar SQLSelect
24
24
 
25
25
  selectables = select.eval
26
26
 
27
- result[:limit] = limit_condition_or_empty.eval unless limit_condition_or_empty.eval.nil?
28
- result[:order_by] = order_by_condition_or_empty.eval unless order_by_condition_or_empty.eval.nil?
29
- result[:from] = from_or_empty.tables if defined? from_or_empty.tables
30
- result[:where] = where_tree.eval unless where_tree.eval.nil?
31
- result[:columns] = selectables[:columns] unless selectables[:columns].nil?
32
- result[:numbers] = selectables[:numbers] unless selectables[:numbers].nil?
27
+ where_tree_val = where_tree.eval
28
+ result[:where] = where_tree_val unless where_tree_val.nil?
29
+
30
+ order_by_val = order_by_condition_or_empty.eval
31
+ result[:order_by] = order_by_val unless order_by_val.nil?
32
+
33
+ limit_val = limit_condition_or_empty.eval
34
+ result[:limit] = limit_val unless limit_val.nil?
35
+
36
+ result[:select] = selectables unless all_selectables_nil?(selectables)
33
37
  result[:aliases] = selectables[:aliases] unless selectables[:aliases].nil?
38
+ result[:from] = from_or_empty.tables if defined? from_or_empty.tables
34
39
 
35
40
  result
36
41
  end
42
+
43
+ def all_selectables_nil?(selectables)
44
+ selectables[:columns].nil? && selectables[:numbers].nil?
45
+ end
37
46
  }
38
47
  end
39
48
  end
@@ -1,82 +1,66 @@
1
1
  grammar SQLUpdate
2
-
3
- rule parts
4
- update / simple_where_clause / assignment_list / assignment / quoted_string / text / identifier
5
- end
2
+ include SQLRowSupport
3
+ include SQLWhereCondition
4
+ include SQLOrderByClause
5
+ include SQLLimit
6
+ include SQLHelpers
6
7
 
7
8
  rule update
8
- "UPDATE" space identifier space "SET" space assignment_list space simple_where_clause {
9
- def table_name
10
- identifier.text_value
11
- end
12
- def id
13
- simple_where_clause.id
14
- end
15
- def items
16
- assignment_list.items
9
+ "UPDATE" SPACES (low_priority SPACES)? (ignore SPACES)? table_name SPACES
10
+ "SET" SPACES col_val_pairs
11
+ where_tree
12
+ order_by_condition_or_empty
13
+ limit_condition_or_empty {
14
+ def query_type
15
+ :update
17
16
  end
18
- }
19
- end
17
+ def tree
18
+ result = {
19
+ :update => table_name.eval,
20
+ :set => col_val_pairs.eval
21
+ }
20
22
 
21
- rule simple_where_clause
22
- "WHERE" space identifier space "=" space quoted_string {
23
- def id
24
- quoted_string.text_value
23
+ where_tree_val = where_tree.eval
24
+ result[:where] = where_tree_val unless where_tree_val.nil?
25
+
26
+ order_by_val = order_by_condition_or_empty.eval
27
+ result[:order_by] = order_by_val unless order_by_val.nil?
28
+
29
+ limit_val = limit_condition_or_empty.eval
30
+ result[:limit] = limit_val unless limit_val.nil?
31
+
32
+ result
25
33
  end
26
34
  }
27
35
  end
28
-
29
- rule assignment_list
30
- a1:assignment space "," space a2:assignment_list {
31
- def items
32
- a1.items.merge(a2.items)
36
+
37
+ rule col_val_pairs
38
+ col_val_pair optional_spaces COMMA optional_spaces col_val_pairs {
39
+ def eval
40
+ result1, result2 = col_val_pair.eval, col_val_pairs.eval
41
+ [result1,result2].flatten
33
42
  end
34
43
  }
35
44
  /
36
- assignment
45
+ col_val_pair
37
46
  end
38
-
39
- rule assignment
40
- identifier space "=" space quoted_string {
41
-
42
- def items
43
- { key => value }
44
- end
45
-
46
- def key
47
- identifier.text_value
48
- end
49
-
50
- def value
51
- quoted_string.text_value
47
+
48
+ rule col_val_pair
49
+ one_column_name optional_spaces "=" optional_spaces simple_primitive {
50
+ def eval
51
+ [{
52
+ :column => one_column_name.eval,
53
+ :value => simple_primitive.eval
54
+ }]
52
55
  end
53
56
  }
54
57
  end
55
-
56
- rule quoted_string
57
- "'" text "'" {
58
- def text_value
59
- text.text_value
60
- end
61
- }
62
- /
63
- "''" {
64
- def text_value
65
- ""
66
- end
67
- }
58
+
59
+ rule low_priority
60
+ "LOW_PRIORITY"
68
61
  end
69
-
70
- rule text
71
- ( "''" / !"'" . )+
72
- end
73
-
74
- rule identifier
75
- (!("'" / "=" / " ") .)+
62
+
63
+ rule ignore
64
+ "IGNORE"
76
65
  end
77
-
78
- rule space
79
- ' '*
80
- end
81
-
82
66
  end
@@ -3,8 +3,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'sql_sentence_types'))
3
3
 
4
4
  require 'spec_helper'
5
5
 
6
-
7
-
8
6
  describe "HipsterSqlToHbase.parse_syntax method" do
9
7
 
10
8
  context "when parse_syntax is run against SELECT FROM query without table hierarchy or backticks" do
@@ -66,14 +64,14 @@ describe "HipsterSqlToHbase.parse_tree method" do
66
64
  expect(response.class).to eq(HipsterSqlToHbase::ResultTree)
67
65
  expect(response[:query_type]).to eq(:select)
68
66
  expect(response[:query_hash].class).to eq(Hash)
69
- expect(response[:query_hash][:columns].class).to eq(Array)
70
- expect(response[:query_hash][:columns].length).to eq(1)
71
- expect(response[:query_hash][:columns][0]).to eq('user')
67
+ expect(response[:query_hash][:select][:columns].class).to eq(Array)
68
+ expect(response[:query_hash][:select][:columns].length).to eq(1)
69
+ expect(response[:query_hash][:select][:columns][0]).to eq('user')
72
70
  expect(response[:query_hash][:from].class).to eq(Array)
73
71
  expect(response[:query_hash][:from][0]).to eq('users')
74
- response[:query_hash][:where].should be_nil
75
- response[:query_hash][:limit].should be_nil
76
- response[:query_hash][:order].should be_nil
72
+ expect(response[:query_hash][:where]).to be_nil
73
+ expect(response[:query_hash][:limit]).to be_nil
74
+ expect(response[:query_hash][:order]).to be_nil
77
75
  end
78
76
  end
79
77
 
@@ -83,14 +81,14 @@ describe "HipsterSqlToHbase.parse_tree method" do
83
81
  expect(response.class).to eq(HipsterSqlToHbase::ResultTree)
84
82
  expect(response[:query_type]).to eq(:select)
85
83
  expect(response[:query_hash].class).to eq(Hash)
86
- expect(response[:query_hash][:columns].class).to eq(Array)
87
- expect(response[:query_hash][:columns].length).to eq(1)
88
- expect(response[:query_hash][:columns][0]).to eq('user')
84
+ expect(response[:query_hash][:select][:columns].class).to eq(Array)
85
+ expect(response[:query_hash][:select][:columns].length).to eq(1)
86
+ expect(response[:query_hash][:select][:columns][0]).to eq('user')
89
87
  expect(response[:query_hash][:from].class).to eq(Array)
90
88
  expect(response[:query_hash][:from][0]).to eq('users')
91
- response[:query_hash][:where].should be_nil
92
- response[:query_hash][:limit].should be_nil
93
- response[:query_hash][:order].should be_nil
89
+ expect(response[:query_hash][:where]).to be_nil
90
+ expect(response[:query_hash][:limit]).to be_nil
91
+ expect(response[:query_hash][:order]).to be_nil
94
92
  end
95
93
  end
96
94
 
@@ -100,14 +98,14 @@ describe "HipsterSqlToHbase.parse_tree method" do
100
98
  expect(response.class).to eq(HipsterSqlToHbase::ResultTree)
101
99
  expect(response[:query_type]).to eq(:select)
102
100
  expect(response[:query_hash].class).to eq(Hash)
103
- expect(response[:query_hash][:columns].class).to eq(Array)
104
- expect(response[:query_hash][:columns].length).to eq(1)
105
- expect(response[:query_hash][:columns][0]).to eq('user')
101
+ expect(response[:query_hash][:select][:columns].class).to eq(Array)
102
+ expect(response[:query_hash][:select][:columns].length).to eq(1)
103
+ expect(response[:query_hash][:select][:columns][0]).to eq('user')
106
104
  expect(response[:query_hash][:from].class).to eq(Array)
107
105
  expect(response[:query_hash][:from][0]).to eq('users')
108
- response[:query_hash][:where].should be_nil
109
- response[:query_hash][:limit].should be_nil
110
- response[:query_hash][:order].should be_nil
106
+ expect(response[:query_hash][:where]).to be_nil
107
+ expect(response[:query_hash][:limit]).to be_nil
108
+ expect(response[:query_hash][:order]).to be_nil
111
109
  end
112
110
  end
113
111
 
@@ -156,7 +154,7 @@ describe "HipsterSqlToHbase.parse_tree method" do
156
154
  context "when query is only a lower-case 'select'" do
157
155
  let(:response) { HipsterSqlToHbase.parse_tree("select") }
158
156
  it "does not succeed" do
159
- response.should be_nil
157
+ expect(response).to be_nil
160
158
  end
161
159
  end
162
160
 
@@ -167,7 +165,7 @@ describe "HipsterSqlToHbase.parse method" do
167
165
  context "when query is only a lower-case 'select'" do
168
166
  let(:response) { HipsterSqlToHbase.parse("select") }
169
167
  it "does not succeed" do
170
- response.should be_nil
168
+ expect(response).to be_nil
171
169
  end
172
170
  end
173
171
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hipster_sql_to_hbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Lescure