Class: Es::Extract
- Inherits:
-
Object
- Object
- Es::Extract
- Defined in:
- lib/es.rb
Instance Attribute Summary collapse
-
#entities ⇒ Object
Returns the value of attribute entities.
-
#partial ⇒ Object
Returns the value of attribute partial.
-
#timeframe ⇒ Object
Returns the value of attribute timeframe.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
Class Method Summary collapse
- .parse(spec, a_load, options = {}) ⇒ Object
- .parse_timeframes(timeframe_spec, options = {}) ⇒ Object
- .parseOldFormat(spec, a_load) ⇒ Object
- .parseOldFormat_timeframes(timeframe_spec) ⇒ Object
Instance Method Summary collapse
- #get_entity(name) ⇒ Object
-
#initialize(entities, options = {}) ⇒ Extract
constructor
A new instance of Extract.
- #to_extract_fragment(pid, options = {}) ⇒ Object
Constructor Details
#initialize(entities, options = {}) ⇒ Extract
Returns a new instance of Extract.
240 241 242 243 244 |
# File 'lib/es.rb', line 240 def initialize(entities, = {}) @entities = entities @timeframe = [:timeframe] @timezone = [:timezone] || 'UTC' end |
Instance Attribute Details
#entities ⇒ Object
Returns the value of attribute entities.
106 107 108 |
# File 'lib/es.rb', line 106 def entities @entities end |
#partial ⇒ Object
Returns the value of attribute partial.
106 107 108 |
# File 'lib/es.rb', line 106 def partial @partial end |
#timeframe ⇒ Object
Returns the value of attribute timeframe.
106 107 108 |
# File 'lib/es.rb', line 106 def timeframe @timeframe end |
#timezone ⇒ Object
Returns the value of attribute timezone.
106 107 108 |
# File 'lib/es.rb', line 106 def timezone @timezone end |
Class Method Details
.parse(spec, a_load, options = {}) ⇒ Object
108 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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/es.rb', line 108 def self.parse(spec, a_load, ={}) global_timeframe = parse_timeframes(spec[:timeframes], ) || parse_timeframes("latest", ) timezone = spec[:timezone] parsed_entities = spec[:entities].map do |entity_spec| entity_name = entity_spec[:entity] partial = entity_spec[:partial] || "false" load_entity = a_load.get_merged_entity_for(entity_name) fields = entity_spec[:fields].map do |field| if load_entity.has_field?(field) if (load_entity.get_field(field).is_recordid?) Es::RecordIdField.new(load_entity.get_field(field).name, load_entity.get_field(field).type, partial) else load_entity.get_field(field) end elsif field == "DeletedAt" Es::Field.new("DeletedAt", "time") elsif field == "IsDeleted" Es::Field.new("IsDeleted", "attribute") elsif field == "snapshot" Es::SnapshotField.new("snapshot", "snapshot") elsif field == "autoincrement" Es::AutoincrementField.new("generate", "autoincrement") elsif field == "duration" || (field.respond_to?(:keys) && field.keys.first == :duration ) if (field == "duration") then Es::DurationField.new("duration", "duration") else Es::DurationField.new("duration", "duration",{ :attribute => field[:duration][:attribute], :value => field[:duration][:value], :control_attribute => field[:duration][:name] }) end elsif field == "velocity" || (field.respond_to?(:keys) && field.keys.first == :velocity ) if (field == "velocity") then Es::VelocityField.new("velocity", "velocity") else Es::VelocityField.new("velocity", "velocity",{ :control_attribute => field[:velocity][:name] }) end elsif field.respond_to?(:keys) && field.keys.first == :hid Es::HIDField.new('hid', "historicid", { :entity => field[:hid][:from_entity], :fields => field[:hid][:from_fields], :through => field[:hid][:connected_through] }) else fail InsufficientSpecificationError.new("The field #{field.to_s.bright} was not found in either the loading specification nor was recognized as a special column") end end parsed_timeframe = parse_timeframes(entity_spec[:timeframes], ) Entity.new(entity_name, { :fields => fields, :file => Pathname.new(entity_spec[:file])..to_s, :timeframe => parsed_timeframe || global_timeframe || (fail "Timeframe has to be defined"), :timezone => timezone }) end Extract.new(parsed_entities) end |
.parse_timeframes(timeframe_spec, options = {}) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/es.rb', line 220 def self.parse_timeframes(timeframe_spec, ={}) return nil if timeframe_spec.nil? if timeframe_spec.is_a?(Array) then timeframe_spec.map {|t_spec| Es::Timeframe.parse(t_spec, )} else Es::Timeframe.parse(timeframe_spec, ) end end |
.parseOldFormat(spec, a_load) ⇒ Object
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 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/es.rb', line 171 def self.parseOldFormat(spec,a_load) global_timeframe = parseOldFormat_timeframes(spec[:timeFrames]) timezone = spec[:timezone] entity_name = spec[:entity] load_entity = a_load.get_merged_entity_for(entity_name) parser = Yajl::Parser.new(:symbolize_keys => true) i=0 begin doc = parser.parse(spec[:readMap]) doc.map do |internal| fields = internal[:columns].map do |definition| if load_entity.has_field?(definition[:name]) load_entity.get_field(definition[:name]) elsif definition[:name] == "DeletedAt" Es::Field.new("DeletedAt", "time") elsif definition[:name] == "IsDeleted" Es::Field.new("IsDeleted", "attribute") elsif definition[:name] == "snapshot" || definition[:definition][:type] == "snapshot" Es::SnapshotField.new("snapshot", "snapshot") elsif definition[:name] == "autoincrement" Es::AutoincrementField.new("generate", "autoincrement") elsif definition[:name] == "duration" Es::DurationField.new("duration", "duration") elsif definition[:name] == "velocity" Es::DurationField.new("velocity", "velocity") elsif definition[:definition][:type] == "historicid" Es::HIDField.new('hid', "historicid",Es::Helpers.get_historyid_settings(definition[:definition][:ops])) elsif definition[:name].downcase == "iswon" || definition[:name].downcase == "isclosed" || definition[:name].downcase == "stagename" || definition[:name].downcase == "daytoclose" || definition[:name] == "dayssincelastactivity" Es::Field.new(definition[:name], "attribute") else puts "WARNING! Transformer has found out field #{definition[:name]} which is not in load script, puting to extract as attribute" Es::Field.new("#{definition[:name]}", "attribute") end end parsed_timeframe = parseOldFormat_timeframes(internal[:timeframes]) entity = Entity.new(entity_name, { :fields => fields, :file => internal[:file], :timeframe => parsed_timeframe || global_timeframe || (fail "Timeframe has to be defined"), :timezone => timezone }) entity end rescue Yajl::ParseError => e fail Yajl::ParseError.new("Failed during parsing internal JSON. Error message: " + e.) end end |
.parseOldFormat_timeframes(timeframe_spec) ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/es.rb', line 229 def self.parseOldFormat_timeframes(timeframe_spec) return nil if timeframe_spec.nil? return Timeframe.parse("latest") if timeframe_spec == "latest" if timeframe_spec.is_a?(Array) then timeframe_spec.map {|t_spec| Es::Timeframe.parseOldFormat(t_spec)} else Es::Timeframe.parseOldFormat(timeframe_spec) end end |
Instance Method Details
#get_entity(name) ⇒ Object
246 247 248 |
# File 'lib/es.rb', line 246 def get_entity(name) entities.detect {|e| e.name == name} end |
#to_extract_fragment(pid, options = {}) ⇒ Object
250 251 252 253 254 |
# File 'lib/es.rb', line 250 def to_extract_fragment(pid, = {}) entities.map do |entity| entity.to_extract_fragment(pid, ) end end |