Skip to content

Commit

Permalink
PR #444: Relax join.as() validations to tolerate missing and duplicat…
Browse files Browse the repository at this point in the history
…e prefixes

Signed-off-by: Jon Seymour <[email protected]>
  • Loading branch information
jonseymour committed Apr 9, 2016
1 parent 9f72163 commit 63673e0
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions pipeline/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,18 @@ func (j *JoinNode) On(dims ...string) *JoinNode {

// Validate that the as() specification is consistent with the number of join arms.
func (j *JoinNode) Validate() error {
if len(j.Names) == 0 {
return fmt.Errorf("a call to join.as() is required to specify the output stream prefixes.")
}

if len(j.Names) != len(j.Parents()) {
if len(j.Names) > len(j.Parents()) {
return fmt.Errorf("number of prefixes specified by join.as() must match the number of joined streams")
} else if len(j.Names) < len(j.Parents()) {
tmp := make([]string, len(j.Parents()))
copy(tmp, j.Names)
j.Names = tmp
}

for _, name := range j.Names {
if len(name) == 0 {
return fmt.Errorf("must provide a prefix name for the join node, see .as() property method")
}
if strings.ContainsRune(name, '.') {
return fmt.Errorf("cannot use name %s as field prefix, it contains a '.' character", name)
}
}
names := make(map[string]bool, len(j.Names))
for _, name := range j.Names {
if names[name] {
return fmt.Errorf("cannot use the same prefix name see .as() property method")
}
names[name] = true
}

return nil
}

0 comments on commit 63673e0

Please sign in to comment.