Class: Axiom::SQL::Generator::Relation::Set

Inherits:
Binary show all
Defined in:
lib/axiom/sql/generator/relation/set.rb

Overview

Generates an SQL statement for a set relation

Direct Known Subclasses

Insertion

Defined Under Namespace

Classes: Base

Constant Summary collapse

DIFFERENCE =
'EXCEPT'.freeze
INTERSECTION =
'INTERSECT'.freeze
UNION =
'UNION'.freeze

Constants inherited from Binary

Binary::JOIN, Binary::LEFT_NAME, Binary::PRODUCT, Binary::RIGHT_NAME

Constants inherited from Axiom::SQL::Generator::Relation

EMPTY_HASH, EMPTY_STRING, SEPARATOR, STAR

Constants included from Identifier

Identifier::ESCAPED_QUOTE, Identifier::QUOTE

Constants inherited from Visitor

Visitor::DOUBLE_COLON, Visitor::NAME_REP, Visitor::NAME_SEP_REGEXP, Visitor::UNDERSCORE

Instance Attribute Summary

Attributes inherited from Axiom::SQL::Generator::Relation

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binary

#visit_axiom_algebra_join, #visit_axiom_algebra_product

Methods inherited from Axiom::SQL::Generator::Relation

#initialize, #to_s, #to_sql, #to_subquery, visit, #visit, #visited?

Methods included from Identifier

#visit_identifier

Methods included from Attribute

#visit_axiom_attribute

Methods inherited from Visitor

handler_for, #visit, #visited?

Constructor Details

This class inherits a constructor from Axiom::SQL::Generator::Relation

Class Method Details

.normalize_operand_headers(relation) ⇒ Relation::Operation::Set

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalize the headers of the operands

This is necessary to make sure the columns are in the correct order when generating SQL.

Parameters:

  • relation (Relation::Operation::Set)

Returns:

  • (Relation::Operation::Set)


25
26
27
28
29
30
31
32
33
34
# File 'lib/axiom/sql/generator/relation/set.rb', line 25

def self.normalize_operand_headers(relation)
  left        = relation.left
  right       = relation.right
  left_header = left.header
  if left_header.to_a != right.header.to_a
    relation.class.new(left, right.project(left_header))
  else
    relation
  end
end

Instance Method Details

#visit_axiom_algebra_difference(difference) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Visit an Difference

Parameters:

  • difference (Algebra::Difference)

Returns:

  • (self)


71
72
73
74
75
76
# File 'lib/axiom/sql/generator/relation/set.rb', line 71

def visit_axiom_algebra_difference(difference)
  set_operation(DIFFERENCE)
  set_operands(difference)
  set_name
  self
end

#visit_axiom_algebra_intersection(intersection) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Visit an Intersection

Parameters:

  • intersection (Algebra::Intersection)

Returns:

  • (self)


57
58
59
60
61
62
# File 'lib/axiom/sql/generator/relation/set.rb', line 57

def visit_axiom_algebra_intersection(intersection)
  set_operation(INTERSECTION)
  set_operands(intersection)
  set_name
  self
end

#visit_axiom_algebra_union(union) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Visit a Union

Parameters:

  • union (Algebra::Union)

Returns:

  • (self)


43
44
45
46
47
48
# File 'lib/axiom/sql/generator/relation/set.rb', line 43

def visit_axiom_algebra_union(union)
  set_operation(UNION)
  set_operands(union)
  set_name
  self
end