Class: Veritas::SQL::Generator::Relation::Unary
- Inherits:
-
Veritas::SQL::Generator::Relation
- Object
- Visitor
- Veritas::SQL::Generator::Relation
- Veritas::SQL::Generator::Relation::Unary
- Extended by:
- Aliasable
- Includes:
- Direction, Function::Aggregate, Function::Connective, Function::Numeric, Function::Predicate, Function::Proposition, Function::String, Literal
- Defined in:
- lib/veritas/sql/generator/relation/unary.rb
Overview
Generates an SQL statement for a unary relation
Direct Known Subclasses
Constant Summary collapse
- DISTINCT =
'DISTINCT '.freeze
- NO_ROWS =
' HAVING FALSE'.freeze
- ANY_ROWS =
' HAVING COUNT (*) > 0'
- COLLAPSIBLE =
{ Algebra::Summarization => Set[ ].freeze, Algebra::Projection => Set[ Algebra::Projection, Algebra::Restriction, ].freeze, Algebra::Extension => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Veritas::Relation::Operation::Offset, Veritas::Relation::Operation::Limit ].freeze, Algebra::Rename => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Veritas::Relation::Operation::Offset, Veritas::Relation::Operation::Limit ].freeze, Algebra::Restriction => Set[ Algebra::Projection, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, ].freeze, Veritas::Relation::Operation::Order => Set[ Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, ].freeze, Veritas::Relation::Operation::Reverse => Set[ Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, ].freeze, Veritas::Relation::Operation::Offset => Set[ Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, ].freeze, Veritas::Relation::Operation::Limit => Set[ Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Veritas::Relation::Operation::Offset, ].freeze, }.freeze
Constants included from Direction
Constants included from Identifier
Identifier::ESCAPED_QUOTE, Identifier::QUOTE
Constants included from Literal
Literal::ESCAPED_QUOTE, Literal::FALSE, Literal::NULL, Literal::QUOTE, Literal::SEPARATOR, Literal::TIME_SCALE, Literal::TRUE
Constants included from Function::Aggregate
Function::Aggregate::COUNT, Function::Aggregate::MAXIMUM, Function::Aggregate::MEAN, Function::Aggregate::MINIMUM, Function::Aggregate::STANDARD_DEVIATION, Function::Aggregate::SUM, Function::Aggregate::VARIANCE
Constants included from Function::Connective
Function::Connective::AND, Function::Connective::NOT, Function::Connective::OR
Constants included from Function::Predicate
Function::Predicate::BETWEEN, Function::Predicate::EMPTY_ARRAY, Function::Predicate::EQUAL_TO, Function::Predicate::EQUAL_TO_NULL, Function::Predicate::GREATER_THAN, Function::Predicate::GREATER_THAN_OR_EQUAL_TO, Function::Predicate::IN, Function::Predicate::LESS_THAN, Function::Predicate::LESS_THAN_OR_EQUAL_TO, Function::Predicate::NOT_BETWEEN, Function::Predicate::NOT_EQUAL_TO, Function::Predicate::NOT_EQUAL_TO_NULL, Function::Predicate::NOT_IN
Constants included from Function::String
Constants included from Function::Numeric
Function::Numeric::ABSOLUTE, Function::Numeric::ADD, Function::Numeric::DIVIDE, Function::Numeric::MOD, Function::Numeric::MULTIPLY, Function::Numeric::POWER, Function::Numeric::SQUARE_ROOT, Function::Numeric::SUBTRACT
Constants inherited from Veritas::SQL::Generator::Relation
EMPTY_HASH, EMPTY_STRING, SEPARATOR, STAR
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
Instance Method Summary collapse
-
#initialize ⇒ undefined
constructor
private
Initialize a Unary relation SQL generator.
-
#visit_veritas_algebra_extension(extension) ⇒ self
private
Visit an Extension.
-
#visit_veritas_algebra_projection(projection) ⇒ self
private
Visit a Projection.
-
#visit_veritas_algebra_rename(rename) ⇒ self
private
Visit a Rename.
-
#visit_veritas_algebra_restriction(restriction) ⇒ self
private
Visit a Restriction.
-
#visit_veritas_algebra_summarization(summarization) ⇒ self
private
Visit a Summarization.
-
#visit_veritas_relation_base(base_relation) ⇒ self
private
Visit a Base Relation.
-
#visit_veritas_relation_operation_limit(limit) ⇒ self
private
Visit a Limit.
-
#visit_veritas_relation_operation_offset(offset) ⇒ self
private
Visit an Offset.
-
#visit_veritas_relation_operation_order(order) ⇒ self
private
Visit an Order.
Methods included from Direction
#visit_veritas_relation_operation_order_ascending, #visit_veritas_relation_operation_order_descending
Methods included from Attribute
Methods included from Identifier
Methods included from Literal
dup_frozen, #visit_class, #visit_date, #visit_date_time, #visit_enumerable, #visit_false_class, #visit_nil_class, #visit_numeric, #visit_string, #visit_time, #visit_true_class
Methods included from Function::Aggregate
#visit_veritas_aggregate_count, #visit_veritas_aggregate_maximum, #visit_veritas_aggregate_mean, #visit_veritas_aggregate_minimum, #visit_veritas_aggregate_standard_deviation, #visit_veritas_aggregate_sum, #visit_veritas_aggregate_variance
Methods included from Function::Connective
#visit_veritas_function_connective_conjunction, #visit_veritas_function_connective_disjunction, #visit_veritas_function_connective_negation
Methods included from Function::Predicate
#visit_veritas_function_predicate_equality, #visit_veritas_function_predicate_exclusion, #visit_veritas_function_predicate_greater_than, #visit_veritas_function_predicate_greater_than_or_equal_to, #visit_veritas_function_predicate_inclusion, #visit_veritas_function_predicate_inequality, #visit_veritas_function_predicate_less_than, #visit_veritas_function_predicate_less_than_or_equal_to
Methods included from Function::Proposition
#visit_veritas_function_proposition_contradiction, #visit_veritas_function_proposition_tautology
Methods included from Function::String
#visit_veritas_function_string_length
Methods included from Function::Numeric
#visit_veritas_function_numeric_absolute, #visit_veritas_function_numeric_addition, #visit_veritas_function_numeric_division, #visit_veritas_function_numeric_exponentiation, #visit_veritas_function_numeric_modulo, #visit_veritas_function_numeric_multiplication, #visit_veritas_function_numeric_square_root, #visit_veritas_function_numeric_subtraction, #visit_veritas_function_numeric_unary_minus, #visit_veritas_function_numeric_unary_plus
Methods inherited from Veritas::SQL::Generator::Relation
#to_s, #to_sql, #to_subquery, #visit, visit, #visited?
Methods inherited from Visitor
handler_for, #visit, #visited?
Constructor Details
#initialize ⇒ undefined
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.
Initialize a Unary relation SQL generator
42 43 44 45 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 42 def initialize super @scope = ::Set.new end |
Instance Method Details
#visit_veritas_algebra_extension(extension) ⇒ 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 Extension
85 86 87 88 89 90 91 92 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 85 def visit_veritas_algebra_extension(extension) @from = subquery_for(extension) @header = extension.header @columns ||= columns_for(extension.operand) add_extensions(extension.extensions) scope_query(extension) self end |
#visit_veritas_algebra_projection(projection) ⇒ 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 Projection
69 70 71 72 73 74 75 76 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 69 def visit_veritas_algebra_projection(projection) @from = subquery_for(projection) @distinct = DISTINCT @header = projection.header @columns = columns_for(projection) scope_query(projection) self end |
#visit_veritas_algebra_rename(rename) ⇒ 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 Rename
101 102 103 104 105 106 107 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 101 def visit_veritas_algebra_rename(rename) @from = subquery_for(rename) @header = rename.header @columns = columns_for(rename.operand, rename.aliases.to_hash) scope_query(rename) self end |
#visit_veritas_algebra_restriction(restriction) ⇒ 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 Restriction
116 117 118 119 120 121 122 123 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 116 def visit_veritas_algebra_restriction(restriction) @from = subquery_for(restriction) @where = " WHERE #{dispatch(restriction.predicate)}" @header = restriction.header @columns ||= columns_for(restriction) scope_query(restriction) self end |
#visit_veritas_algebra_summarization(summarization) ⇒ 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 Summarization
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 132 def visit_veritas_algebra_summarization(summarization) summarize_per = summarization.summarize_per @from = subquery_for(summarization) @header = summarization.header @columns = columns_for(summarize_per) summarize_per(summarize_per) group_by_columns add_extensions(summarization.summarizers) scope_query(summarization) self end |
#visit_veritas_relation_base(base_relation) ⇒ 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 Base Relation
54 55 56 57 58 59 60 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 54 def visit_veritas_relation_base(base_relation) @name = base_relation.name @from = visit_identifier(@name) @header = base_relation.header @columns = columns_for(base_relation) self end |
#visit_veritas_relation_operation_limit(limit) ⇒ 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 Limit
167 168 169 170 171 172 173 174 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 167 def visit_veritas_relation_operation_limit(limit) @from = subquery_for(limit) @limit = " LIMIT #{limit.limit}" @header = limit.header @columns ||= columns_for(limit) scope_query(limit) self end |
#visit_veritas_relation_operation_offset(offset) ⇒ 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 Offset
183 184 185 186 187 188 189 190 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 183 def visit_veritas_relation_operation_offset(offset) @from = subquery_for(offset) @offset = " OFFSET #{offset.offset}" @header = offset.header @columns ||= columns_for(offset) scope_query(offset) self end |
#visit_veritas_relation_operation_order(order) ⇒ 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 Order
151 152 153 154 155 156 157 158 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 151 def visit_veritas_relation_operation_order(order) @from = subquery_for(order) @order = " ORDER BY #{order_for(order.directions)}" @header = order.header @columns ||= columns_for(order) scope_query(order) self end |