Skip to content

Commit

Permalink
Alias filter operations to their Cascading equivalents, but prefer ve…
Browse files Browse the repository at this point in the history
…rbs to nouns for operations
  • Loading branch information
mrwalker committed Apr 19, 2013
1 parent 07d7c3a commit 9ba7db1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/cascading/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module Cascading
# [input] c.p.Each argument selector
# [into] c.o.Operation field declaration
# [output] c.p.Each output selector
#
# A note on aliases: when a DSL method uniquely wraps a single Cascading
# operation, we attempt to provide an alias that matches the Cascading
# operation. However, Cascading operations are often nouns rather than verbs,
# and the latter are preferable for a dataflow DSL.
class Assembly < Cascading::Node
attr_reader :head_pipe, :tail_pipe

Expand Down
7 changes: 4 additions & 3 deletions lib/cascading/filter_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ module FilterOperations
#
# Example:
# filter :input => 'field1', :regex => /\t/, :remove_match => true
# filter :expression => 'field1:long > 0 && "".equals(field2:string)', :remove_match => true
# filter :expression => 'field1:long > 0 && "".equals(field2:string)'
def filter(options = {})
input_fields = options[:input] || all_fields
expression = options[:expression]
regex = options[:regex]
validate = options.has_key?(:validate) ? options[:validate] : true
validate_with = options[:validate_with] || {}

if expression
validate = options.has_key?(:validate) ? options[:validate] : true
validate_with = options[:validate_with] || {}

stub = expr(expression, { :validate => validate, :validate_with => validate_with })
stub.validate_scope(scope)

Expand Down
5 changes: 5 additions & 0 deletions lib/cascading/regex_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def parse(input_field, regex, into_fields, options = {})
:output => output
)
end
alias regex_parser parse

# Splits the given input_field into multiple fields using the specified
# regular expression.
Expand All @@ -59,6 +60,7 @@ def split(input_field, regex, into_fields, options = {})
:output => output
)
end
alias regex_splitter split

# Splits the given input_field into new rows using the specified regular
# expression.
Expand All @@ -79,6 +81,7 @@ def split_rows(input_field, regex, into_field, options = {})
:output => output
)
end
alias regex_split_generator split_rows

# Emits a new row for each regex group matched in input_field using the
# specified regular expression.
Expand All @@ -99,6 +102,7 @@ def match_rows(input_field, regex, into_field, options = {})
:output => output
)
end
alias regex_generator match_rows

# Performs a query/replace on the given input_field using the specified
# regular expression and replacement.
Expand All @@ -124,5 +128,6 @@ def replace(input_field, regex, into_field, replacement, options = {})
:output => output
)
end
alias regex_replace replace
end
end

0 comments on commit 9ba7db1

Please sign in to comment.