43 lines
2.0 KiB
C#
43 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
|
|
using BCG.Utilities;
|
|
|
|
namespace BCG {
|
|
/// <summary>
|
|
/// Computes the max for a given column
|
|
/// </summary>
|
|
public class MaxGroupByEvaluator : GroupByEvaluator {
|
|
|
|
public MaxGroupByEvaluator(string outputCol, string[] groupByCols) : base(outputCol, groupByCols) { }
|
|
|
|
public MaxGroupByEvaluator(string colMapEpression, string outputCol, string[] groupByCols)
|
|
: base(colMapEpression, outputCol, groupByCols) { }
|
|
|
|
public override IBlueRow evaluate(DataPacket dp) {
|
|
myOutputTable = myOutputTable == null ? new GroupByOutputTable(dp.schema) :
|
|
myOutputTable;
|
|
string hashString = BlueDataUtility.rowToString(GroupByStream.getRepRow(dp), myGroupByCols);
|
|
IBlueRow currMaxRow = myOutputTable.getRow(hashString);
|
|
IBlueRow maxRow = BlueDataUtility.computeMaxRow(dp.deletedRows, myOutputColumn);
|
|
if (maxRow != null) {
|
|
bts.Log.assert(currMaxRow != null);
|
|
bts.Log.assert(BlueDataUtility.compare_rows(maxRow, currMaxRow, myOutputColumn) <= 0);
|
|
if (BlueDataUtility.compare_rows(maxRow, currMaxRow, myOutputColumn) == 0) {
|
|
maxRow = BlueDataUtility.computeMaxRow(dp.newRows, myOutputColumn);
|
|
if (maxRow == null)
|
|
myOutputTable.removeRow(hashString);
|
|
else
|
|
myOutputTable.addRow(maxRow, hashString);
|
|
}
|
|
}
|
|
maxRow = BlueDataUtility.computeMaxRow(dp.addedRows, myOutputColumn);
|
|
// if the row was replaced in the above lines, then currMaxRow < maxRow, so the if below would never return a true,
|
|
// otherwise if maxRow > currMaxRow then its replaced
|
|
if (maxRow != null && (currMaxRow == null || BlueDataUtility.compare_rows(maxRow, currMaxRow, myOutputColumn) > 0))
|
|
myOutputTable.addRow(maxRow, hashString);
|
|
return myProject(myOutputTable.getRow(hashString));
|
|
}
|
|
}
|
|
}
|