class Dataflow::Nodes::SqlQueryNode

Transforms the dependency's dataset to a SQL-compatible one.

Public Instance Methods

computed_query() click to toggle source
# File lib/dataflow/nodes/sql_query_node.rb, line 24
def computed_query
  # 1. replace the current write dataset's name
  q = query.gsub('<node>', write_dataset_name)

  # 2. replace the dependencies' (read) dataset names
  q.gsub(/<[0-9]+>/) do |match|
    # [1..-2] will remove the 'less than' < and 'greater than' >
    dep_index = match[1..-2].to_i
    raise "Specified depependency #{match} does not exist. There are only #{dependencies.count} dependencies." if dep_index >= dependencies.count
    dependencies[dep_index].read_dataset_name
  end
end
execute_query() click to toggle source
# File lib/dataflow/nodes/sql_query_node.rb, line 37
def execute_query
  query = computed_query
  logger.log(query)
  data_node.send(:db_adapter).client[query].to_a
end
valid_for_computation?() click to toggle source
# File lib/dataflow/nodes/sql_query_node.rb, line 10
def valid_for_computation?
  unless (data_node&.db_backend.to_s =~ /sql/).present?
    errors.add(:db_backend, 'Must have a SQL based backend.')
  end

  begin
    computed_query
  rescue StandardError => e
    errors.add(:query, "Specified query has errors: #{e.message}")
  end

  super
end

Private Instance Methods

compute_impl() click to toggle source

Overrides the base implementation. This node will leave all the work to the DB.

# File lib/dataflow/nodes/sql_query_node.rb, line 47
def compute_impl
  execute_query
end