Class: Veritas::SQL::Generator::Relation::Set

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

Overview

Generates an SQL statement for a set relation

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 Veritas::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 Veritas::SQL::Generator::Relation

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binary

#visit_veritas_algebra_join, #visit_veritas_algebra_product

Methods inherited from Veritas::SQL::Generator::Relation

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

Methods included from Identifier

#visit_identifier

Methods included from Attribute

#visit_veritas_attribute

Methods inherited from Visitor

handler_for, #visit, #visited?

Constructor Details

This class inherits a constructor from Veritas::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/veritas/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_veritas_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/veritas/sql/generator/relation/set.rb', line 71

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

#visit_veritas_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/veritas/sql/generator/relation/set.rb', line 57

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

#visit_veritas_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/veritas/sql/generator/relation/set.rb', line 43

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