Class: Dataflow::Nodes::Transformation::ToTimeNode

Inherits:
ComputeNode
  • Object
show all
Defined in:
lib/dataflow/nodes/transformation/to_time_node.rb

Overview

Transforms the given keys’ values to Time.

Constant Summary

Constants included from SchemaMixin

SchemaMixin::SAMPLE_DATA_OUTPUT, SchemaMixin::SEPARATOR

Instance Method Summary collapse

Methods inherited from ComputeNode

#all_dependencies, #compute, #data_node, data_node_opts, #dependencies, dependency_opts, ensure_data_node_exists, ensure_dependencies, #execute_local_batch_computation, #execute_local_computation, #execution_valid?, #explain_update, #force_computing_lock_release!, #locked_for_computing?, #make_batch_params, #needs_automatic_recomputing?, #recompute, #schema, #set_defaults, #updated?, #updated_at, #updated_at=

Methods included from SchemaMixin

#infer_partial_schema, #infer_schema, #sample_data, #schema_inferrer

Methods included from Dataflow::Node

#all_dependencies, find, #metadata, #recompute, #required_by, #validate!

Instance Method Details

#compute_batch(records:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dataflow/nodes/transformation/to_time_node.rb', line 21

def compute_batch(records:)
  key_tokens = keys.map do |key|
    record_dig_tokens(key: key, use_sym: dependencies.first.use_symbols?)
  end

  records.each do |record|
    key_tokens.each_with_index do |tokens, index|
      value = record.dig(*tokens)
      next unless value.present?

      value = value.to_time
      add_value_to_record(record: record, key: keys[index], value: value)
    end
  end

  records
end

#valid_for_computation?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/dataflow/nodes/transformation/to_time_node.rb', line 12

def valid_for_computation?
  # It does not make sense to use this node without any keys specified.
  if (keys || []).count.zero?
    errors.add(:keys, "#{self.class} keys must contain at least 1 value")
  end

  super
end