I have a data like this .

```
 1:23:0.20
 2:34:0.50
 3:67:0.90
 4:87:0.10
 5:23:0.12

```

I am trying to sum the every 2 rows last column values like this.

```
0.20+0.50 = 0.70
0.90+0.10 = 1.0

```

and print like this 

```
 1:23:0.20:0.70
 2:34:0.50:0.70
 3:67:0.90:1.0
 4:87:0.10:1.0
 5:23:0.12

```

This is my pig script

```
 data = LOAD '/home/user/Documents/test/test.txt' using PigStorage(':') AS (tag:int,rssi:chararray,weightage:chararray,seqnum:int);
B = FOREACH (GROUP data ALL) {
A_ordered = ORDER data BY rssi;
GENERATE FLATTEN(CUSTOM_UDF(A_ordered));
}

```

I tried with java UDF. but not works properly.

```
this is what I tried.

public List<String> sumValues() {
    List<String> processedList = new ArrayList<>();
    if (entries == null) {
        return processedList;
    } else {
        double columnSum = 0;
        List<String> tempList = new ArrayList<>(); 
        int length = entries.size();
        for (int index = 1; index <= length; index++) {
            tempList.add(entries.get(index - 1)); 
            String[] splitValues = entries.get(index - 1).split(DELIMITER);
            if (splitValues.length >= MIN_SPLIT_STRING_LENGTH) {

                try {
                    double lastValue = Double.parseDouble(splitValues[WEIGHTAGE_INDEX]);
                    columnSum = columnSum + lastValue;

                    if ((index % ROWS_TO_BE_SUMMED == 0) || (index == length)) {
                        for (String tempString : tempList) {
                            processedList.add(tempString + ":" + columnSum);
                        }
                        tempList.clear(); // Clear the temporary array
                        columnSum = 0;
                    }
                } catch (NumberFormatException e) {
                    System.out.println("Invalid weightage");
                }
            } else {
                System.out.println("Invalid input");
            }
        }
    }
    return processedList;
}

@Override
public String exec(Tuple input) throws IOException {
    System.out.println("------INSIDE EXEC FUCTION ----" + input);
    if (input != null && input.size() != 0) {
        try {
            String str = (String) input.get(0);
            if (str != null) {
                String splitStrings[] = str.split(":");
                if (splitStrings != null && splitStrings.length >= 3 && splitStrings[2].equals(EXIT)) {
                    List<String> processedList = sumValues();
                    String sum = processedList.toString();
                    System.out.println("SUM VALUE----:" + sum);
                    return sum;
                } else {
                    System.out.println("INPUT VALUE----:" + str);
                    entries.add(str);
                    return null;
                }
            }
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
}

```

The above code prints empty results.
Any help will be appreciated.