Module: Piglet::Field::Field
- Included in:
- BinaryConditional, CallExpression, DirectExpression, InfixExpression, Literal, MapValue, PrefixExpression, Reference, SuffixExpression, UdfExpression
- Defined in:
- lib/piglet/field/field.rb
Overview
:nodoc:
Defined Under Namespace
Classes: DummyRelation
Constant Summary collapse
- SYMBOLIC_OPERATORS =
[:==, :>, :<, :>=, :<=, :%, :+, :-, :*, :/]
- FUNCTIONS =
[:avg, :count, :max, :min, :size, :sum, :tokenize]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#predecessors ⇒ Object
readonly
Returns the value of attribute predecessors.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #and(other) ⇒ Object
- #as(new_name) ⇒ Object
- #cast(type) ⇒ Object
- #diff(other) ⇒ Object
- #distinct ⇒ Object
- #empty? ⇒ Boolean
- #field(name) ⇒ Object
- #field_alias ⇒ Object
- #filter(&block) ⇒ Object
- #flatten ⇒ Object
- #generate_field_alias ⇒ Object
- #get(key) ⇒ Object
- #limit(size) ⇒ Object
- #matches(pattern) ⇒ Object
- #ne(other) ⇒ Object
- #neg ⇒ Object
- #not ⇒ Object
- #not_null? ⇒ Boolean
- #null? ⇒ Boolean
- #or(other) ⇒ Object
- #order(*args) ⇒ Object
- #sample(rate) ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/piglet/field/field.rb', line 9 def name @name end |
#predecessors ⇒ Object (readonly)
Returns the value of attribute predecessors.
9 10 11 |
# File 'lib/piglet/field/field.rb', line 9 def predecessors @predecessors end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/piglet/field/field.rb', line 9 def type @type end |
Instance Method Details
#and(other) ⇒ Object
59 60 61 |
# File 'lib/piglet/field/field.rb', line 59 def and(other) InfixExpression.new('AND', self, other, :type => :boolean) end |
#as(new_name) ⇒ Object
25 26 27 |
# File 'lib/piglet/field/field.rb', line 25 def as(new_name) Rename.new(new_name, self) end |
#cast(type) ⇒ Object
41 42 43 |
# File 'lib/piglet/field/field.rb', line 41 def cast(type) PrefixExpression.new("(#{type.to_s})", self, true, :type => type.to_sym) end |
#diff(other) ⇒ Object
21 22 23 |
# File 'lib/piglet/field/field.rb', line 21 def diff(other) raise NotSupportedError end |
#distinct ⇒ Object
89 90 91 |
# File 'lib/piglet/field/field.rb', line 89 def distinct DirectExpression.new("DISTINCT #{field_alias}", self) end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/piglet/field/field.rb', line 17 def empty? CallExpression.new('IsEmpty', self, :type => :boolean) end |
#field(name) ⇒ Object
119 120 121 |
# File 'lib/piglet/field/field.rb', line 119 def field(name) Reference.new(name, self, :explicit_ancestry => true) end |
#field_alias ⇒ Object
81 82 83 |
# File 'lib/piglet/field/field.rb', line 81 def field_alias @field_alias ||= generate_field_alias end |
#filter(&block) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/piglet/field/field.rb', line 108 def filter(&block) dummy_relation = DummyRelation.new(self.send(:alias)) context = Relation::BlockContext.new(dummy_relation, @interpreter) expression = context.instance_eval(&block) DirectExpression.new("FILTER #{field_alias} BY #{expression}", self) end |
#flatten ⇒ Object
115 116 117 |
# File 'lib/piglet/field/field.rb', line 115 def flatten DirectExpression.new("FLATTEN(#{field_alias})", self) end |
#generate_field_alias ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/piglet/field/field.rb', line 73 def generate_field_alias if @parent.respond_to?(:next_field_alias) @parent.next_field_alias elsif predecessors.first.respond_to?(:generate_field_alias) predecessors.first.generate_field_alias end end |
#get(key) ⇒ Object
123 124 125 |
# File 'lib/piglet/field/field.rb', line 123 def get(key) MapValue.new(key, self) end |
#limit(size) ⇒ Object
93 94 95 |
# File 'lib/piglet/field/field.rb', line 93 def limit(size) DirectExpression.new("LIMIT #{field_alias} #{size}", self) end |
#matches(pattern) ⇒ Object
45 46 47 48 49 |
# File 'lib/piglet/field/field.rb', line 45 def matches(pattern) = /^\(\?.+?:(.*)\)$/ pattern = pattern.to_s.sub(, '\1') if pattern.is_a?(Regexp) && pattern.to_s =~ InfixExpression.new('matches', self, "'#{pattern.to_s}'", :type => :boolean) end |
#ne(other) ⇒ Object
55 56 57 |
# File 'lib/piglet/field/field.rb', line 55 def ne(other) InfixExpression.new('!=', self, other, :type => :boolean) end |
#neg ⇒ Object
51 52 53 |
# File 'lib/piglet/field/field.rb', line 51 def neg PrefixExpression.new('-', self, false, :type => self.type) end |
#not ⇒ Object
29 30 31 |
# File 'lib/piglet/field/field.rb', line 29 def not PrefixExpression.new('NOT', self, true, :type => :boolean) end |
#not_null? ⇒ Boolean
37 38 39 |
# File 'lib/piglet/field/field.rb', line 37 def not_null? SuffixExpression.new('is not null', self, :type => :boolean) end |
#null? ⇒ Boolean
33 34 35 |
# File 'lib/piglet/field/field.rb', line 33 def null? SuffixExpression.new('is null', self, :type => :boolean) end |
#or(other) ⇒ Object
63 64 65 |
# File 'lib/piglet/field/field.rb', line 63 def or(other) InfixExpression.new('OR', self, other, :type => :boolean) end |
#order(*args) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/piglet/field/field.rb', line 101 def order(*args) fields, = (args) fields = *fields expression = Relation::Order.new(self, @interpreter, fields, ).to_s DirectExpression.new(expression, self) end |
#sample(rate) ⇒ Object
97 98 99 |
# File 'lib/piglet/field/field.rb', line 97 def sample(rate) DirectExpression.new("SAMPLE #{field_alias} #{rate}", self) end |