Module: GoodData::Bam::Generators::Etl
- Includes:
- GoodData::Bam, CloudConnect
- Defined in:
- lib/generators/etl.rb
Constant Summary
Constants included from GoodData::Bam
BAM_DEFINED_GRAPHS_ROOT, BAM_ROOT, GoodData::Bam::GENERATOR_ROOT, REPO_ROOT, TEMPLATE_ROOT
Class Method Summary collapse
- .create_es_downloading_graph(file, tap, options = {}) ⇒ Object
- .create_es_readmap(metadata, tap) ⇒ Object
- .create_file_downloading_graph(file, tap, options = {}) ⇒ Object
- .create_file_uploading_graph(file, sink, input_name, state = {}) ⇒ Object
- .create_gd_uploading_graph(file, sink, input_name, state = {}) ⇒ Object
- .create_sf_downloading_graph(file, tap, options = {}) ⇒ Object
Methods included from GoodData::Bam
Class Method Details
.create_es_downloading_graph(file, tap, options = {}) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/generators/etl.rb', line 208 def self.create_es_downloading_graph(file, tap, ={}) s3_backup = [:params][:s3_backup] = Metadata.(tap) = Metadata.(tap) id = tap[:id] File.open(file, "w") do |file| builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" builder.Graph({ :name => "GoodData EventStore Downloader" }) do builder.Global do Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"}) builder.Metadata({:id => "es_metadata"}) do |builder| Helpers::(builder, ) end builder.Metadata({:id => "output_metadata"}) do |builder| Helpers::(builder, ) end end builder.Phase(:number => 0) do stuff, read_map, time_frames = create_es_readmap(, tap) if time_frames.blank? Core::build_node2(builder, Nodes.es_reader2({:name => "ES Reader", :id => "es", :entityFieldsMapping => stuff.to_json , :readMap => read_map.to_json})) else Core::build_node2(builder, Nodes.es_reader2({:name => "ES Reader", :id => "es", :entityFieldsMapping => stuff.to_json , :readMap => read_map.to_json, :timeIntervals => time_frames.to_json})) end transformation_source = if Metadata::has_field?(, "Snapshot") "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\n$out.0.Snapshot = date2str(dateAdd(str2date(\"1900-01-01\", \"yyyy-MM-dd\"), str2long($in.0.Snapshot), day), \"yyyy-MM-dd\");\nreturn OK;\n}" else "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}" end Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source})) Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "es:0", :metadata => "es_metadata"})) Core::build_node2(builder, Nodes.copy2({:name => "Copy", :id => "copy"})) Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "reformat:0", :metadata => "output_metadata"})) Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "${PROJECT}/data/#{tap[:id]}.csv", :outputFieldNames => "true", :makeDirs => "true"})) Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "copy:0", :metadata => "output_metadata"})) end end end end |
.create_es_readmap(metadata, tap) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/etl.rb', line 10 def self.create_es_readmap(, tap) e = Es::Entity.new("x", { :file => "none", :fields => [:fields].map do |f| name = f[:name] if name == "Id" Es::Field.new('Id', 'recordid') elsif name == "Snapshot" Es::SnapshotField.new('Snapshot', 'snapshot') else Es::Field.new(name, 'attribute') end end, :timeframe => Es::Timeframe::parse("latest") }) stuff = { :entityName => tap[:id], :fieldsMapping => tap[:fields].inject({}) do |memo, field| name = field[:name] memo[name] = name memo end, :eventStoreFieldToTypeMapping => tap[:fields].inject({}) do |memo, field| name = field[:name] if name == "Id" memo[name] = "recordid" elsif name == "Snapshot" memo[name] = "snapshot" else memo[name] = "attribute" end memo end, :outputMetadataName => "es_metadata" } read_map = { :columns => e.to_extract_fragment('pid')["readTask"]["readMap"].first[:columns], :populates => e.to_extract_fragment('pid')["readTask"]["readMap"].first[:populates] } if tap.has_key?(:time_intervals) [stuff, read_map, tap[:time_intervals]] else [stuff, read_map, nil] end end |
.create_file_downloading_graph(file, tap, options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/generators/etl.rb', line 109 def self.create_file_downloading_graph(file, tap, ={}) s3_backup = [:params][:s3_backup] File.open(file, "w") do |file| builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" builder.Graph({ :name => "File Downloader" }) do builder.Global do Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"}) builder.Metadata({:id => "file_metadata"}) do |builder| Helpers::(builder, Metadata.(tap)) end builder.Metadata({:id => "clover_metadata"}) do |builder| Helpers::(builder, Metadata.(tap)) end end builder.Phase(:number => 0) do Core::build_node2(builder, Nodes.reader2({:name => "reader", :id => "reader", :fileURL => tap[:source] })) Core::build_node2(builder, Nodes.copy2({:name => "copy", :id => "copy"})) Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "reader:0", :metadata => "file_metadata"})) transformation_source = "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}" Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source})) Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "copy:0", :metadata => "file_metadata"})) Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "data/#{tap[:id]}.csv", :outputFieldNames => "true"})) Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "reformat:0", :metadata => "clover_metadata"})) if s3_backup then Core::build_node2(builder, Nodes.writer2({:name => "s3 Writer", :id => "s3", :fileURL => "bucket", :outputFieldNames => true})) end if s3_backup then Core::build_node2(builder, Nodes.edge2({:toNode => "s3:0", :fromNode => "copy:1", :metadata => "file_metadata"})) end end end end end |
.create_file_uploading_graph(file, sink, input_name, state = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/etl.rb', line 61 def self.create_file_uploading_graph(file, sink, input_name, state={}) File.open(file, "w") do |file| builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" builder.Graph({ :name => "GoodData Data loader" }) do builder.Global do Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"}) builder.Metadata({:id => "load_metadata"}) do |builder| Helpers::(builder, state[:metadata][input_name]) end end builder.Phase(:number => 0) do gd_dataset = sink[:gd_name] || sink[:id] to_svinstvo = GoodData::CloverGenerator::build_gd_dataset_loader_json(sink) Core::build_node2(builder, Nodes.reader2({:name => "CSV Loader", :id => "loader", :fileURL => "${PROJECT}/data/#{input_name}.csv"})) Core::build_node2(builder, Nodes.writer2({:name => "GD Loader", :id => "writer", :fileURL => sink[:target]})) Core::build_node2(builder, Nodes.edge2({:toNode => "writer:0", :fromNode => "loader:0", :metadata => "load_metadata"})) end end end end |
.create_gd_uploading_graph(file, sink, input_name, state = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/generators/etl.rb', line 85 def self.create_gd_uploading_graph(file, sink, input_name, state={}) File.open(file, "w") do |file| builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" builder.Graph({ :name => "GoodData Data loader" }) do builder.Global do Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"}) builder.Metadata({:id => "load_metadata"}) do |builder| Helpers::(builder, state[:metadata][input_name]) end end builder.Phase(:number => 0) do gd_dataset = sink[:gd_name] || sink[:id] to_svinstvo = GoodData::CloverGenerator::build_gd_dataset_loader_json(sink) Core::build_node2(builder, Nodes.reader2({:name => "CSV Loader", :id => "loader", :fileURL => "${PROJECT}/data/#{input_name}.csv"})) Core::build_node2(builder, Nodes.edge2({:toNode => "gd_load:0", :fromNode => "loader:0", :metadata => "load_metadata"})) Core::build_node2(builder, Nodes.gd_loader2({:name => "GD Loader", :id => "gd_load", :dataset => "dataset.#{gd_dataset}", :datasetFieldMappings => to_svinstvo.to_json})) end end end end |
.create_sf_downloading_graph(file, tap, options = {}) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/generators/etl.rb', line 149 def self.create_sf_downloading_graph(file, tap, ={}) s3_backup = [:params][:s3_backup] File.open(file, "w") do |file| builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" builder.Graph({ :name => "Goodsales Salesforce Downloader" }) do builder.Global do builder.Metadata({:id => "clover_metadata"}) do |builder| Helpers::(builder, Metadata.(tap)) end builder.Metadata({:id => "sf_metadata"}) do |builder| Helpers::(builder, Metadata.(tap)) end Helpers::sf_connection(builder, {}) Helpers::property(builder, {:id => "SFDC_CLIENT_ID", :value => "gooddata/gooddata/"}) Helpers::property(builder, {:id => "SFDC_LOGIN_HOSTNAME", :value => [:params][:sf_server] || "login.salesforce.com"}) Helpers::property(builder, {:id => "SFDC_NAME", :value => "Salesforce connection"}) Helpers::property(builder, {:id => "SFDC_PASSWORD", :value => [:params][:sf_password]}) Helpers::property(builder, {:id => "SFDC_TOKEN", :value => [:params][:sf_token]}) Helpers::property(builder, {:id => "SFDC_USERNAME", :value => [:params][:sf_login]}) Helpers::property_file(builder, {:id => "workspace_params", :fileURL => "workspace.prm"}) end builder.Phase(:number => 0) do fields = tap[:fields] mapping = "{\"xmlFieldsMapping\":{\"xmlFields\":[" add = fields.map do |f| "{\"xmlFieldMapping\":{\"name\":\"#{f[:name]}\",\"label\":\"#{f[:label]}\",\"xmlPath\":\"#{f[:name]}\",\"metadataField\":\"#{f[:name]}\"}}" end stuff = mapping + add.join(",") + "]}}" mandatory_fields = fields.reject {|f| f[:is_mandatory] == false }.map {|f| f[:name] + ";"}.join Core::build_node2(builder, Nodes.sfdc_reader2({:name => "SF Writer", :id => "sf", :soql => Helpers::generate_select(tap), :sfdcConnection => "SFDC", :fieldsMapping => stuff, :mandatoryFields => mandatory_fields})) Core::build_node2(builder, Nodes.copy2({:name => "copy", :id => "copy"})) Core::build_node2(builder, Nodes.edge2({:toNode => "copy:0", :fromNode => "sf:0", :metadata => "sf_metadata"})) transformation_source = "function integer transform() {\n" + (Tap.source_target_mappging(tap).map {|t| "$out.0.#{t.last} = $in.0.#{t.first};"}.join("\n")) + "\nreturn OK;\n}" Core::build_node2(builder, Nodes.reformat2({:name => "Reformat", :id => "reformat", :transformation => transformation_source})) Core::build_node2(builder, Nodes.edge2({:toNode => "reformat:0", :fromNode => "copy:0", :metadata => "sf_metadata"})) Core::build_node2(builder, Nodes.writer2({:name => "CSV Writer", :id => "csv", :fileURL => "data/#{tap[:id]}.csv", :outputFieldNames => "true"})) Core::build_node2(builder, Nodes.edge2({:toNode => "csv:0", :fromNode => "reformat:0", :metadata => "clover_metadata"})) if s3_backup Core::build_node2(builder, Nodes.writer2({:name => "s3 Writer", :id => "s3", :fileURL => "bucket", :outputFieldNames => true})) Core::build_node2(builder, Nodes.edge2({:toNode => "s3:0", :fromNode => "copy:1", :metadata => "sf_metadata"})) end end end end end |