flydata 0.6.4 → 0.6.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +2 -0
  4. data/VERSION +1 -1
  5. data/flydata-core/lib/flydata-core/table_def/base.rb +31 -0
  6. data/flydata-core/lib/flydata-core/table_def/mysql_table_def.rb +9 -30
  7. data/flydata-core/lib/flydata-core/table_def/postgresql_table_def.rb +111 -0
  8. data/flydata-core/lib/flydata-core/table_def/redshift_table_def.rb +4 -1
  9. data/flydata-core/spec/table_def/postgresql_table_def_spec.rb +348 -0
  10. data/flydata-core/spec/table_def/redshift_table_def_spec.rb +25 -0
  11. data/flydata.gemspec +0 -0
  12. data/lib/flydata.rb +0 -7
  13. data/lib/flydata/command/base.rb +3 -2
  14. data/lib/flydata/fluent-plugins/flydata_plugin_ext/base.rb +5 -0
  15. data/lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb +52 -0
  16. data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync.rb +55 -0
  17. data/lib/flydata/fluent-plugins/{idle_event_detector.rb → flydata_plugin_ext/idle_event_detector.rb} +0 -0
  18. data/lib/flydata/fluent-plugins/{preference.rb → flydata_plugin_ext/preference.rb} +2 -14
  19. data/lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb +58 -0
  20. data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +55 -135
  21. data/lib/flydata/fluent-plugins/mysql/dml_record_handler.rb +9 -4
  22. data/lib/flydata/helper/server.rb +7 -0
  23. data/lib/flydata/preference/data_entry_preference.rb +5 -13
  24. data/lib/flydata/source.rb +1 -1
  25. data/lib/flydata/source/data_entry.rb +29 -0
  26. data/lib/flydata/source/sync.rb +19 -0
  27. data/lib/flydata/source/sync_generate_table_ddl.rb +47 -7
  28. data/lib/flydata/source_mysql/data_entry.rb +22 -0
  29. data/lib/flydata/source_mysql/parser/dump_parser.rb +1 -1
  30. data/lib/flydata/source_mysql/parser/mysql_alter_table.treetop +8 -3
  31. data/lib/flydata/source_mysql/sync.rb +1 -8
  32. data/lib/flydata/source_mysql/sync_generate_table_ddl.rb +11 -16
  33. data/lib/flydata/source_postgresql/data_entry.rb +21 -0
  34. data/lib/flydata/source_postgresql/sync.rb +29 -0
  35. data/lib/flydata/source_postgresql/sync_generate_table_ddl.rb +126 -0
  36. data/spec/flydata/fluent-plugins/{idle_event_detector_spec.rb → flydata_plugin_ext/idle_event_detector_spec.rb} +1 -1
  37. data/spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb +10 -0
  38. data/spec/flydata/source_mysql/parser/alter_table_parser_spec.rb +119 -0
  39. data/spec/flydata/source_mysql/parser/dump_parser_spec.rb +32 -1
  40. data/spec/flydata/source_mysql/sync_generate_table_ddl_spec.rb +4 -4
  41. metadata +31 -5
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'fluent_plugins_spec_helper'
4
- require 'idle_event_detector'
4
+ require 'flydata_plugin_ext/idle_event_detector'
5
5
  require 'timecop'
6
6
 
7
7
  module Fluent
@@ -16,6 +16,7 @@ module Fluent
16
16
  TEST_TABLE_BINLOG_POS = File.join(FLYDATA_HOME, "positions/#{TEST_TABLE}.binlog.pos")
17
17
  TEST_TABLES = "#{TEST_TABLE},test_table_1,test_table_2,test_table_3"
18
18
  TEST_POSITION_FILE = "test_position.binlog.pos"
19
+ TEST_SENT_POSITION_FILE = "test_position.binlog.sent.pos"
19
20
  TEST_REVISION_FILE = File.join(FLYDATA_HOME, "positions/#{TEST_TABLE}.rev")
20
21
  TEST_TIMESTAMP = 1389214083
21
22
  TEST_TABLE_APPEND_ONLY = "test_table_4"
@@ -203,6 +204,13 @@ EOT
203
204
  f
204
205
  end
205
206
 
207
+ let(:sent_position_file) do
208
+ f = double('sent_position_file')
209
+ allow(f).to receive(:exists?).and_return(true)
210
+ allow(f).to receive(:read).and_return('test_sent_position')
211
+ f
212
+ end
213
+
206
214
  def create_file(file_path, content)
207
215
  File.open(file_path, 'w') {|f| f.write(content)}
208
216
  end
@@ -228,6 +236,8 @@ EOT
228
236
  setup_initial_flydata_files
229
237
  allow(MysqlBinlogInput::BinlogUtil).to receive(:to_hash) {|e| e}
230
238
  allow(Mysql::BinLogPositionFile).to receive(:new).with(TEST_POSITION_FILE).and_return(binlog_position_file)
239
+ allow(Mysql::BinLogPositionFile).to receive(:new).with(TEST_SENT_POSITION_FILE).
240
+ and_return(sent_position_file)
231
241
  allow(Flydata::Mysql::TableMeta).to receive(:update)
232
242
  allow(plugin).to receive(:`).with("mysql -V").and_return("mysql Ver 14.14 Distrib 5.5.40")
233
243
  allow(plugin).to receive(:`).with(/^echo 'select version\(\);'/).and_return("version()\n5.5.40-0ubuntu0.12.04.1-log")
@@ -33,6 +33,86 @@ describe 'MysqlAlterTableParser' do
33
33
  end
34
34
  end
35
35
 
36
+ context 'with space between type and meta' do
37
+ let(:query) { "alter table test_table add column value varchar (26)" }
38
+ it do
39
+ expect(subject).to eq({
40
+ type: :alter_table,
41
+ table_name: "test_table",
42
+ actions: [{
43
+ action: :add_column,
44
+ column: "value",
45
+ type: "varchar(78)",
46
+ query: "add column value varchar (26)"
47
+ }]
48
+ })
49
+ end
50
+ end
51
+
52
+ context 'with space before meta value' do
53
+ let(:query) { "alter table test_table add column value varchar( 26)" }
54
+ it do
55
+ expect(subject).to eq({
56
+ type: :alter_table,
57
+ table_name: "test_table",
58
+ actions: [{
59
+ action: :add_column,
60
+ column: "value",
61
+ type: "varchar(78)",
62
+ query: "add column value varchar( 26)"
63
+ }]
64
+ })
65
+ end
66
+ end
67
+
68
+ context 'with space after meta value' do
69
+ let(:query) { "alter table test_table add column value varchar(26 )" }
70
+ it do
71
+ expect(subject).to eq({
72
+ type: :alter_table,
73
+ table_name: "test_table",
74
+ actions: [{
75
+ action: :add_column,
76
+ column: "value",
77
+ type: "varchar(78)",
78
+ query: "add column value varchar(26 )"
79
+ }]
80
+ })
81
+ end
82
+ end
83
+
84
+ context 'with space before and after meta value' do
85
+ let(:query) { "alter table test_table add column value varchar( 26 )" }
86
+ it do
87
+ expect(subject).to eq({
88
+ type: :alter_table,
89
+ table_name: "test_table",
90
+ actions: [{
91
+ action: :add_column,
92
+ column: "value",
93
+ type: "varchar(78)",
94
+ query: "add column value varchar( 26 )"
95
+ }]
96
+ })
97
+ end
98
+ end
99
+
100
+ context 'with spaces everywhere' do
101
+ let(:query) { "alter table test_table add column value varchar ( 26 )" }
102
+ it do
103
+ expect(subject).to eq({
104
+ type: :alter_table,
105
+ table_name: "test_table",
106
+ actions: [{
107
+ action: :add_column,
108
+ column: "value",
109
+ type: "varchar(78)",
110
+ query: "add column value varchar ( 26 )"
111
+ }]
112
+ })
113
+ end
114
+ end
115
+
36
116
  context 'with a non-ascii table name' do
37
117
  let(:query) { "alter table `テスト` add column value varchar(26)" }
38
118
  it do
@@ -83,6 +163,23 @@ describe 'MysqlAlterTableParser' do
83
163
  end
84
164
  end
85
165
 
166
+ context 'data_type without meta' do
167
+ let(:query) { "alter table test_table add value int not null" }
168
+ it do
169
+ expect(subject).to eq({
170
+ type: :alter_table,
171
+ table_name: "test_table",
172
+ actions: [{
173
+ action: :add_column,
174
+ column: "value",
175
+ type: "int4(11)",
176
+ not_null: true,
177
+ query: "add value int not null"
178
+ }]
179
+ })
180
+ end
181
+ end
182
+
86
183
  context 'with multiple columns' do
87
184
  shared_examples 'test result hash' do
88
185
  it do
@@ -103,6 +200,7 @@ describe 'MysqlAlterTableParser' do
103
200
  })
104
201
  end
105
202
  end
203
+
106
204
  context 'with spaces before opening bracket' do
107
205
  let(:query) { "alter table test_table add column (value1 varchar(26), value2 varchar(26))" }
108
206
  let(:expected_query) {"add column (value1 varchar(26), value2 varchar(26))"}
@@ -115,6 +213,27 @@ describe 'MysqlAlterTableParser' do
115
213
  end
116
214
  end
117
215
 
216
+ context 'with multiple columns without bracket without the keyword "COLUMN"' do
217
+ let(:query) { "alter table test_table add value1 varchar(26), add value2 varchar(26)" }
218
+ it do
219
+ expect(subject).to eq({
220
+ type: :alter_table,
221
+ table_name: "test_table",
222
+ actions: [{
223
+ action: :add_column,
224
+ column: "value1",
225
+ type: "varchar(78)",
226
+ query: "add value1 varchar(26)"
227
+ },{
228
+ action: :add_column,
229
+ column: "value2",
230
+ type: "varchar(78)",
231
+ query: "add value2 varchar(26)"
232
+ }]
233
+ })
234
+ end
235
+ end
236
+
118
237
  context 'with multiple columns and without the keyword "COLUMN"' do
119
238
  let(:query) { "alter table test_table add ( value1 varchar(26), value2 varchar(26) )" }
120
239
  it do
@@ -322,16 +322,29 @@ EOT
322
322
  expect(source_table.table_name).to eq('users_login')
323
323
  expect(values_set).to eq(expected_values)
324
324
  nil
325
+ =begin
326
+ # Use this when _parse2 is used
325
327
  }.once
328
+ =end
329
+ # =begin
330
+ # Use this when _parse is used
331
+ }.never
332
+ # =end
326
333
  end
327
334
  expect(insert_record_block).to receive(:call).never
328
335
 
329
- # insert_record_block
336
+ # check_point_block
330
337
  [
331
338
  {state: Flydata::Parser::State::CREATE_TABLE},
332
339
  {state: Flydata::Parser::State::INSERT_RECORD},
340
+ =begin
341
+ # Use this when _parse2 is used
333
342
  {state: Flydata::Parser::State::CREATE_TABLE,
334
343
  last_pos: index_after(dump_content, 'UNLOCK TABLES;')}
344
+ =end
345
+ # =begin
346
+ # Use this when _parse is used
347
+ # =end
335
348
  ].each do |expected_params|
336
349
  expect(check_point_block).to receive(:call) { |source_table, last_pos, bytesize, binlog_pos, state, substate|
337
350
  expect(source_table.table_name).to eq('users_login') if source_table
@@ -346,10 +359,21 @@ EOT
346
359
  end
347
360
  expect(check_point_block).to receive(:call).never
348
361
 
362
+ =begin
363
+ # Use this when _parse2 is used
349
364
  binlog_pos = default_parser.parse(
350
365
  dump_io, create_table_block, insert_record_block, check_point_block
351
366
  )
352
367
  expect(binlog_pos).to eq(default_binlog_pos)
368
+ =end
369
+ # =begin
370
+ # Use this when _parse is used
371
+ expect {
372
+ binlog_pos = default_parser.parse(
373
+ dump_io, create_table_block, insert_record_block,
374
+ check_point_block)
375
+ }.to raise_error(DumpParseError)
376
+ # =end
353
377
  end
354
378
  end
355
379
 
@@ -851,7 +875,14 @@ EOT
851
875
  end
852
876
  context 'with various escape chars 1' do
853
877
  let(:value) { %Q|\\r\t\\Z| }
878
+ =begin
879
+ # Use this when _parse2 is used
854
880
  let(:expected_value) { %Q|\r\t\x1a| }
881
+ =end
882
+ # =begin
883
+ # Use this when _parse is used
884
+ let(:expected_value) { %Q|\r\t\\Z| }
885
+ # =end
855
886
  it 'returns correct chars' do
856
887
  expect(subject).to eq([[expected_value]])
857
888
  end
@@ -12,7 +12,7 @@ describe SyncGenerateTableDdl do
12
12
  'host' => 'localhost',
13
13
  'port' => 3306,
14
14
  'username' => 'masashi',
15
- 'password' => 'welcome',
15
+ 'password' => 'welcomes',
16
16
  'database' => 'sync_test',
17
17
  }
18
18
  } }
@@ -42,7 +42,7 @@ describe SyncGenerateTableDdl do
42
42
  context 'with full options' do
43
43
  it 'issues mysqldump command with expected parameters' do
44
44
  expect(Open3).to receive(:popen3).with(
45
- 'mysqldump -h localhost -P 3306 -umasashi -pwelcome --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
45
+ 'mysqldump -h localhost -P 3306 -umasashi -pwelcomes --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
46
46
 
47
47
  subject
48
48
  end
@@ -65,7 +65,7 @@ describe SyncGenerateTableDdl do
65
65
  end
66
66
  it "uses the default port" do
67
67
  expect(Open3).to receive(:popen3).with(
68
- 'mysqldump -h localhost -umasashi -pwelcome --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
68
+ 'mysqldump -h localhost -umasashi -pwelcomes --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
69
69
  subject
70
70
  end
71
71
  end
@@ -75,7 +75,7 @@ describe SyncGenerateTableDdl do
75
75
  end
76
76
  it "uses the specified port" do
77
77
  expect(Open3).to receive(:popen3).with(
78
- 'mysqldump -h localhost -P 1234 -umasashi -pwelcome --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
78
+ 'mysqldump -h localhost -P 1234 -umasashi -pwelcomes --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
79
79
  subject
80
80
  end
81
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Fujikawa
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-01-26 00:00:00.000000000 Z
15
+ date: 2016-02-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client
@@ -162,6 +162,20 @@ dependencies:
162
162
  - - ~>
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0.3'
165
+ - !ruby/object:Gem::Dependency
166
+ name: pg
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ~>
170
+ - !ruby/object:Gem::Version
171
+ version: 0.18.4
172
+ type: :runtime
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ~>
177
+ - !ruby/object:Gem::Version
178
+ version: 0.18.4
165
179
  - !ruby/object:Gem::Dependency
166
180
  name: slop
167
181
  requirement: !ruby/object:Gem::Requirement
@@ -536,7 +550,9 @@ files:
536
550
  - flydata-core/lib/flydata-core/string_utils.rb
537
551
  - flydata-core/lib/flydata-core/table_def.rb
538
552
  - flydata-core/lib/flydata-core/table_def/autoload_redshift_table_def.rb
553
+ - flydata-core/lib/flydata-core/table_def/base.rb
539
554
  - flydata-core/lib/flydata-core/table_def/mysql_table_def.rb
555
+ - flydata-core/lib/flydata-core/table_def/postgresql_table_def.rb
540
556
  - flydata-core/lib/flydata-core/table_def/redshift_table_def.rb
541
557
  - flydata-core/lib/flydata-core/table_def/sync_redshift_table_def.rb
542
558
  - flydata-core/lib/flydata-core/thread_context.rb
@@ -578,6 +594,7 @@ files:
578
594
  - flydata-core/spec/table_def/mysqldump_test_unique_key2.dump
579
595
  - flydata-core/spec/table_def/mysqldump_test_unique_key3.dump
580
596
  - flydata-core/spec/table_def/mysqldump_test_unsigned.dump
597
+ - flydata-core/spec/table_def/postgresql_table_def_spec.rb
581
598
  - flydata-core/spec/table_def/redshift_table_def_spec.rb
582
599
  - flydata-core/spec/table_def/sync_redshift_table_def_spec.rb
583
600
  - flydata-core/spec/wrapper_forwardable_spec.rb
@@ -616,7 +633,12 @@ files:
616
633
  - lib/flydata/cron.rb
617
634
  - lib/flydata/errors.rb
618
635
  - lib/flydata/event/api_event_sender.rb
619
- - lib/flydata/fluent-plugins/idle_event_detector.rb
636
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/base.rb
637
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
638
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync.rb
639
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/idle_event_detector.rb
640
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb
641
+ - lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
620
642
  - lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb
621
643
  - lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb
622
644
  - lib/flydata/fluent-plugins/mysql/binlog_position_file.rb
@@ -631,7 +653,6 @@ files:
631
653
  - lib/flydata/fluent-plugins/mysql/table_meta.rb
632
654
  - lib/flydata/fluent-plugins/mysql/truncate_table_query_handler.rb
633
655
  - lib/flydata/fluent-plugins/out_forward_ssl.rb
634
- - lib/flydata/fluent-plugins/preference.rb
635
656
  - lib/flydata/flydata_crontab.sh
636
657
  - lib/flydata/helper/action/agent_action.rb
637
658
  - lib/flydata/helper/action/check_abnormal_shutdown.rb
@@ -663,6 +684,7 @@ files:
663
684
  - lib/flydata/queueable_thread.rb
664
685
  - lib/flydata/source.rb
665
686
  - lib/flydata/source/component.rb
687
+ - lib/flydata/source/data_entry.rb
666
688
  - lib/flydata/source/errors.rb
667
689
  - lib/flydata/source/generate_source_dump.rb
668
690
  - lib/flydata/source/parse_dump_and_send.rb
@@ -676,6 +698,7 @@ files:
676
698
  - lib/flydata/source_mysql/command/mysql_command_base.rb
677
699
  - lib/flydata/source_mysql/command/mysqlbinlog.rb
678
700
  - lib/flydata/source_mysql/command/mysqldump.rb
701
+ - lib/flydata/source_mysql/data_entry.rb
679
702
  - lib/flydata/source_mysql/generate_source_dump.rb
680
703
  - lib/flydata/source_mysql/mysql_compatibility_check.rb
681
704
  - lib/flydata/source_mysql/parse_dump_and_send.rb
@@ -687,6 +710,9 @@ files:
687
710
  - lib/flydata/source_mysql/sync.rb
688
711
  - lib/flydata/source_mysql/sync_generate_table_ddl.rb
689
712
  - lib/flydata/source_mysql/table_ddl.rb
713
+ - lib/flydata/source_postgresql/data_entry.rb
714
+ - lib/flydata/source_postgresql/sync.rb
715
+ - lib/flydata/source_postgresql/sync_generate_table_ddl.rb
690
716
  - lib/flydata/source_zendesk/sync_generate_table_ddl.rb
691
717
  - lib/flydata/source_zendesk/zendesk_flydata_tabledefs.rb
692
718
  - lib/flydata/sync_file_manager.rb
@@ -718,7 +744,7 @@ files:
718
744
  - spec/flydata/command/sync_spec.rb
719
745
  - spec/flydata/command/version_spec.rb
720
746
  - spec/flydata/compatibility_check_spec.rb
721
- - spec/flydata/fluent-plugins/idle_event_detector_spec.rb
747
+ - spec/flydata/fluent-plugins/flydata_plugin_ext/idle_event_detector_spec.rb
722
748
  - spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb
723
749
  - spec/flydata/fluent-plugins/mysql/alter_table_query_handler_spec.rb
724
750
  - spec/flydata/fluent-plugins/mysql/binlog_query_dispatcher_spec.rb