Module: GoodData::Bam::Compiler
- Defined in:
- lib/compiler/compiler.rb,
lib/compiler/etl_visitor.rb
Defined Under Namespace
Classes: EtlVisitor
Class Method Summary collapse
- .change_metadata(state, metadata_change_description) ⇒ Object
- .check_metadata_existence(metadata_store, id, flow_description) ⇒ Object
- .compile_dsl(project) ⇒ Object
- .compile_flow(project, flow_description) ⇒ Object
Class Method Details
.change_metadata(state, metadata_change_description) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/compiler/compiler.rb', line 13 def self.(state, ) = state[[:id]] # enrich meta with everything from descriptor. There might be additional stuff so we want this to be part of metadata = .merge(.reject {|k,v| [:id, :steps, :type].include?(k)}) [:steps].reduce(Metadata.create()) do |, step| case step[:type] when :field_add Metadata.add_field(, {:name => step[:name]}) when :field_remove Metadata.remove_field(, step[:name]) end end end |
.check_metadata_existence(metadata_store, id, flow_description) ⇒ Object
29 30 31 32 33 |
# File 'lib/compiler/compiler.rb', line 29 def self.(, id, flow_description) unless .has_key?(id) fail "Metadata with id \"#{id}\" were not found. Check that you have them included in flow \"#{flow_description[:name]}\"." end end |
.compile_dsl(project) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/compiler/compiler.rb', line 5 def self.compile_dsl(project) fail "There are no flow. Nothing to work on." if project[:flows_definitions].empty? compiled_flows = project[:flows_definitions].map do |flow_description| Compiler.compile_flow(project, flow_description) end Project.create(project.merge({:flows => compiled_flows})) end |
.compile_flow(project, flow_description) ⇒ Object
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 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/compiler/compiler.rb', line 35 def self.compile_flow(project, flow_description) flow = Flow.create({:name => flow_description[:name]}) # metadata_state = {} out_port = nil # this nil magic is done so we have visibility to one step back and forward. Currently not used much but it is useful for detectin input to sink flow = [nil].concat(flow_description[:steps]).concat([nil]).each_cons(3).reduce(flow) do |flow_memo, steps| previous_step, current_step, next_step = steps id = current_step[:id] || current_step[:flow_id] case current_step[:type] when :dummy_tap Flow.add_step(flow_memo, Tap.create(current_step.merge(:source => :dummy, :id => :none))) when :tap tap = Project.find_tap_by_id(project, id) fail "Tap \"#{id}\" which was used in flow \"#{current_step[:flow_id]}\" is not defined" if tap.nil? Flow.add_step(flow_memo, Tap.create(tap.merge(current_step))) when :sink sink = Project.find_sink_by_id(project, id) fail "Sink \"#{id}\" not found" if sink.nil? out_step = Step.find_output_step(previous_step[:steps]) Flow.add_step(flow_memo, Sink.create(sink.merge(current_step).merge({:in => out_step}))) when :graph graph = Project.find_graph_by_path(project, current_step[:path]) fail "Graph on the path \"#{current_step[:path]}\" could not be found. This was specified in step \"#{current_step}\"" if graph.nil? g = Graph.create(graph.merge(current_step)) if !Step.has_output_step?(g[:steps]) && g[:steps].count > 1 fail "You need to specify an output metadata." end Flow.add_step(flow_memo, Graph.create(g.merge({ :input_ports => g[:steps], :output_port => Step.find_output_step(g[:steps]) }))) end end end |