piglet 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +24 -4
- data/lib/piglet/field/binary_conditional.rb +15 -0
- data/lib/piglet/field/call_expression.rb +21 -0
- data/lib/piglet/field/infix_expression.rb +19 -0
- data/lib/piglet/field/literal.rb +20 -0
- data/lib/piglet/field/operators.rb +80 -0
- data/lib/piglet/field/prefix_expression.rb +23 -0
- data/lib/piglet/field/reference.rb +41 -0
- data/lib/piglet/field/rename.rb +13 -0
- data/lib/piglet/field/suffix_expression.rb +19 -0
- data/lib/piglet/inout/describe.rb +7 -0
- data/lib/piglet/inout/dump.rb +7 -0
- data/lib/piglet/inout/explain.rb +15 -0
- data/lib/piglet/inout/illustrate.rb +7 -0
- data/lib/piglet/inout/load.rb +31 -0
- data/lib/piglet/inout/output.rb +15 -0
- data/lib/piglet/inout/storage_types.rb +18 -0
- data/lib/piglet/inout/store.rb +19 -0
- data/lib/piglet/interpreter.rb +39 -7
- data/lib/piglet/relation/cogroup.rb +33 -0
- data/lib/piglet/relation/cross.rb +24 -0
- data/lib/piglet/relation/distinct.rb +18 -0
- data/lib/piglet/relation/filter.rb +15 -0
- data/lib/piglet/relation/foreach.rb +21 -0
- data/lib/piglet/relation/group.rb +23 -0
- data/lib/piglet/relation/join.rb +22 -0
- data/lib/piglet/relation/limit.rb +15 -0
- data/lib/piglet/relation/order.rb +31 -0
- data/lib/piglet/relation/relation.rb +179 -0
- data/lib/piglet/relation/sample.rb +15 -0
- data/lib/piglet/relation/split.rb +45 -0
- data/lib/piglet/relation/stream.rb +7 -0
- data/lib/piglet/relation/union.rb +21 -0
- data/lib/piglet.rb +40 -38
- data/spec/piglet/{field_spec.rb → field/reference_spec.rb} +22 -6
- data/spec/piglet/interpreter_spec.rb +51 -5
- data/spec/piglet/{relation_spec.rb → relation/relation_spec.rb} +6 -6
- data/spec/piglet/{split_spec.rb → relation/split_spec.rb} +8 -8
- data/spec/spec_helper.rb +0 -2
- metadata +39 -40
- data/examples/spike1.rb +0 -43
- data/examples/spike2.rb +0 -40
- data/lib/piglet/assignment.rb +0 -13
- data/lib/piglet/cogroup.rb +0 -31
- data/lib/piglet/cross.rb +0 -22
- data/lib/piglet/describe.rb +0 -5
- data/lib/piglet/distinct.rb +0 -16
- data/lib/piglet/dump.rb +0 -5
- data/lib/piglet/explain.rb +0 -13
- data/lib/piglet/field.rb +0 -40
- data/lib/piglet/field_expression_functions.rb +0 -62
- data/lib/piglet/field_function_expression.rb +0 -19
- data/lib/piglet/field_infix_expression.rb +0 -17
- data/lib/piglet/field_prefix_expression.rb +0 -21
- data/lib/piglet/field_rename.rb +0 -11
- data/lib/piglet/field_suffix_expression.rb +0 -17
- data/lib/piglet/filter.rb +0 -13
- data/lib/piglet/foreach.rb +0 -19
- data/lib/piglet/group.rb +0 -21
- data/lib/piglet/illustrate.rb +0 -5
- data/lib/piglet/join.rb +0 -20
- data/lib/piglet/limit.rb +0 -13
- data/lib/piglet/load.rb +0 -31
- data/lib/piglet/load_and_store.rb +0 -16
- data/lib/piglet/order.rb +0 -29
- data/lib/piglet/relation.rb +0 -177
- data/lib/piglet/sample.rb +0 -13
- data/lib/piglet/split.rb +0 -41
- data/lib/piglet/store.rb +0 -17
- data/lib/piglet/storing.rb +0 -13
- data/lib/piglet/stream.rb +0 -5
- data/lib/piglet/union.rb +0 -19
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piglet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Hultberg
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-07 00:00:00 +01:00
|
13
13
|
default_executable: piglet
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,44 +38,43 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- bin/piglet
|
41
|
-
- examples/spike1.rb
|
42
|
-
- examples/spike2.rb
|
43
41
|
- lib/piglet.rb
|
44
|
-
- lib/piglet/
|
45
|
-
- lib/piglet/
|
46
|
-
- lib/piglet/
|
47
|
-
- lib/piglet/
|
48
|
-
- lib/piglet/
|
49
|
-
- lib/piglet/
|
50
|
-
- lib/piglet/
|
51
|
-
- lib/piglet/field.rb
|
52
|
-
- lib/piglet/
|
53
|
-
- lib/piglet/
|
54
|
-
- lib/piglet/
|
55
|
-
- lib/piglet/
|
56
|
-
- lib/piglet/
|
57
|
-
- lib/piglet/
|
58
|
-
- lib/piglet/
|
59
|
-
- lib/piglet/
|
60
|
-
- lib/piglet/
|
61
|
-
- lib/piglet/illustrate.rb
|
42
|
+
- lib/piglet/field/binary_conditional.rb
|
43
|
+
- lib/piglet/field/call_expression.rb
|
44
|
+
- lib/piglet/field/infix_expression.rb
|
45
|
+
- lib/piglet/field/literal.rb
|
46
|
+
- lib/piglet/field/operators.rb
|
47
|
+
- lib/piglet/field/prefix_expression.rb
|
48
|
+
- lib/piglet/field/reference.rb
|
49
|
+
- lib/piglet/field/rename.rb
|
50
|
+
- lib/piglet/field/suffix_expression.rb
|
51
|
+
- lib/piglet/inout/describe.rb
|
52
|
+
- lib/piglet/inout/dump.rb
|
53
|
+
- lib/piglet/inout/explain.rb
|
54
|
+
- lib/piglet/inout/illustrate.rb
|
55
|
+
- lib/piglet/inout/load.rb
|
56
|
+
- lib/piglet/inout/output.rb
|
57
|
+
- lib/piglet/inout/storage_types.rb
|
58
|
+
- lib/piglet/inout/store.rb
|
62
59
|
- lib/piglet/interpreter.rb
|
63
|
-
- lib/piglet/
|
64
|
-
- lib/piglet/
|
65
|
-
- lib/piglet/
|
66
|
-
- lib/piglet/
|
67
|
-
- lib/piglet/
|
68
|
-
- lib/piglet/relation.rb
|
69
|
-
- lib/piglet/
|
70
|
-
- lib/piglet/
|
71
|
-
- lib/piglet/
|
72
|
-
- lib/piglet/
|
73
|
-
- lib/piglet/
|
74
|
-
- lib/piglet/
|
75
|
-
-
|
60
|
+
- lib/piglet/relation/cogroup.rb
|
61
|
+
- lib/piglet/relation/cross.rb
|
62
|
+
- lib/piglet/relation/distinct.rb
|
63
|
+
- lib/piglet/relation/filter.rb
|
64
|
+
- lib/piglet/relation/foreach.rb
|
65
|
+
- lib/piglet/relation/group.rb
|
66
|
+
- lib/piglet/relation/join.rb
|
67
|
+
- lib/piglet/relation/limit.rb
|
68
|
+
- lib/piglet/relation/order.rb
|
69
|
+
- lib/piglet/relation/relation.rb
|
70
|
+
- lib/piglet/relation/sample.rb
|
71
|
+
- lib/piglet/relation/split.rb
|
72
|
+
- lib/piglet/relation/stream.rb
|
73
|
+
- lib/piglet/relation/union.rb
|
74
|
+
- spec/piglet/field/reference_spec.rb
|
76
75
|
- spec/piglet/interpreter_spec.rb
|
77
|
-
- spec/piglet/relation_spec.rb
|
78
|
-
- spec/piglet/split_spec.rb
|
76
|
+
- spec/piglet/relation/relation_spec.rb
|
77
|
+
- spec/piglet/relation/split_spec.rb
|
79
78
|
- spec/piglet_spec.rb
|
80
79
|
- spec/spec.opts
|
81
80
|
- spec/spec_helper.rb
|
@@ -111,9 +110,9 @@ signing_key:
|
|
111
110
|
specification_version: 3
|
112
111
|
summary: Piglet is a DSL for Pig scripts
|
113
112
|
test_files:
|
114
|
-
- spec/piglet/
|
113
|
+
- spec/piglet/field/reference_spec.rb
|
115
114
|
- spec/piglet/interpreter_spec.rb
|
116
|
-
- spec/piglet/relation_spec.rb
|
117
|
-
- spec/piglet/split_spec.rb
|
115
|
+
- spec/piglet/relation/relation_spec.rb
|
116
|
+
- spec/piglet/relation/split_spec.rb
|
118
117
|
- spec/piglet_spec.rb
|
119
118
|
- spec/spec_helper.rb
|
data/examples/spike1.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# raw_ads =
|
2
|
-
# LOAD '$INPUT/ads*'
|
3
|
-
# USING PigStorage AS (
|
4
|
-
# ad_id:chararray,
|
5
|
-
# api_key:chararray,
|
6
|
-
# name:chararray,
|
7
|
-
# dimensions:chararray,
|
8
|
-
# destination:chararray,
|
9
|
-
# agent_version:chararray
|
10
|
-
# );
|
11
|
-
raw_ads << load('$INPUT/ads*').using(:pig_storage).as(
|
12
|
-
[:ad_id, :chararray],
|
13
|
-
[:api_key, :chararray],
|
14
|
-
[:name, :chararray],
|
15
|
-
[:dimensions, :chararray],
|
16
|
-
[:destination, :chararray],
|
17
|
-
[:agent_version, :chararray]
|
18
|
-
)
|
19
|
-
|
20
|
-
# ads =
|
21
|
-
# FOREACH
|
22
|
-
# (GROUP raw_ads BY ad_id PARALLEL $PARALLELISM)
|
23
|
-
# GENERATE
|
24
|
-
# $0 AS ad_id,
|
25
|
-
# MAX($1.api_key) AS api_key,
|
26
|
-
# MAX($1.name) AS name,
|
27
|
-
# MAX($1.dimensions) AS dimensions,
|
28
|
-
# MAX($1.destination) AS destination,
|
29
|
-
# MAX($1.agent_version) AS agent_version
|
30
|
-
# ;
|
31
|
-
ads << (raw_ads.group(:ad_id)).foreach do |relation|
|
32
|
-
[
|
33
|
-
relation[0].as(:ad_id),
|
34
|
-
relation[1].api_key.max.as(:api_key),
|
35
|
-
relation[1].name.max.as(:name),
|
36
|
-
relation[1].dimensions.max.as(:dimensions),
|
37
|
-
relation[1].destination.max.as(:destination),
|
38
|
-
relation[1].agent_version.max.as(:agent_version)
|
39
|
-
]
|
40
|
-
end
|
41
|
-
|
42
|
-
# STORE ads INTO '$OUTPUT/ads' USING PigStorage;
|
43
|
-
ads.store('$OUTPUT/ads').using(:pig_storage)
|
data/examples/spike2.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# raw_ads =
|
2
|
-
# LOAD '$INPUT/ads*'
|
3
|
-
# USING PigStorage AS (
|
4
|
-
# ad_id:chararray,
|
5
|
-
# api_key:chararray,
|
6
|
-
# name:chararray,
|
7
|
-
# dimensions:chararray,
|
8
|
-
# destination:chararray,
|
9
|
-
# agent_version:chararray
|
10
|
-
# );
|
11
|
-
raw_ads = load(
|
12
|
-
'$INPUT/ads*',
|
13
|
-
:using => :pig_storage,
|
14
|
-
:schema => %w(ad_id api_key name dimensions destination agent_version)
|
15
|
-
)
|
16
|
-
|
17
|
-
# ads =
|
18
|
-
# FOREACH
|
19
|
-
# (GROUP raw_ads BY ad_id PARALLEL $PARALLELISM)
|
20
|
-
# GENERATE
|
21
|
-
# $0 AS ad_id,
|
22
|
-
# MAX($1.api_key) AS api_key,
|
23
|
-
# MAX($1.name) AS name,
|
24
|
-
# MAX($1.dimensions) AS dimensions,
|
25
|
-
# MAX($1.destination) AS destination,
|
26
|
-
# MAX($1.agent_version) AS agent_version
|
27
|
-
# ;
|
28
|
-
ads = raw_ads.group(:ad_id, :parallel => 2).foreach do |relation|
|
29
|
-
[
|
30
|
-
relation[0].as(:ad_id),
|
31
|
-
relation[1].api_key.as(:api_key)
|
32
|
-
relation[1].name.max.as(:name)
|
33
|
-
relation[1].dimensions.max.as(:dimensions)
|
34
|
-
relation[1].destination.max.as(:destination)
|
35
|
-
relation[1].agent_version.max.as(:agent_version)
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
# STORE ads INTO '$OUTPUT/ads' USING PigStorage;
|
40
|
-
store(ads, '$OUTPUT/ads', :using => :pig_storage)
|
data/lib/piglet/assignment.rb
DELETED
data/lib/piglet/cogroup.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Cogroup # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, description)
|
6
|
-
@join_fields = description.reject { |k, v| ! (k.is_a?(Relation)) }
|
7
|
-
@sources = @join_fields.keys
|
8
|
-
@parallel = description[:parallel]
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
joins = @sources.map do |s|
|
13
|
-
fields = @join_fields[s]
|
14
|
-
if fields.is_a?(Enumerable) && fields.size > 1 && (fields.last == :inner || fields.last == :outer)
|
15
|
-
inout = fields.last.to_s.upcase
|
16
|
-
fields = fields[0..-2]
|
17
|
-
end
|
18
|
-
if fields.is_a?(Enumerable) && fields.size > 1
|
19
|
-
str = "#{s.alias} BY (#{fields.join(', ')})"
|
20
|
-
else
|
21
|
-
str = "#{s.alias} BY #{fields}"
|
22
|
-
end
|
23
|
-
str << " #{inout}" if inout
|
24
|
-
str
|
25
|
-
end
|
26
|
-
str = "COGROUP #{joins.join(', ')}"
|
27
|
-
str << " PARALLEL #{@parallel}" if @parallel
|
28
|
-
str
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/piglet/cross.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Cross # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relations, options={})
|
6
|
-
options ||= {}
|
7
|
-
@sources, @parallel = relations, options[:parallel]
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
str = "CROSS #{source_aliases.join(', ')}"
|
12
|
-
str << " PARALLEL #{@parallel}" if @parallel
|
13
|
-
str
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def source_aliases
|
19
|
-
@sources.map { |s| s.alias }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/piglet/describe.rb
DELETED
data/lib/piglet/distinct.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Distinct # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, options={})
|
6
|
-
options ||= {}
|
7
|
-
@sources, @parallel = [relation], options[:parallel]
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
str = "DISTINCT #{@sources.first.alias}"
|
12
|
-
str << " PARALLEL #{@parallel}" if @parallel
|
13
|
-
str
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/piglet/dump.rb
DELETED
data/lib/piglet/explain.rb
DELETED
data/lib/piglet/field.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Field # :nodoc:
|
3
|
-
include FieldExpressionFunctions
|
4
|
-
|
5
|
-
def initialize(name, relation=nil, options=nil)
|
6
|
-
options ||= {}
|
7
|
-
@name, @parent = name, relation
|
8
|
-
@explicit_ancestry = options[:explicit_ancestry] || false
|
9
|
-
end
|
10
|
-
|
11
|
-
def simple?
|
12
|
-
true
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(name, *args)
|
16
|
-
if name.to_s =~ /^\w+$/ && args.empty?
|
17
|
-
Field.new(name, self, :explicit_ancestry => true)
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def [](n)
|
24
|
-
Field.new("\$#{n}", self, :explicit_ancestry => true)
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_s
|
28
|
-
if @explicit_ancestry
|
29
|
-
if @parent.respond_to?(:alias)
|
30
|
-
"#{@parent.alias}.#{@name.to_s}"
|
31
|
-
else
|
32
|
-
"#{@parent}.#{@name.to_s}"
|
33
|
-
end
|
34
|
-
else
|
35
|
-
@name.to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
module FieldExpressionFunctions # :nodoc:
|
3
|
-
SYMBOLIC_OPERATORS = [:==, :>, :<, :>=, :<=, :%, :+, :-, :*, :/]
|
4
|
-
FUNCTIONS = [:avg, :count, :diff, :max, :min, :size, :sum, :tokenize]
|
5
|
-
|
6
|
-
FUNCTIONS.each do |fun|
|
7
|
-
define_method(fun) { FieldFunctionExpression.new(fun.to_s.upcase, self) }
|
8
|
-
end
|
9
|
-
|
10
|
-
def empty?
|
11
|
-
FieldFunctionExpression.new('IsEmpty', self)
|
12
|
-
end
|
13
|
-
|
14
|
-
def as(new_name)
|
15
|
-
FieldRename.new(new_name, self)
|
16
|
-
end
|
17
|
-
|
18
|
-
def not
|
19
|
-
FieldPrefixExpression.new('NOT', self)
|
20
|
-
end
|
21
|
-
|
22
|
-
def null?
|
23
|
-
FieldSuffixExpression.new('is null', self)
|
24
|
-
end
|
25
|
-
|
26
|
-
def not_null?
|
27
|
-
FieldSuffixExpression.new('is not null', self)
|
28
|
-
end
|
29
|
-
|
30
|
-
def cast(type)
|
31
|
-
FieldPrefixExpression.new("(#{type.to_s})", self)
|
32
|
-
end
|
33
|
-
|
34
|
-
def matches(pattern)
|
35
|
-
regex_options_pattern = /^\(\?.+?:(.*)\)$/
|
36
|
-
pattern = pattern.to_s.sub(regex_options_pattern, '\1') if pattern.is_a?(Regexp) && pattern.to_s =~ regex_options_pattern
|
37
|
-
FieldInfixExpression.new('matches', self, "'#{pattern.to_s}'")
|
38
|
-
end
|
39
|
-
|
40
|
-
def neg
|
41
|
-
FieldPrefixExpression.new('-', self, false)
|
42
|
-
end
|
43
|
-
|
44
|
-
def ne(other)
|
45
|
-
FieldInfixExpression.new('!=', self, other)
|
46
|
-
end
|
47
|
-
|
48
|
-
SYMBOLIC_OPERATORS.each do |op|
|
49
|
-
define_method(op) { |other| FieldInfixExpression.new(op.to_s, self, other) }
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
def parenthesise(expr)
|
55
|
-
if expr.respond_to?(:simple?) && ! expr.simple?
|
56
|
-
"(#{expr})"
|
57
|
-
else
|
58
|
-
expr.to_s
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class FieldFunctionExpression # :nodoc:
|
3
|
-
include FieldExpressionFunctions
|
4
|
-
|
5
|
-
def initialize(name, inner_expression, options=nil)
|
6
|
-
options ||= {}
|
7
|
-
@name, @inner_expression = name, inner_expression
|
8
|
-
@new_name = options[:as]
|
9
|
-
end
|
10
|
-
|
11
|
-
def simple?
|
12
|
-
false
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_s
|
16
|
-
"#{@name}(#{@inner_expression})"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class FieldInfixExpression # :nodoc:
|
3
|
-
include FieldExpressionFunctions
|
4
|
-
|
5
|
-
def initialize(operator, left_expression, right_expression)
|
6
|
-
@operator, @left_expression, @right_expression = operator, left_expression, right_expression
|
7
|
-
end
|
8
|
-
|
9
|
-
def simple?
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
"#{parenthesise(@left_expression)} #{@operator} #{parenthesise(@right_expression)}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class FieldPrefixExpression # :nodoc:
|
3
|
-
include FieldExpressionFunctions
|
4
|
-
|
5
|
-
def initialize(operator, expression, space_between=true)
|
6
|
-
@operator, @expression, @space_between = operator, expression, space_between
|
7
|
-
end
|
8
|
-
|
9
|
-
def simple?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
if @space_between
|
15
|
-
"#{@operator} #{parenthesise(@expression)}"
|
16
|
-
else
|
17
|
-
"#{@operator}#{parenthesise(@expression)}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/piglet/field_rename.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class FieldSuffixExpression # :nodoc:
|
3
|
-
include FieldExpressionFunctions
|
4
|
-
|
5
|
-
def initialize(operator, expression)
|
6
|
-
@operator, @expression = operator, expression
|
7
|
-
end
|
8
|
-
|
9
|
-
def simple?
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
"#{parenthesise(@expression)} #{@operator}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/piglet/filter.rb
DELETED
data/lib/piglet/foreach.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Foreach # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, field_expressions)
|
6
|
-
@sources, @field_expressions = [relation], [field_expressions].flatten
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
"FOREACH #{@sources.first.alias} GENERATE #{field_expressions_string}"
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def field_expressions_string
|
16
|
-
@field_expressions.map { |fe| fe.to_s }.join(', ')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/piglet/group.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Group # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, grouping, options={})
|
6
|
-
options ||= {}
|
7
|
-
@sources, @grouping, @parallel = [relation], grouping, options[:parallel]
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
str = "GROUP #{@sources.first.alias} BY "
|
12
|
-
if @grouping.size > 1
|
13
|
-
str << "(#{@grouping.join(', ')})"
|
14
|
-
else
|
15
|
-
str << @grouping.first.to_s
|
16
|
-
end
|
17
|
-
str << " PARALLEL #{@parallel}" if @parallel
|
18
|
-
str
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/piglet/illustrate.rb
DELETED
data/lib/piglet/join.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Join # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, description)
|
6
|
-
@join_fields = Hash[*description.select { |k, v| k.is_a?(Relation) }.flatten]
|
7
|
-
@sources = @join_fields.keys
|
8
|
-
@using = description[:using]
|
9
|
-
@parallel = description[:parallel]
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
joins = @sources.map { |s| "#{s.alias} BY #{@join_fields[s]}" }.join(', ')
|
14
|
-
str = "JOIN #{joins}"
|
15
|
-
str << " USING \"#{@using.to_s}\"" if @using
|
16
|
-
str << " PARALLEL #{@parallel}" if @parallel
|
17
|
-
str
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/piglet/limit.rb
DELETED
data/lib/piglet/load.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Load # :nodoc:
|
3
|
-
include Relation
|
4
|
-
include LoadAndStore
|
5
|
-
|
6
|
-
def initialize(path, options={})
|
7
|
-
options ||= {}
|
8
|
-
@path, @using, @schema = path, options[:using], options[:schema]
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
str = "LOAD '#{@path}'"
|
13
|
-
str << " USING #{resolve_load_store_function(@using)}" if @using
|
14
|
-
str << " AS (#{schema_string})" if @schema
|
15
|
-
str
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def schema_string
|
21
|
-
@schema.map do |field|
|
22
|
-
if field.is_a?(Enumerable)
|
23
|
-
field.map { |f| f.to_s }.join(':')
|
24
|
-
else
|
25
|
-
field.to_s
|
26
|
-
end
|
27
|
-
end.join(', ')
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
module LoadAndStore # :nodoc:
|
3
|
-
LOAD_STORE_FUNCTIONS = {
|
4
|
-
:binary_serializer => 'BinarySerializer',
|
5
|
-
:binary_deserializer => 'BinaryDeserializer',
|
6
|
-
:bin_storage => 'BinStorage',
|
7
|
-
:pig_storage => 'PigStorage',
|
8
|
-
:pig_dump => 'PigDump',
|
9
|
-
:text_loader => 'TextLoader'
|
10
|
-
}
|
11
|
-
|
12
|
-
def resolve_load_store_function(name)
|
13
|
-
LOAD_STORE_FUNCTIONS[name] || name.to_s
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/piglet/order.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Piglet
|
2
|
-
class Order # :nodoc:
|
3
|
-
include Relation
|
4
|
-
|
5
|
-
def initialize(relation, fields, options)
|
6
|
-
options ||= {}
|
7
|
-
@sources, @parallel = [relation], options[:parallel]
|
8
|
-
@fields = fields.is_a?(Enumerable) ? fields : [fields]
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"ORDER #{@sources.first.alias} BY #{field_strings}"
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def field_strings
|
18
|
-
@fields.map { |f| field_string(f) }.join(', ')
|
19
|
-
end
|
20
|
-
|
21
|
-
def field_string(f)
|
22
|
-
if f.is_a?(Enumerable)
|
23
|
-
"#{f[0]} #{f[1].to_s.upcase}"
|
24
|
-
else
|
25
|
-
f.to_s
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|