ddl_parser 0.0.14 → 0.0.15

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/Vagrantfile CHANGED
@@ -1,9 +1,65 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- config.vm.box = 'thoughtbot/ubuntu-14-04-server-with-laptop'
9
- end
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # -----
5
+ $script = <<SCRIPT
6
+ set -e
7
+ set -x
8
+
9
+ cd
10
+ sudo apt-get update -y
11
+ sudo apt-get install \
12
+ git-core \
13
+ curl \
14
+ zlib1g-dev\
15
+ build-essential\
16
+ libssl-dev\
17
+ libreadline-dev\
18
+ libyaml-dev\
19
+ libsqlite3-dev\
20
+ sqlite3\
21
+ libxml2-dev\
22
+ libxslt1-dev\
23
+ libcurl4-openssl-dev\
24
+ python-software-properties \
25
+ -y 2> /dev/null
26
+
27
+ # install rbenv
28
+ rm -rf ~/.rbenv
29
+ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
30
+ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
31
+
32
+ # Setup rbenv paths
33
+ pathstring='export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/plugins/ruby-build/bin:$PATH"'
34
+ eval $pathstring
35
+ echo $pathstring >> ~/.bashrc
36
+
37
+ # Init rbenv
38
+ initstring='eval "\$(rbenv init -)"'
39
+ echo $initstring >> ~/.bashrc
40
+ eval $initstring
41
+
42
+ # install ruby
43
+ rbenv install 1.9.3-p194
44
+ rbenv global 1.9.3-p194
45
+ ruby -v
46
+ echo "gem: --no-ri --no-rdoc" > ~/.gemrc
47
+
48
+ # install gems
49
+ gem install bundler
50
+ rbenv rehash
51
+
52
+ SCRIPT
53
+ # -----
54
+
55
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
56
+ VAGRANTFILE_API_VERSION = "2"
57
+
58
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
59
+ config.vm.box = "ubuntu/trusty32"
60
+
61
+ if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id/*").empty?
62
+ config.vm.provision :shell, inline: $script, privileged: false
63
+ end
64
+
65
+ end
@@ -35,7 +35,7 @@ module DDLParser
35
35
 
36
36
  rule(:column_definition) { (column_name.as(:field) >> space.repeat >> data_type >> space.repeat >> (column_options.maybe).as(:options)).as(:column)}
37
37
 
38
- rule(:index_column_definition) { column_name.as(:field) >> (space? >> column_sort.as(:sort_id) >> space.repeat).maybe }
38
+ rule(:index_column_definition) { column_name.as(:field) >> (space? >> column_sort.as(:sort_type) >> space.repeat).maybe }
39
39
 
40
40
  rule(:element_list) { (lparen >> space? >> (column_definition | constraint | primary_key) >> space? >>
41
41
  (comma >> space? >> (column_definition | constraint | primary_key) >> space?).repeat >> rparen).as(:elements)
@@ -83,7 +83,7 @@ module DDLParser
83
83
  }
84
84
  # index options
85
85
 
86
- rule(:option_reverse_scans) { str('allow reverse scans') }
86
+ rule(:option_reverse_scans) { str('allow reverse scans').as(:reverse_scans_property)}
87
87
  rule(:index_option) { (option_reverse_scans).as(:index_option) }
88
88
 
89
89
  rule(:item) { function | identifier | string }
@@ -20,7 +20,7 @@ class DDLParser::Translator::CreateIndexColumn
20
20
  end
21
21
 
22
22
  def sort_type
23
- @index_column_hash[:sort_type]
23
+ @index_column_hash[:sort_type].to_s
24
24
  end
25
25
 
26
26
  end
@@ -6,7 +6,7 @@ class DDLParser::Translator::CreateIndexHeader
6
6
  def initialize(index_hash)
7
7
  if index_hash.is_a?(Hash) and index_hash.count > 1
8
8
  @index_head = index_hash
9
- @index_columns = [{:field =>index_hash[:field], :sort_id => index_hash[:sort_id]}]
9
+ @index_columns = [{:field =>index_hash[:field], :sort_type => index_hash[:sort_type]}]
10
10
  else
11
11
  if index_hash.is_a?(Array) and index_hash.count > 1
12
12
  @index_head = index_hash.first.is_a?(Hash) ? index_hash.first : {}
@@ -27,15 +27,11 @@ class DDLParser::Translator::CreateIndexHeader
27
27
  end
28
28
 
29
29
  def index_name
30
- @index_head[:index_name]
31
- end
32
-
33
- def index_table
34
- @index_head[:index_table]
30
+ @index_head[:index_name].to_s
35
31
  end
36
32
 
37
33
  def table_name
38
- @index_head[:table_name]
34
+ @index_head[:table_name].to_s
39
35
  end
40
36
 
41
37
  def object_property
@@ -43,7 +39,7 @@ class DDLParser::Translator::CreateIndexHeader
43
39
  end
44
40
 
45
41
  def option_reverse_scans
46
- @index_head[:option_reverse_scans]
42
+ index_head.has_key?(:index_option) && index_head[:index_option].has_key?(:reverse_scans_property) ? 'Y' : 'N'
47
43
  end
48
44
 
49
45
  def columns
@@ -1,3 +1,3 @@
1
1
  module DDLParser
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
@@ -51,19 +51,22 @@ EOF
51
51
  puts error.cause.ascii_tree
52
52
  end
53
53
 
54
- result.count.should == 6
55
- result.should include(:operation => 'create')
56
- result.should include(:object_property => 'unique')
57
- result.should include(:object_type => 'index')
58
- result.should include(:index_name => 'cost_invoice_1')
59
- result.should include(:table_name => 'cost_invoice')
60
- result.should include(:field => 'doc_no')
54
+ result.count.should == 3
55
+ result.is_a?(Array).should == true
56
+
57
+ result[0].should include(:operation => 'create')
58
+ result[0].should include(:object_property => 'unique')
59
+ result[0].should include(:object_type => 'index')
60
+ result[0].should include(:index_name => 'cost_invoice_1')
61
+ result[0].should include(:table_name => 'cost_invoice')
62
+ result[1].should include(:field => 'doc_no')
63
+ result[2].should include(:field => 'doc_no_1')
61
64
  end
62
65
  end
63
66
  context 'element list index' do
64
67
  it 'parses one element' do
65
68
  sql = 'deptno asc'
66
- parser.element_list_index.parse(sql).should == {:field=> 'deptno',:sort_id=> 'asc'}
69
+ parser.element_list_index.parse(sql).should == {:field=> 'deptno',:sort_type=> 'asc'}
67
70
  end
68
71
  it 'parses two element' do
69
72
  sql = 'field1, field2'
@@ -77,8 +80,8 @@ EOF
77
80
  DEPTNO desc,
78
81
  DEPTNAME asc
79
82
  EOF
80
- parser.element_list_index.parse(sql.downcase).should == [{:field=> 'deptno',:sort_id=> 'desc'},
81
- {:field=> 'deptname',:sort_id=> 'asc'}]
83
+ parser.element_list_index.parse(sql.downcase).should == [{:field=> 'deptno',:sort_type=> 'desc'},
84
+ {:field=> 'deptname',:sort_type=> 'asc'}]
82
85
  end
83
86
  end
84
87
  context 'index column definition' do
@@ -93,7 +96,7 @@ EOF
93
96
  sql = <<EOF
94
97
  DEPTNO descending
95
98
  EOF
96
- parser.index_column_definition.parse(sql.downcase).should == {:field=> 'deptno',:sort_id=> 'descending'}
99
+ parser.index_column_definition.parse(sql.downcase).should == {:field=> 'deptno',:sort_type=> 'descending'}
97
100
 
98
101
  end
99
102
  end
@@ -103,7 +106,7 @@ EOF
103
106
  end
104
107
  it 'parses index_option with reverse scans' do
105
108
  sql = 'allow reverse scans'
106
- parser.index_option.parse(sql).should include(:index_option => 'allow reverse scans')
109
+ parser.index_option.parse(sql).should include(:index_option => {:reverse_scans_property=>"allow reverse scans"})
107
110
  end
108
111
  end
109
112
  context 'create_index_statement' do
@@ -141,7 +144,7 @@ EOF
141
144
  end
142
145
  end
143
146
  context 'full index example with reverse scan option' do
144
- it 'with reverse scan' do
147
+ it 'with reverse scan 1' do
145
148
  sql = <<EOF
146
149
  CREATE UNIQUE INDEX COST_INVOICE_1
147
150
  ON COST_INVOICE
@@ -160,7 +163,7 @@ EOF
160
163
  result.should include(:index_name => 'cost_invoice_1')
161
164
  result.should include(:table_name => 'cost_invoice')
162
165
  result.should include(:field => 'doc_no')
163
- result.should include(:index_option => 'allow reverse scans')
166
+ result.should include(:index_option => {:reverse_scans_property=>"allow reverse scans"})
164
167
 
165
168
  end
166
169
  it 'without reverse scan' do
@@ -182,6 +185,28 @@ EOF
182
185
  result.should include(:table_name => 'cost_invoice')
183
186
  result.should include(:field => 'doc_no')
184
187
 
188
+ end
189
+ it 'with reverse scan 2' do
190
+ sql = <<EOF
191
+ CREATE INDEX PL_TRIGGER_I2
192
+ ON PL_TRIGGER
193
+ (UNIQUE_NO)
194
+ ALLOW REVERSE SCANS
195
+ EOF
196
+ begin
197
+ result = parser.parse(sql.downcase)
198
+ rescue Parslet::ParseFailed => error
199
+ puts error.cause.ascii_tree
200
+ end
201
+ result.count.should == 6
202
+ result.should include(:operation => 'create')
203
+ result.should include(:object_type => 'index')
204
+ result.should include(:index_name => 'pl_trigger_i2')
205
+ result.should include(:table_name => 'pl_trigger')
206
+ result.should include(:field => 'unique_no')
207
+ result.should include(:index_option => {:reverse_scans_property=>"allow reverse scans"})
208
+
209
+
185
210
  end
186
211
  it 'live example' do
187
212
  sql = <<EOF
@@ -59,7 +59,7 @@ describe 'DDLParser::Parser' do
59
59
  end
60
60
  end
61
61
 
62
- context 'alter table translate' do
62
+ context 'alter table add column translate' do
63
63
  let(:sql) {
64
64
  sql = <<EOF
65
65
  ALTER TABLE BUDGET
@@ -75,7 +75,7 @@ EOF
75
75
  end
76
76
 
77
77
 
78
- it 'translate columns' do
78
+ it 'translate columns xxx' do
79
79
  parser = DDLParser::Parser.new(sql)
80
80
  parser.translate.add_columns.map(&:to_hash).should == [{:field=> 'budget_amount_in_co',
81
81
  :data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}, :scale=>{:integer=> '2'}}}},
@@ -106,11 +106,11 @@ EOF
106
106
  @parser.translate.index_name.should == 'replan_addr_1'
107
107
  end
108
108
  it 'columns' do
109
- @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_id=>"ascending"}, {:field=>"colli", :sort_id=>"descending"}]
109
+ @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_type=>"ascending"}, {:field=>"colli", :sort_type=>"descending"}]
110
110
  end
111
111
 
112
112
  end
113
- context 'create index translate one index column' do
113
+ context 'create index translate one index column allow not reverse scans' do
114
114
  before :each do
115
115
  sql = 'CREATE UNIQUE INDEX REPLAN_ADDR_1 ON REPLAN_ADDR (CONSIGNMENT ASCENDING)'
116
116
  @parser = DDLParser::Parser.new(sql)
@@ -123,11 +123,32 @@ EOF
123
123
  @parser.translate.index_name.should == 'replan_addr_1'
124
124
  end
125
125
  it 'columns' do
126
- @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_id=>"ascending"}]
126
+ @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_type=>"ascending"}]
127
+ end
128
+
129
+ it 'allow not reverse scans 1' do
130
+ @parser.translate.option_reverse_scans.should == 'N'
127
131
  end
128
132
 
129
133
  end
134
+ context 'create index translate one index column allow reverse scans' do
135
+ before :each do
136
+ sql = 'CREATE UNIQUE INDEX REPLAN_ADDR_1 ON REPLAN_ADDR (CONSIGNMENT ASCENDING) ALLOW REVERSE SCANS'
137
+ @parser = DDLParser::Parser.new(sql)
138
+ end
139
+
140
+ it 'table name' do
141
+ @parser.translate.table_name.should == 'replan_addr'
142
+ end
143
+ it 'index name' do
144
+ @parser.translate.index_name.should == 'replan_addr_1'
145
+ end
146
+
147
+ it 'allow reverse scans 1' do
148
+ @parser.translate.option_reverse_scans.should == 'Y'
149
+ end
130
150
 
151
+ end
131
152
  context 'report errors' do
132
153
  it 'misses right parant' do
133
154
  sql = "Create table USER (FOO CHAR(4) NOT NULL, BAR CHAR(4) NOT NULL"
@@ -31,10 +31,9 @@ end
31
31
 
32
32
  it 'should return name' do
33
33
  unique_no_column.index_name.should == 'test_index'
34
- unique_no_column.index_table.should == 'on test_table'
35
34
  unique_no_column.table_name.should == 'test_table'
36
35
  unique_no_column.object_property.should == 'unique'
37
- unique_no_column.option_reverse_scans.should == 'allow reverse scans'
36
+ unique_no_column.option_reverse_scans.should == 'N'
38
37
  end
39
38
 
40
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddl_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-25 00:00:00.000000000 Z
12
+ date: 2014-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet