etl 0.9.5.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.yardopts +5 -0
- data/0.9-UPGRADE +6 -0
- data/CHANGELOG +236 -0
- data/Gemfile +4 -0
- data/HOW_TO_RELEASE +13 -0
- data/LICENSE +7 -0
- data/README.textile +111 -0
- data/Rakefile +105 -0
- data/TODO +28 -0
- data/activewarehouse-etl.gemspec +38 -0
- data/bin/etl +28 -0
- data/bin/etl.cmd +8 -0
- data/examples/database.example.yml +16 -0
- data/lib/etl.rb +97 -0
- data/lib/etl/batch.rb +2 -0
- data/lib/etl/batch/batch.rb +111 -0
- data/lib/etl/batch/directives.rb +65 -0
- data/lib/etl/builder.rb +2 -0
- data/lib/etl/builder/date_dimension_builder.rb +96 -0
- data/lib/etl/builder/time_dimension_builder.rb +31 -0
- data/lib/etl/commands/etl.rb +89 -0
- data/lib/etl/control.rb +3 -0
- data/lib/etl/control/control.rb +405 -0
- data/lib/etl/control/destination.rb +438 -0
- data/lib/etl/control/destination/csv_destination.rb +113 -0
- data/lib/etl/control/destination/database_destination.rb +97 -0
- data/lib/etl/control/destination/excel_destination.rb +91 -0
- data/lib/etl/control/destination/file_destination.rb +126 -0
- data/lib/etl/control/destination/insert_update_database_destination.rb +136 -0
- data/lib/etl/control/destination/update_database_destination.rb +109 -0
- data/lib/etl/control/destination/yaml_destination.rb +74 -0
- data/lib/etl/control/source.rb +132 -0
- data/lib/etl/control/source/database_source.rb +224 -0
- data/lib/etl/control/source/enumerable_source.rb +11 -0
- data/lib/etl/control/source/file_source.rb +90 -0
- data/lib/etl/control/source/model_source.rb +39 -0
- data/lib/etl/core_ext.rb +1 -0
- data/lib/etl/core_ext/time.rb +5 -0
- data/lib/etl/core_ext/time/calculations.rb +42 -0
- data/lib/etl/engine.rb +582 -0
- data/lib/etl/execution.rb +19 -0
- data/lib/etl/execution/base.rb +8 -0
- data/lib/etl/execution/batch.rb +10 -0
- data/lib/etl/execution/job.rb +8 -0
- data/lib/etl/execution/migration.rb +90 -0
- data/lib/etl/generator.rb +2 -0
- data/lib/etl/generator/generator.rb +20 -0
- data/lib/etl/generator/surrogate_key_generator.rb +39 -0
- data/lib/etl/http_tools.rb +139 -0
- data/lib/etl/parser.rb +11 -0
- data/lib/etl/parser/apache_combined_log_parser.rb +49 -0
- data/lib/etl/parser/csv_parser.rb +93 -0
- data/lib/etl/parser/excel_parser.rb +112 -0
- data/lib/etl/parser/fixed_width_parser.rb +65 -0
- data/lib/etl/parser/nokogiri_xml_parser.rb +83 -0
- data/lib/etl/parser/parser.rb +41 -0
- data/lib/etl/parser/sax_parser.rb +218 -0
- data/lib/etl/parser/xml_parser.rb +65 -0
- data/lib/etl/processor.rb +11 -0
- data/lib/etl/processor/block_processor.rb +14 -0
- data/lib/etl/processor/bulk_import_processor.rb +94 -0
- data/lib/etl/processor/check_exist_processor.rb +80 -0
- data/lib/etl/processor/check_unique_processor.rb +39 -0
- data/lib/etl/processor/copy_field_processor.rb +26 -0
- data/lib/etl/processor/database_join_processor.rb +82 -0
- data/lib/etl/processor/encode_processor.rb +55 -0
- data/lib/etl/processor/ensure_fields_presence_processor.rb +24 -0
- data/lib/etl/processor/escape_csv_processor.rb +77 -0
- data/lib/etl/processor/filter_row_processor.rb +51 -0
- data/lib/etl/processor/ftp_downloader_processor.rb +68 -0
- data/lib/etl/processor/ftp_uploader_processor.rb +65 -0
- data/lib/etl/processor/hierarchy_exploder_processor.rb +55 -0
- data/lib/etl/processor/imapattachment_downloader_processor.rb +91 -0
- data/lib/etl/processor/pop3attachment_downloader_processor.rb +90 -0
- data/lib/etl/processor/print_row_processor.rb +12 -0
- data/lib/etl/processor/processor.rb +25 -0
- data/lib/etl/processor/rename_processor.rb +24 -0
- data/lib/etl/processor/require_non_blank_processor.rb +26 -0
- data/lib/etl/processor/row_processor.rb +27 -0
- data/lib/etl/processor/sequence_processor.rb +23 -0
- data/lib/etl/processor/sftp_downloader_processor.rb +63 -0
- data/lib/etl/processor/sftp_uploader_processor.rb +63 -0
- data/lib/etl/processor/surrogate_key_processor.rb +53 -0
- data/lib/etl/processor/truncate_processor.rb +40 -0
- data/lib/etl/processor/zip_file_processor.rb +27 -0
- data/lib/etl/row.rb +20 -0
- data/lib/etl/screen.rb +14 -0
- data/lib/etl/screen/row_count_screen.rb +20 -0
- data/lib/etl/transform.rb +2 -0
- data/lib/etl/transform/block_transform.rb +13 -0
- data/lib/etl/transform/calculation_transform.rb +71 -0
- data/lib/etl/transform/date_to_string_transform.rb +20 -0
- data/lib/etl/transform/decode_transform.rb +51 -0
- data/lib/etl/transform/default_transform.rb +20 -0
- data/lib/etl/transform/foreign_key_lookup_transform.rb +211 -0
- data/lib/etl/transform/hierarchy_lookup_transform.rb +49 -0
- data/lib/etl/transform/md5_transform.rb +13 -0
- data/lib/etl/transform/ordinalize_transform.rb +14 -0
- data/lib/etl/transform/sha1_transform.rb +13 -0
- data/lib/etl/transform/split_fields_transform.rb +27 -0
- data/lib/etl/transform/string_to_date_time_transform.rb +14 -0
- data/lib/etl/transform/string_to_date_transform.rb +16 -0
- data/lib/etl/transform/string_to_time_transform.rb +11 -0
- data/lib/etl/transform/transform.rb +61 -0
- data/lib/etl/transform/trim_transform.rb +26 -0
- data/lib/etl/transform/type_transform.rb +35 -0
- data/lib/etl/util.rb +59 -0
- data/lib/etl/version.rb +3 -0
- data/spec/fixtures/all.ebf +6 -0
- data/spec/fixtures/apache_combined_log.ctl +11 -0
- data/spec/fixtures/batch_with_error.ebf +6 -0
- data/spec/fixtures/batched1.ctl +0 -0
- data/spec/fixtures/batched2.ctl +0 -0
- data/spec/fixtures/block_processor.ctl +6 -0
- data/spec/fixtures/block_processor_error.ctl +1 -0
- data/spec/fixtures/block_processor_pre_post_process.ctl +4 -0
- data/spec/fixtures/block_processor_remove_rows.ctl +5 -0
- data/spec/fixtures/data/apache_combined_log.txt +3 -0
- data/spec/fixtures/data/bulk_import.txt +3 -0
- data/spec/fixtures/data/bulk_import_with_empties.txt +3 -0
- data/spec/fixtures/data/decode.txt +3 -0
- data/spec/fixtures/data/delimited.txt +3 -0
- data/spec/fixtures/data/encode_source_latin1.txt +2 -0
- data/spec/fixtures/data/excel.xls +0 -0
- data/spec/fixtures/data/excel2.xls +0 -0
- data/spec/fixtures/data/fixed_width.txt +3 -0
- data/spec/fixtures/data/multiple_delimited_1.txt +3 -0
- data/spec/fixtures/data/multiple_delimited_2.txt +3 -0
- data/spec/fixtures/data/nokogiri.xml +38 -0
- data/spec/fixtures/data/people.txt +3 -0
- data/spec/fixtures/data/sax.xml +14 -0
- data/spec/fixtures/data/xml.xml +16 -0
- data/spec/fixtures/delimited.ctl +30 -0
- data/spec/fixtures/delimited_absolute.ctl +31 -0
- data/spec/fixtures/delimited_destination_db.ctl +23 -0
- data/spec/fixtures/delimited_excel.ctl +31 -0
- data/spec/fixtures/delimited_insert_update.ctl +34 -0
- data/spec/fixtures/delimited_update.ctl +34 -0
- data/spec/fixtures/delimited_with_bulk_load.ctl +34 -0
- data/spec/fixtures/errors.ctl +24 -0
- data/spec/fixtures/excel.ctl +24 -0
- data/spec/fixtures/excel2.ctl +25 -0
- data/spec/fixtures/fixed_width.ctl +35 -0
- data/spec/fixtures/inline_parser.ctl +17 -0
- data/spec/fixtures/model_source.ctl +14 -0
- data/spec/fixtures/multiple_delimited.ctl +22 -0
- data/spec/fixtures/multiple_source_delimited.ctl +39 -0
- data/spec/fixtures/nokogiri_all.ctl +35 -0
- data/spec/fixtures/nokogiri_select.ctl +35 -0
- data/spec/fixtures/output/.ignore +1 -0
- data/spec/fixtures/output/delimited.txt +3 -0
- data/spec/fixtures/output/encode_destination_utf-8.txt +2 -0
- data/spec/fixtures/output/fixed_width.txt +3 -0
- data/spec/fixtures/output/inline_parser.txt +3 -0
- data/spec/fixtures/output/multiple_source_delimited.txt +6 -0
- data/spec/fixtures/output/test_excel_destination.xls +0 -0
- data/spec/fixtures/output/test_file_destination.2.txt +2 -0
- data/spec/fixtures/output/test_file_destination.txt +2 -0
- data/spec/fixtures/output/test_multiple_unique.txt +1 -0
- data/spec/fixtures/output/test_unique.txt +2 -0
- data/spec/fixtures/sax.ctl +26 -0
- data/spec/fixtures/scd/1.txt +1 -0
- data/spec/fixtures/scd/2.txt +1 -0
- data/spec/fixtures/scd/3.txt +1 -0
- data/spec/fixtures/scd_test_type_1.ctl +43 -0
- data/spec/fixtures/scd_test_type_2.ctl +34 -0
- data/spec/fixtures/screen_test_error.ctl +3 -0
- data/spec/fixtures/screen_test_fatal.ctl +3 -0
- data/spec/fixtures/xml.ctl +31 -0
- data/spec/quality_spec.rb +11 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/custom_fixtures.rb +54 -0
- data/spec/support/custom_matchers.rb +54 -0
- data/test-matrix.yml +10 -0
- data/test/.gitignore +1 -0
- data/test/.ignore +2 -0
- data/test/batch_test.rb +41 -0
- data/test/block_processor_test.rb +38 -0
- data/test/check_exist_processor_test.rb +92 -0
- data/test/check_unique_processor_test.rb +40 -0
- data/test/config/Gemfile.rails-2.3.x +3 -0
- data/test/config/Gemfile.rails-2.3.x.lock +53 -0
- data/test/config/Gemfile.rails-3.0.x +3 -0
- data/test/config/Gemfile.rails-3.0.x.lock +61 -0
- data/test/config/common.rb +29 -0
- data/test/connection/mysql/connection.rb +9 -0
- data/test/connection/mysql/schema.sql +37 -0
- data/test/connection/postgresql/connection.rb +13 -0
- data/test/connection/postgresql/schema.sql +40 -0
- data/test/control_test.rb +43 -0
- data/test/database_join_processor_test.rb +43 -0
- data/test/date_dimension_builder_test.rb +96 -0
- data/test/destination_test.rb +275 -0
- data/test/directive_test.rb +23 -0
- data/test/encode_processor_test.rb +32 -0
- data/test/engine_test.rb +78 -0
- data/test/ensure_fields_presence_processor_test.rb +28 -0
- data/test/etl_test.rb +42 -0
- data/test/foreign_key_lookup_transform_test.rb +50 -0
- data/test/generator_test.rb +14 -0
- data/test/mocks/mock_destination.rb +26 -0
- data/test/mocks/mock_source.rb +25 -0
- data/test/nokogiri_test.rb +35 -0
- data/test/parser_test.rb +224 -0
- data/test/performance/delimited.ctl +30 -0
- data/test/processor_test.rb +44 -0
- data/test/row_processor_test.rb +17 -0
- data/test/scd_test.rb +257 -0
- data/test/screen_test.rb +9 -0
- data/test/source_test.rb +154 -0
- data/test/test_helper.rb +37 -0
- data/test/transform_test.rb +101 -0
- data/test/truncate_processor_test.rb +37 -0
- metadata +510 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
|
3
|
+
<people>
|
4
|
+
<person age="24">
|
5
|
+
<first_name>Bob</first_name>
|
6
|
+
<last_name>Smith</last_name>
|
7
|
+
<social_security_number>123456789</social_security_number>
|
8
|
+
</person>
|
9
|
+
<person age="31">
|
10
|
+
<first_name>John</first_name>
|
11
|
+
<last_name>Doe</last_name>
|
12
|
+
<social_security_number>222114545</social_security_number>
|
13
|
+
</person>
|
14
|
+
</people>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
|
3
|
+
<people>
|
4
|
+
<person>
|
5
|
+
<first_name>Bob</first_name>
|
6
|
+
<last_name>Smith</last_name>
|
7
|
+
<social_security_number>123456789</social_security_number>
|
8
|
+
<age>24</age>
|
9
|
+
</person>
|
10
|
+
<person>
|
11
|
+
<first_name>John</first_name>
|
12
|
+
<last_name>Doe</last_name>
|
13
|
+
<social_security_number>222114545</social_security_number>
|
14
|
+
<age>31</age>
|
15
|
+
</person>
|
16
|
+
</people>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/delimited.txt',
|
3
|
+
:parser => {
|
4
|
+
:name => :csv
|
5
|
+
}
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
:age,
|
12
|
+
:sex
|
13
|
+
]
|
14
|
+
|
15
|
+
#transform :age, :type, :type => :number
|
16
|
+
transform :ssn, :sha1
|
17
|
+
transform(:ssn){ |n, v, row| v[0,24] }
|
18
|
+
transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:file => 'output/delimited.txt'
|
22
|
+
},
|
23
|
+
{
|
24
|
+
:order => [:id, :first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
|
25
|
+
:virtual => {
|
26
|
+
:id => :surrogate_key,
|
27
|
+
:test => "test!",
|
28
|
+
:calc_test => Time.now
|
29
|
+
},
|
30
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => '/tmp/delimited_abs.txt',
|
3
|
+
:parser => {
|
4
|
+
:name => :csv
|
5
|
+
}
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
{
|
12
|
+
:name => :age,
|
13
|
+
:type => :integer
|
14
|
+
},
|
15
|
+
:sex
|
16
|
+
]
|
17
|
+
|
18
|
+
transform :ssn, :sha1
|
19
|
+
transform(:ssn){ |n, v, row| v[0,24] }
|
20
|
+
transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
|
21
|
+
|
22
|
+
destination :out, {
|
23
|
+
:file => 'data/delimited_abs.txt'
|
24
|
+
},
|
25
|
+
{
|
26
|
+
:order => [:first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
|
27
|
+
:virtual => {
|
28
|
+
:test => "test!",
|
29
|
+
:calc_test => Time.now
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/delimited.txt',
|
3
|
+
:parser => :csv
|
4
|
+
},
|
5
|
+
[
|
6
|
+
:id,
|
7
|
+
:first_name,
|
8
|
+
:last_name,
|
9
|
+
:ssn
|
10
|
+
]
|
11
|
+
|
12
|
+
transform :ssn, :sha1
|
13
|
+
transform(:ssn){ |v| v[0,24] }
|
14
|
+
|
15
|
+
destination :out, {
|
16
|
+
:type => :database,
|
17
|
+
:target => :data_warehouse,
|
18
|
+
:database => 'etl_unittest',
|
19
|
+
:table => 'people',
|
20
|
+
},
|
21
|
+
{
|
22
|
+
:order => [:id, :first_name, :last_name, :ssn]
|
23
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/delimited.txt',
|
3
|
+
:parser => {
|
4
|
+
:name => :csv
|
5
|
+
}
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
:age,
|
12
|
+
:sex
|
13
|
+
]
|
14
|
+
|
15
|
+
#transform :age, :type, :type => :number
|
16
|
+
transform :ssn, :sha1
|
17
|
+
transform(:ssn){ |n, v, row| v[0,24] }
|
18
|
+
transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:type => :excel,
|
22
|
+
:file => 'output/delimited_excel.xls'
|
23
|
+
},
|
24
|
+
{
|
25
|
+
:order => [:id, :first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
|
26
|
+
:virtual => {
|
27
|
+
:id => :surrogate_key,
|
28
|
+
:test => "test!",
|
29
|
+
:calc_test => Time.now
|
30
|
+
},
|
31
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/delimited.txt',
|
3
|
+
:parser => {
|
4
|
+
:name => :csv
|
5
|
+
}
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
:age,
|
12
|
+
:sex
|
13
|
+
]
|
14
|
+
|
15
|
+
#transform :age, :type, :type => :number
|
16
|
+
transform :ssn, :sha1
|
17
|
+
transform(:ssn){ |n, v, row| v[0,24] }
|
18
|
+
transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:type => :insert_update_database,
|
22
|
+
:target => :data_warehouse,
|
23
|
+
:database => 'etl_unittest',
|
24
|
+
:table => 'people'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
:primarykey => [:id],
|
28
|
+
:order => [:id, :first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
|
29
|
+
:virtual => {
|
30
|
+
:id => :surrogate_key,
|
31
|
+
:test => "test!",
|
32
|
+
:calc_test => Time.now
|
33
|
+
},
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/delimited.txt',
|
3
|
+
:parser => {
|
4
|
+
:name => :csv
|
5
|
+
}
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
:age,
|
12
|
+
:sex
|
13
|
+
]
|
14
|
+
|
15
|
+
#transform :age, :type, :type => :number
|
16
|
+
transform :ssn, :sha1
|
17
|
+
transform(:ssn){ |n, v, row| v[0,24] }
|
18
|
+
transform :sex, :decode, {:decode_table_path => 'data/decode.txt'}
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:type => :update_database,
|
22
|
+
:target => :data_warehouse,
|
23
|
+
:database => 'etl_unittest',
|
24
|
+
:table => 'people'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
:conditions => [{:field => "\#{conn.quote_column_name(:id)}", :value => "\#{conn.quote(row[:id])}", :comp => "="}],
|
28
|
+
:order => [:id, :first_name, :last_name, :ssn, :age, :sex, :test, :calc_test],
|
29
|
+
:virtual => {
|
30
|
+
:id => :surrogate_key,
|
31
|
+
:test => "test!",
|
32
|
+
:calc_test => Time.now
|
33
|
+
},
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
infile = 'data/people.txt'
|
2
|
+
outfile = 'output/people.txt'
|
3
|
+
|
4
|
+
source :in, {
|
5
|
+
:file => infile,
|
6
|
+
:parser => {
|
7
|
+
:name => :csv
|
8
|
+
}
|
9
|
+
},
|
10
|
+
[
|
11
|
+
:first_name,
|
12
|
+
:last_name,
|
13
|
+
]
|
14
|
+
|
15
|
+
before_write :surrogate_key, :target => :data_warehouse, :table => 'person_dimension', :column => 'id'
|
16
|
+
before_write :check_exist, {
|
17
|
+
:target => :data_warehouse,
|
18
|
+
:table => 'person_dimension',
|
19
|
+
:columns => [:first_name, :last_name]
|
20
|
+
}
|
21
|
+
|
22
|
+
destination :out, {
|
23
|
+
:file => outfile
|
24
|
+
},
|
25
|
+
{
|
26
|
+
:order => [:id, :first_name, :last_name]
|
27
|
+
}
|
28
|
+
|
29
|
+
post_process :bulk_import, {
|
30
|
+
:file => outfile,
|
31
|
+
:target => :data_warehouse,
|
32
|
+
:table => 'person_dimension',
|
33
|
+
:order => [:id, :first_name, :last_name]
|
34
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ErrorProcessor < ETL::Processor::RowProcessor
|
2
|
+
def initialize(control, configuration)
|
3
|
+
super
|
4
|
+
end
|
5
|
+
def process(row)
|
6
|
+
raise RuntimeError, "Generated error"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
set_error_threshold 1
|
11
|
+
|
12
|
+
source :in, {
|
13
|
+
:type => :enumerable,
|
14
|
+
:enumerable => [
|
15
|
+
{:first_name => 'Bob',:last_name => 'Smith'},
|
16
|
+
{:first_name => 'Joe', :last_name => 'Thompson'}
|
17
|
+
]
|
18
|
+
},
|
19
|
+
[
|
20
|
+
:first_name,
|
21
|
+
:last_name
|
22
|
+
]
|
23
|
+
|
24
|
+
after_read ErrorProcessor
|
@@ -0,0 +1,24 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/excel.xls',
|
3
|
+
:parser => :excel
|
4
|
+
},
|
5
|
+
{
|
6
|
+
:ignore_blank_line => false,
|
7
|
+
:fields => [
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
:age
|
12
|
+
]
|
13
|
+
}
|
14
|
+
|
15
|
+
transform :ssn, :sha1
|
16
|
+
transform(:ssn){ |n, v, r| v[0,24] }
|
17
|
+
|
18
|
+
|
19
|
+
destination :out, {
|
20
|
+
:file => 'output/excel.out.txt'
|
21
|
+
},
|
22
|
+
{
|
23
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
24
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => 'data/excel2.xls',
|
3
|
+
:parser => :excel
|
4
|
+
},
|
5
|
+
{
|
6
|
+
:ignore_blank_line => true,
|
7
|
+
:worksheets => [ 1 ],
|
8
|
+
:fields => [
|
9
|
+
:first_name,
|
10
|
+
:last_name,
|
11
|
+
:ssn,
|
12
|
+
:age
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
transform :ssn, :sha1
|
17
|
+
transform(:ssn){ |n, v, r| v[0,24] }
|
18
|
+
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:file => 'output/excel2.out.txt'
|
22
|
+
},
|
23
|
+
{
|
24
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
25
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# puts "executing fixed_width.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/fixed_width.txt',
|
5
|
+
:parser => :fixed_width
|
6
|
+
},
|
7
|
+
{
|
8
|
+
:first_name => {
|
9
|
+
:start => 1,
|
10
|
+
:length => 9
|
11
|
+
},
|
12
|
+
:last_name => {
|
13
|
+
:start => 10,
|
14
|
+
:length => 12
|
15
|
+
},
|
16
|
+
:ssn => {
|
17
|
+
:start => 22,
|
18
|
+
:length => 9
|
19
|
+
},
|
20
|
+
:age => {
|
21
|
+
:start => 31,
|
22
|
+
:length => 2,
|
23
|
+
:type => :integer
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
transform :ssn, :sha1
|
28
|
+
transform(:ssn){ |n, v, r| v[0,24] }
|
29
|
+
|
30
|
+
destination :out, {
|
31
|
+
:file => 'output/fixed_width.txt'
|
32
|
+
},
|
33
|
+
{
|
34
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
35
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class MyParser < ETL::Parser::Parser
|
2
|
+
def each
|
3
|
+
[{:name => 'foo'},{:name => 'bar'},{:name => 'baz'}].each do |row|
|
4
|
+
yield row
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
source :in, {
|
10
|
+
:file => '',
|
11
|
+
:parser => MyParser
|
12
|
+
},
|
13
|
+
[
|
14
|
+
:name
|
15
|
+
]
|
16
|
+
|
17
|
+
destination :out, {:file => 'output/inline_parser.txt'},{:order => [:name]}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# puts "executing delimited.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/multiple_delimited_*.txt',
|
5
|
+
:parser => :csv
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
{
|
12
|
+
:name => :age,
|
13
|
+
:type => :integer
|
14
|
+
}
|
15
|
+
]
|
16
|
+
|
17
|
+
destination :out, {
|
18
|
+
:file => 'output/multiple_delimited.txt'
|
19
|
+
},
|
20
|
+
{
|
21
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
22
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# puts "executing delimited.ctl"
|
2
|
+
|
3
|
+
source :source1, {
|
4
|
+
:file => 'data/multiple_delimited_*.txt',
|
5
|
+
:parser => :csv
|
6
|
+
},
|
7
|
+
[
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:ssn,
|
11
|
+
{
|
12
|
+
:name => :age,
|
13
|
+
:type => :integer
|
14
|
+
}
|
15
|
+
]
|
16
|
+
|
17
|
+
source :source2, {
|
18
|
+
:file => 'data/multiple_delimited_*.txt',
|
19
|
+
:parser => :csv
|
20
|
+
},
|
21
|
+
[
|
22
|
+
:first_name,
|
23
|
+
:last_name,
|
24
|
+
:ssn,
|
25
|
+
{
|
26
|
+
:name => :age,
|
27
|
+
:type => :integer
|
28
|
+
}
|
29
|
+
]
|
30
|
+
|
31
|
+
transform :ssn, :sha1
|
32
|
+
transform(:ssn){ |v| v[0,24] }
|
33
|
+
|
34
|
+
destination :out, {
|
35
|
+
:file => 'output/multiple_source_delimited.txt'
|
36
|
+
},
|
37
|
+
{
|
38
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
39
|
+
}
|