Skip to content

Commit

Permalink
fix bug on ZIP function when handling a list with only singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
randomboolean committed Mar 1, 2016
1 parent d037227 commit ebd1f83
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions warp10/src/main/java/io/warp10/continuum/gts/ZIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException {
// Check the size of the various lists, they are either singletons or of the same size
//

int len = -1;
int len = 1;

for (Object o: metalist) {
if (!(o instanceof List)) {
Expand All @@ -66,7 +66,7 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException {
continue;
}

if (-1 == len) {
if (1 == len) {
len = size;
} else if (size != len) {
throw new WarpScriptException(getName() + " operates on lists of lists. All lists which are not singletons must be of the same size.");
Expand All @@ -77,6 +77,21 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException {

List<List<Object>> results = new ArrayList<List<Object>>();

// in the case the list contains only singletons, we concatenate them together.
if (1 == len) {
List<Object> flat = new ArrayList<Object>();

for (Object l : metalist) {
flat.add(((List) l).get(0));
}

results.add(flat);

stack.push(results);

return stack;
}

while (i < len) {
List<Object> l = new ArrayList<Object>();

Expand Down

1 comment on commit ebd1f83

@hbs
Copy link
Collaborator

@hbs hbs commented on ebd1f83 Mar 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please simplify your fix as you suggested :-)

Please sign in to comment.