80 lines
3.9 KiB
C#
80 lines
3.9 KiB
C#
// using System;
|
|
// using BCG.Utilities;
|
|
|
|
// namespace BCG
|
|
// {
|
|
// /// <summary>
|
|
// /// Abstracts the functionality used to GroupBy rows in an incremental fation,
|
|
// /// governed by the delegates passed in the argument
|
|
// /// </summary>
|
|
// public class IncrementalGroupByEvaluator : GroupByEvaluator
|
|
// {
|
|
// /// <summary>
|
|
// /// Delegate supposed to act incrementally and produce an output object given the last value
|
|
// /// of the data, new value and add/remove boolean. If its the first data, then null would be passed
|
|
// /// on as the last value. Also if the user wants the group to be removed than null should be returned
|
|
// /// </summary>
|
|
// public delegate object IncrementalComputeDelegate (object prevData, object newData, bool isAdd);
|
|
// private IncrementalGroupByEvaluator.IncrementalComputeDelegate myCompute;
|
|
// private int myOutputColIndex = -1, myIdColIndex = -1, myIdGenerator = 0;
|
|
|
|
// #region constructors
|
|
// public IncrementalGroupByEvaluator (IncrementalComputeDelegate compute, string outputCol, string[] groupByCols)
|
|
// : base (outputCol, groupByCols)
|
|
// {myCompute = compute;}
|
|
|
|
// public IncrementalGroupByEvaluator (IncrementalComputeDelegate compute, string colMapExpression,
|
|
// string outputCol, string[] groupByCols) : base (colMapExpression, outputCol, groupByCols)
|
|
// {myCompute = compute;}
|
|
// #endregion
|
|
|
|
// public override IBlueRow evaluate (DataPacket packet)
|
|
// {
|
|
// myCheckTableState (packet);//initialization, if required
|
|
// string hashString = GroupByStream.getRepString (packet, myGroupByCols);//hash of the group repsented by the packet
|
|
// foreach (IBlueRow delRow in packet.deletedRows)
|
|
// {
|
|
// IBlueRow existantRow = myOutputTable.getRow (hashString);
|
|
// BlueEventLog.logAssert (existantRow != null);//if rows are to be deleted, there ought to be a rep row for this group
|
|
// object newValue = myCompute (existantRow[myOutputColIndex], delRow[myOutputColIndex], false);
|
|
// myOutputTable.addRow (
|
|
// BlueDataUtility.getNewReplacedRow (
|
|
// existantRow,
|
|
// new object[]{myIdGenerator++, newValue}, new int[]{myIdColIndex, myOutputColIndex}),
|
|
// //BlueDataUtility.getNewReplacedRow (existantRow, newValue, myOutputColIndex),
|
|
// hashString);
|
|
// }
|
|
// foreach (IBlueRow addedRow in packet.addedRows)
|
|
// {
|
|
// IBlueRow existantRow = myOutputTable.getRow (hashString);
|
|
// object newValue = myCompute (existantRow == null ? null : existantRow[myOutputColIndex],
|
|
// addedRow[myOutputColIndex], true);
|
|
// myOutputTable.addRow (
|
|
// //BlueDataUtility.getNewReplacedRow (addedRow, newValue, myOutputColIndex), hashString);
|
|
// BlueDataUtility.getNewReplacedRow (
|
|
// addedRow,
|
|
// new object[]{myIdGenerator++, newValue}, new int[]{myIdColIndex, myOutputColIndex}),
|
|
// hashString);
|
|
// }
|
|
// IBlueRow res = myOutputTable.getRow (hashString);
|
|
// //ref to deleted group is kept in myOutputTable
|
|
// return res[myOutputColIndex] == null ? null : myProject(res);
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// Initalizes the state of the class, ie by evaluating the output Col Index and initialzing the table
|
|
// /// </summary>
|
|
// /// <param name="packet"></param>
|
|
// private void myCheckTableState (DataPacket packet)
|
|
// {
|
|
// if (myOutputTable == null)
|
|
// {
|
|
// myOutputTable = new GroupByOutputTable (packet.schema);
|
|
// myOutputColIndex = packet.schema [myOutputColumn].colNo;
|
|
// myIdColIndex = packet.schema["id"].colNo;
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// }
|