Class: Dataflow::Nodes::JoinNode

Inherits:
ComputeNode show all
Defined in:
lib/dataflow/nodes/join_node.rb

Overview

Performs a join operation on 2 dependencies.

Constant Summary collapse

VALID_TYPES =
%w(inner left).freeze

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, #force_computing_lock_release!, #locked_for_computing?, #needs_automatic_recomputing?, #recompute, #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

find, #recompute, #updated?, #validate!

Instance Method Details

#compute_implObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dataflow/nodes/join_node.rb', line 37

def compute_impl
  all_same_postgresql = db_backend == :postgresql
  all_same_postgresql &&= dependencies[1..-1].all? do |dep|
    dep.db_backend == :postgresql && dep.db_name == db_name
  end

  if all_same_postgresql
    # use SQL join
    execute_sql_join
    self.updated_at = Time.now
  else
    # use software join
    super
  end
end

#required_schemaObject



29
30
31
32
33
34
35
# File 'lib/dataflow/nodes/join_node.rb', line 29

def required_schema
  return {} unless dependencies.count == 2

  # merge both dependencies schemas
  sch = dependencies.first.schema || {}
  sch.merge(dependencies.second.schema || {})
end

#valid_for_computation?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/dataflow/nodes/join_node.rb', line 20

def valid_for_computation?
  # We need an equivalent number of keys as they will be matched with each others
  if other_keys1.count != other_keys2.count
    errors.add(:other_keys2, "#{self.class} other_keys2 must match other_keys1's length")
  end

  super
end