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 +4 -4
- data/VERSION +1 -1
- data/hipster_sql_to_hbase.gemspec +1 -1
- data/lib/sql_parser/sql.treetop +3 -1
- data/lib/sql_parser/sql_insert.treetop +0 -1
- data/lib/sql_parser/sql_row_support.treetop +5 -16
- data/lib/sql_parser/sql_select.treetop +16 -7
- data/lib/sql_parser/sql_update.treetop +48 -64
- data/spec/hipster_sql_to_hbase_spec.rb +20 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a64e4c9a48c5328824939eb0c1e2f9298e8154c
|
4
|
+
data.tar.gz: 285e51b8f9508b1e657e9e6bbecca9c033a6291a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff411219b4f4e9508346ead60e19bfb22905005584db758f1e16911755acfa3536e5995f478b587731704bf32e59516f3ab24f7efd496f7cc09358305bd945bd
|
7
|
+
data.tar.gz: f13efc205066e78011bc4e35728fcb5be5bb3126d5449b26853b01e9c284611c85e367ac376a41766e5d6830a4f2ecdcda0c33460279471aa58c063f06c95c39
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/sql_parser/sql.treetop
CHANGED
@@ -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
|
@@ -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
|
-
|
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
|
-
|
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 =>
|
103
|
+
:column => one_column_name.eval,
|
115
104
|
:alias_hash => {
|
116
|
-
:column =>
|
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
|
-
|
28
|
-
result[:
|
29
|
-
|
30
|
-
|
31
|
-
result[:
|
32
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
2
|
+
include SQLRowSupport
|
3
|
+
include SQLWhereCondition
|
4
|
+
include SQLOrderByClause
|
5
|
+
include SQLLimit
|
6
|
+
include SQLHelpers
|
6
7
|
|
7
8
|
rule update
|
8
|
-
"UPDATE"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
+
def tree
|
18
|
+
result = {
|
19
|
+
:update => table_name.eval,
|
20
|
+
:set => col_val_pairs.eval
|
21
|
+
}
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
30
|
-
|
31
|
-
def
|
32
|
-
|
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
|
-
|
45
|
+
col_val_pair
|
37
46
|
end
|
38
|
-
|
39
|
-
rule
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
57
|
-
"
|
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
|
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].
|
75
|
-
response[:query_hash][:limit].
|
76
|
-
response[:query_hash][:order].
|
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].
|
92
|
-
response[:query_hash][:limit].
|
93
|
-
response[:query_hash][:order].
|
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].
|
109
|
-
response[:query_hash][:limit].
|
110
|
-
response[:query_hash][:order].
|
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.
|
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.
|
168
|
+
expect(response).to be_nil
|
171
169
|
end
|
172
170
|
end
|
173
171
|
|