feat: Resurrect DataStream primitives

They were originally commented out because the expression parsing utils
weren't ready (now they are).
This commit is contained in:
John Colvin committed 2023-09-29 13:10:50 -04:00
1 parent 1dfc028554
commit 9311c27f47
29 files changed
+2737 -2647

No files matched your search

@@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ArithmeticExpressions\ArithmeticExpressions.csproj" />
<ProjectReference Include="..\BaseUtilities\BaseUtilities.csproj" />
<ProjectReference Include="..\BooleanExpressions\BooleanExpressions.csproj" />
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
@@ -1,100 +1,102 @@
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
using Bts.ArithmeticExpressions;
// namespace BCG
// {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// public class BooleanStringReplaceStream : ViewStream, IStreamMapper
// {
// private BooleanExpressionFilter _bool;
// private string _column, _value;
// private IBlueTableSchema _schema;
// public BooleanStringReplaceStream(ViewStream vs, string boolean_expression, string column, string value)
// {
// _column = column;
// _value = value;
// if(!string.IsNullOrEmpty(boolean_expression))
// _bool = new BooleanExpressionFilter(boolean_expression);
// mySetRealSource(new MapStream(vs, this));
// }
// public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema)
// {
// _schema = inputSchema;
// return inputSchema;
// }
// public IBlueRow map(IBlueRow row)
// {
// MutableBlueRow result = new MutableBlueRow(_schema, row);
// if(_bool == null || _bool.filter(row))
// result.setValue(_column, _value);
// return result;
// }
namespace BCG
{
// }
public class BooleanStringReplaceStream : ViewStream, IStreamMapper
{
private BooleanExpressionFilter _bool;
private string _column, _value;
private IBlueTableSchema _schema;
public BooleanStringReplaceStream(ViewStream vs, string boolean_expression, string column, string value)
{
_column = column;
_value = value;
if(!string.IsNullOrEmpty(boolean_expression))
_bool = new BooleanExpressionFilter(boolean_expression);
mySetRealSource(new MapStream(vs, this));
}
public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema)
{
_schema = inputSchema;
return inputSchema;
}
public IBlueRow map(IBlueRow row)
{
MutableBlueRow result = new MutableBlueRow(_schema, row);
if(_bool == null || _bool.filter(row))
result.setValue(_column, _value);
return result;
}
// public class MathStream : ViewStream, IStreamMapper
// {
// private ArithmeticExpressionEvaluator.ArithmeticExpression myExp;
// private BooleanExpressionFilter _bool;
// List<string> myExtraColumns = new List<string>();
// BlueTableSchema mySchema;
}
public class MathStream : ViewStream, IStreamMapper
{
private IArithmeticProgram myExp;
private BooleanExpressionFilter _bool;
List<string> myExtraColumns = new List<string>();
BlueTableSchema mySchema;
// public MathStream(ViewStream vs, string mathExpression)
// : this(vs, mathExpression, string.Empty)
// {
// }
public MathStream(ViewStream vs, string mathExpression)
: this(vs, mathExpression, string.Empty)
{
}
// public MathStream(ViewStream vs, string mathExpression, string boolean_expression)
// {
// myExp = ArithmeticExpressionEvaluator.compile(mathExpression);
// myExtraColumns = ArithmeticExpressionEvaluator.getOutputIdentifiers(myExp);
// if(!string.IsNullOrEmpty(boolean_expression))
// _bool = new BooleanExpressionFilter(boolean_expression);
// mySetRealSource(new MapStream(vs, this));
// }
public MathStream(ViewStream vs, string mathExpression, string boolean_expression)
{
myExp = ArithmeticProgramParser.Parse(mathExpression) ??
throw new Exception($"Failed to parse ArithmeticExpression '{mathExpression}'");
myExtraColumns = myExp.OutputIdentifiers.ToList();
if(!string.IsNullOrEmpty(boolean_expression))
_bool = new BooleanExpressionFilter(boolean_expression);
mySetRealSource(new MapStream(vs, this));
}
// #region IStreamMapper Members
#region IStreamMapper Members
// public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema)
// {
// if (mySchema == null)
// {
// Dictionary<string, ColumnInfo> colIdx = new Dictionary<string, ColumnInfo>();
// foreach (ColumnInfo ci in inputSchema.columnInfo)
// colIdx[ci.colName] = ci;
public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema)
{
if (mySchema == null)
{
Dictionary<string, ColumnInfo> colIdx = new Dictionary<string, ColumnInfo>();
foreach (ColumnInfo ci in inputSchema.columnInfo)
colIdx[ci.colName] = ci;
// foreach (string ncn in myExtraColumns)
// {
// ColumnInfo newC;
// if (colIdx.ContainsKey(ncn))
// newC = new ColumnInfo(colIdx[ncn].colName, colIdx[ncn].colNo, typeof(double));
// else
// newC = new ColumnInfo(ncn, colIdx.Count, typeof(double));
// colIdx[ncn] = newC;
// }
// mySchema = new BlueTableSchema(colIdx.Values.ToArray(), "math(" + inputSchema.tableName + ")");
// }
// return mySchema;
// }
foreach (string ncn in myExtraColumns)
{
ColumnInfo newC;
if (colIdx.ContainsKey(ncn))
newC = new ColumnInfo(colIdx[ncn].colName, colIdx[ncn].colNo, typeof(double));
else
newC = new ColumnInfo(ncn, colIdx.Count, typeof(double));
colIdx[ncn] = newC;
}
mySchema = new BlueTableSchema(colIdx.Values.ToArray(), "math(" + inputSchema.tableName + ")");
}
return mySchema;
}
// #endregion
#endregion
// #region IDynamicStreamMapper Members
#region IDynamicStreamMapper Members
// public IBlueRow map(IBlueRow row)
// {
// MutableBlueRow result = new MutableBlueRow(mySchema, row);
// if(_bool == null || _bool.filter(row))
// {
// foreach(var kvp in ArithmeticExpressionEvaluator.eval(myExp, (System.Collections.IDictionary)result))
// result.setValue(kvp.Key, kvp.Value);
// }
// return result;
// }
public IBlueRow map(IBlueRow row)
{
MutableBlueRow result = new MutableBlueRow(mySchema, row);
if(_bool == null || _bool.filter(row))
{
myExp.Evaluate(result.AsDictionary());
}
return result;
}
// #endregion
// }
// }
#endregion
}
}
@@ -1,36 +1,36 @@
// using System;
// using System.Collections;
using System;
using System.Collections;
// using BCG.Utilities;
using BCG.Utilities;
// namespace BCG
// {
// public class DistinctRowEvaluator : GroupByEvaluator
// {
namespace BCG
{
public class DistinctRowEvaluator : GroupByEvaluator
{
// private int myIdGenerator = 0;
// public DistinctRowEvaluator (string[] columnNames) : base (null, columnNames) {}
private int myIdGenerator = 0;
public DistinctRowEvaluator (string[] columnNames) : base (null, columnNames) {}
// public DistinctRowEvaluator(string colMapExpression, string[] columnNames)
// : base (colMapExpression, null, columnNames) {}
public DistinctRowEvaluator(string colMapExpression, string[] columnNames)
: base (colMapExpression, null, columnNames) {}
// public override IBlueRow evaluate (DataPacket packet)
// {
// myOutputTable = myOutputTable == null ? new GroupByOutputTable (packet.schema) : myOutputTable;
// string hashString = GroupByStream.getRepString (packet, myGroupByCols);
// if (packet.newRows.Count == 0)
// //if there are no rows for this group we remove the group from the output table
// myOutputTable.removeRow (hashString);
// else if (myOutputTable.getRow (hashString) == null)
// //a row is added for the first time (or first time after the removal of the group)
// myOutputTable.addRow (
// BlueDataUtility.getNewReplacedRow (
// BlueDataUtility.extractRow (packet.newRows, 0),
// myIdGenerator++, "id"),
// hashString);
public override IBlueRow evaluate (DataPacket packet)
{
myOutputTable = myOutputTable == null ? new GroupByOutputTable (packet.schema) : myOutputTable;
string hashString = GroupByStream.getRepString (packet, myGroupByCols);
if (packet.newRows.Count == 0)
//if there are no rows for this group we remove the group from the output table
myOutputTable.removeRow (hashString);
else if (myOutputTable.getRow (hashString) == null)
//a row is added for the first time (or first time after the removal of the group)
myOutputTable.addRow (
BlueDataUtility.getNewReplacedRow (
BlueDataUtility.extractRow (packet.newRows, 0),
myIdGenerator++, "id"),
hashString);
// return myProject (myOutputTable.getRow (hashString));
// }
// }
// }
return myProject (myOutputTable.getRow (hashString));
}
}
}
@@ -1,23 +1,23 @@
// using System;
// using System.Collections;
using System;
using System.Collections;
// namespace BCG
// {
// /// <summary>
// /// Provides a stream that with distinct rows with respect to the columns
// /// the user specifies in the argument
// /// </summary>
// [DataStreamUserRespresentation ("distinct")]
// public class DistinctRowStream : ViewStream
// {
// public DistinctRowStream (ViewStream stream, params string[] cols)
// {
// ArrayList groupByCols = new ArrayList ();
// foreach (string col in cols)
// foreach (string c in col.Split (' '))
// groupByCols.Add (c);
// mySetRealSource (new GroupByStream (stream,
// new DistinctRowEvaluator (groupByCols.ToArray (typeof(string)) as string[]), false));
// }
// }
// }
namespace BCG
{
/// <summary>
/// Provides a stream that with distinct rows with respect to the columns
/// the user specifies in the argument
/// </summary>
[DataStreamUserRespresentation ("distinct")]
public class DistinctRowStream : ViewStream
{
public DistinctRowStream (ViewStream stream, params string[] cols)
{
ArrayList groupByCols = new ArrayList ();
foreach (string col in cols)
foreach (string c in col.Split (' '))
groupByCols.Add (c);
mySetRealSource (new GroupByStream (stream,
new DistinctRowEvaluator (groupByCols.ToArray (typeof(string)) as string[]), false));
}
}
}
@@ -1,82 +1,82 @@
// using System;
using System;
// namespace BCG
// {
// /// <summary>
// /// Serves as an abtraction for some of the functionalities needed in implementations
// /// of IGroupByEvaluator
// /// </summary>
// public abstract class GroupByEvaluator : IGroupByEvaluator
// {
// protected string[] myGroupByCols;
// protected string myOutputColumn;
// protected GroupByOutputTable myOutputTable;
// protected string myColMapExpression;
namespace BCG
{
/// <summary>
/// Serves as an abtraction for some of the functionalities needed in implementations
/// of IGroupByEvaluator
/// </summary>
public abstract class GroupByEvaluator : IGroupByEvaluator
{
protected string[] myGroupByCols;
protected string myOutputColumn;
protected GroupByOutputTable myOutputTable;
protected string myColMapExpression;
// #region constructors
// public GroupByEvaluator (string outputCol, string[] groupByCols)
// {
// myOutputColumn = outputCol;
// myGroupByCols = groupByCols;
// }
#region constructors
public GroupByEvaluator (string outputCol, string[] groupByCols)
{
myOutputColumn = outputCol;
myGroupByCols = groupByCols;
}
// public GroupByEvaluator (string colMapExpression, string outputCol, string[] groupByCols)
// : this (outputCol, groupByCols) {myColMapExpression = colMapExpression;}
// #endregion
public GroupByEvaluator (string colMapExpression, string outputCol, string[] groupByCols)
: this (outputCol, groupByCols) {myColMapExpression = colMapExpression;}
#endregion
// #region IGroupByEvaluator methods
// public virtual string[] groupByColumns {get{return myGroupByCols;}}
#region IGroupByEvaluator methods
public virtual string[] groupByColumns {get{return myGroupByCols;}}
// public virtual void clear ()
// {
// if ( myOutputTable != null )
// myOutputTable.clear ();
// }
public virtual void clear ()
{
if ( myOutputTable != null )
myOutputTable.clear ();
}
// public virtual IBlueTableSchema getOutputSchema (IBlueTableSchema schema)
// {
// IBlueTableSchema retVal =
// myColMapExpression == null || myColMapExpression.Length < 1 ?
// schema :
// new ProjectHelper (schema, myColMapExpression, schema.tableName).schema;
// return retVal;
// }
public virtual IBlueTableSchema getOutputSchema (IBlueTableSchema schema)
{
IBlueTableSchema retVal =
myColMapExpression == null || myColMapExpression.Length < 1 ?
schema :
new ProjectHelper (schema, myColMapExpression, schema.tableName).schema;
return retVal;
}
// public abstract IBlueRow evaluate (DataPacket dp) ;
// #endregion
public abstract IBlueRow evaluate (DataPacket dp) ;
#endregion
// #region Helper methods
// /// <summary>
// /// Projects the r, replacing the id of the returned rows with the id provided in the arg
// /// </summary>
// /// <param name="r"></param>
// /// <param name="id"></param>
// /// <returns></returns>
// protected IBlueRow myProject (IBlueRow r, int id)
// {
// return r == null ? null :
// myColMapExpression == null || myColMapExpression.Length < 1 ?
// BlueDataUtility.getNewReplacedRow (r, id, "id") :
// BlueDataUtility.getNewReplacedRow(myProjectRow (r, myColMapExpression),
// id, "id");
// }
#region Helper methods
/// <summary>
/// Projects the r, replacing the id of the returned rows with the id provided in the arg
/// </summary>
/// <param name="r"></param>
/// <param name="id"></param>
/// <returns></returns>
protected IBlueRow myProject (IBlueRow r, int id)
{
return r == null ? null :
myColMapExpression == null || myColMapExpression.Length < 1 ?
BlueDataUtility.getNewReplacedRow (r, id, "id") :
BlueDataUtility.getNewReplacedRow(myProjectRow (r, myColMapExpression),
id, "id");
}
// /// <summary>
// /// Projects the id, conserving the id
// /// </summary>
// /// <param name="r"></param>
// /// <returns></returns>
// protected IBlueRow myProject (IBlueRow r) {return myProject (r, r == null ? Int32.MinValue : (int)r["id"]);}
// #endregion
/// <summary>
/// Projects the id, conserving the id
/// </summary>
/// <param name="r"></param>
/// <returns></returns>
protected IBlueRow myProject (IBlueRow r) {return myProject (r, r == null ? Int32.MinValue : (int)r["id"]);}
#endregion
// private IBlueRow myProjectRow (IBlueRow r, string colMapExpression)
// {
// BlueTable auxTable = new BlueTable (r.schema);
// auxTable.addRow (r);
// BlueRowCollectionStaticStream staticStream = new BlueRowCollectionStaticStream (auxTable);
// ProjectStream projStream = new ProjectStream (staticStream, colMapExpression);
// return BlueDataUtility.extractRow (projStream.rows, 0);
// }
private IBlueRow myProjectRow (IBlueRow r, string colMapExpression)
{
BlueTable auxTable = new BlueTable (r.schema);
auxTable.addRow (r);
BlueRowCollectionStaticStream staticStream = new BlueRowCollectionStaticStream (auxTable);
ProjectStream projStream = new ProjectStream (staticStream, colMapExpression);
return BlueDataUtility.extractRow (projStream.rows, 0);
}
// }
// }
}
}
@@ -1,31 +1,31 @@
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// namespace BCG
// {
// public class FullJoinStream : ViewStream
// {
// private ViewStream myMainStream;
// public FullJoinStream(ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2, string cmExp2, string empty_col)
// {
// myMainStream = new LeftJoinStream(v1, joinCol1, cmExp1, v2, joinCol2, cmExp2);
// ViewStream filtered = new LeftJoinStream(v2, joinCol2, cmExp2, v1, joinCol1, cmExp1);
// filtered = new FilterStream(filtered, String.Format("{0}=null", empty_col));
// myMainStream = new AppendStream(myMainStream, filtered);
// }
namespace BCG
{
public class FullJoinStream : ViewStream
{
private ViewStream myMainStream;
public FullJoinStream(ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2, string cmExp2, string empty_col)
{
myMainStream = new LeftJoinStream(v1, joinCol1, cmExp1, v2, joinCol2, cmExp2);
ViewStream filtered = new LeftJoinStream(v2, joinCol2, cmExp2, v1, joinCol1, cmExp1);
filtered = new FilterStream(filtered, String.Format("{0}=null", empty_col));
myMainStream = new AppendStream(myMainStream, filtered);
}
// protected override void myOnFirstSubscriber()
// {
// myMainStream.onChange += myHandleMainStreamChange;
// }
protected override void myOnFirstSubscriber()
{
myMainStream.onChange += myHandleMainStreamChange;
}
// private void myHandleMainStreamChange(object newData)
// {
// IBlueRowCollection result = (newData as DataPacket).newRows;
// myFireEvent(new DataPacket(result, result, myLastValue == null ? new BlueTable(result.schema) : (myLastValue as DataPacket).newRows));
// }
// }
// }
private void myHandleMainStreamChange(object newData)
{
IBlueRowCollection result = (newData as DataPacket).newRows;
myFireEvent(new DataPacket(result, result, myLastValue == null ? new BlueTable(result.schema) : (myLastValue as DataPacket).newRows));
}
}
}
@@ -1,35 +1,35 @@
// using System;
using System;
// namespace BCG
// {
// [DataStreamUserRespresentation (false)]
// public class InternalJoinForeignStream : InternalJoinStream
// {
// public InternalJoinForeignStream (ViewStream vsLeft,
// string jcLeft,
// ViewStream vsRight,
// string jcRight)
// : base (vsLeft, jcLeft, vsRight, jcRight) {}
namespace BCG
{
[DataStreamUserRespresentation (false)]
public class InternalJoinForeignStream : InternalJoinStream
{
public InternalJoinForeignStream (ViewStream vsLeft,
string jcLeft,
ViewStream vsRight,
string jcRight)
: base (vsLeft, jcLeft, vsRight, jcRight) {}
// public InternalJoinForeignStream (ViewStream vsLeft,
// string jcLeft,
// ViewStream vsRight) : this (vsLeft, jcLeft, vsRight, "id") {}
public InternalJoinForeignStream (ViewStream vsLeft,
string jcLeft,
ViewStream vsRight) : this (vsLeft, jcLeft, vsRight, "id") {}
// protected override void myInitFiredPacket ()
// {
// myLastFiredPacket = new DataPacket ();
// myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// myLastFiredPacket.deletedRows = new BlueTable (mySchema);
// }
protected override void myInitFiredPacket ()
{
myLastFiredPacket = new DataPacket ();
myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
myLastFiredPacket.deletedRows = new BlueTable (mySchema);
}
// public override void onTableClear (bool isLeft)
// {
// //incase of natural join, left or right wont matter, the end result zeroes out
// myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
// myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// }
public override void onTableClear (bool isLeft)
{
//incase of natural join, left or right wont matter, the end result zeroes out
myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
}
// }
// }
}
}
@@ -1,183 +1,183 @@
// using System;
// using System.Collections;
using System;
using System.Collections;
// namespace BCG
// {
// /// <summary>
// /// Does all the computations required for performing the Joins. The JoinStream is a wrapper around
// /// InternalJoinStreaming taking caring of the column namings etc
// /// </summary>
// [DataStreamUserRespresentation (false)]
// public class InternalJoinStream : ViewStream
// {
// protected JoinOperand myLeftOperand, myRightOperand;
// protected int myLeftJoinColOrdinal, myRightJoinColOrdinal;
// protected ViewStream myLeftStream, myRightStream;
// protected JoinTableSchema mySchema;
// protected DataPacket myLastFiredPacket;
// protected bool myOnceFired = false;
namespace BCG
{
/// <summary>
/// Does all the computations required for performing the Joins. The JoinStream is a wrapper around
/// InternalJoinStreaming taking caring of the column namings etc
/// </summary>
[DataStreamUserRespresentation (false)]
public class InternalJoinStream : ViewStream
{
protected JoinOperand myLeftOperand, myRightOperand;
protected int myLeftJoinColOrdinal, myRightJoinColOrdinal;
protected ViewStream myLeftStream, myRightStream;
protected JoinTableSchema mySchema;
protected DataPacket myLastFiredPacket;
protected bool myOnceFired = false;
// public IBlueTableSchema schema {get{return mySchema;}}
public IBlueTableSchema schema {get{return mySchema;}}
// public InternalJoinStream (ViewStream vsLeft, string jcLeft, ViewStream vsRight, string jcRight)
// {
// myLeftStream = vsLeft;
// myRightStream = vsRight;
// myLeftOperand = new JoinOperand (jcLeft, true);
// myRightOperand = new JoinOperand (jcRight, false);
// }
public InternalJoinStream (ViewStream vsLeft, string jcLeft, ViewStream vsRight, string jcRight)
{
myLeftStream = vsLeft;
myRightStream = vsRight;
myLeftOperand = new JoinOperand (jcLeft, true);
myRightOperand = new JoinOperand (jcRight, false);
}
// protected override void myOnFirstSubscriber()
// {
// myLeftOperand.master = this;
// myRightOperand.master = this;
// myLeftStream.onChange += new DataStream.ChangeDelegate (myLeftOperand.changeHandler);
// myRightStream.onChange += new DataStream.ChangeDelegate (myRightOperand.changeHandler);
// }
protected override void myOnFirstSubscriber()
{
myLeftOperand.master = this;
myRightOperand.master = this;
myLeftStream.onChange += new DataStream.ChangeDelegate (myLeftOperand.changeHandler);
myRightStream.onChange += new DataStream.ChangeDelegate (myRightOperand.changeHandler);
}
// protected override void myOnLastSubscriber ()
// {
// myInit ();
// myLeftStream.onChange -= new DataStream.ChangeDelegate (myLeftOperand.changeHandler);
// myRightStream.onChange -= new DataStream.ChangeDelegate (myRightOperand.changeHandler);
// }
protected override void myOnLastSubscriber ()
{
myInit ();
myLeftStream.onChange -= new DataStream.ChangeDelegate (myLeftOperand.changeHandler);
myRightStream.onChange -= new DataStream.ChangeDelegate (myRightOperand.changeHandler);
}
// public JoinOperand getOtherOperand (JoinOperand jo)
// {
// JoinOperand retVal = jo == myLeftOperand ? myRightOperand : myLeftOperand;
// return retVal;
// }
public JoinOperand getOtherOperand (JoinOperand jo)
{
JoinOperand retVal = jo == myLeftOperand ? myRightOperand : myLeftOperand;
return retVal;
}
// public void startSession ()
// {
// if (myLastFiredPacket != null)
// {
// //reset add and deletes
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// myLastFiredPacket.deletedRows = new BlueTable (mySchema);
// return;
// }
// //first time case, need to initialize everything
// else if (myLeftOperand.hasReceivedData && myRightOperand.hasReceivedData)
// {
// myLeftJoinColOrdinal = myLeftOperand.joinColOridinal;
// myRightJoinColOrdinal = myRightOperand.joinColOridinal;
// mySchema = new JoinTableSchema (myLeftOperand.operandSchema, myLeftOperand.joinCol,
// myRightOperand.operandSchema, myRightOperand.joinCol);
// myInitFiredPacket ();
// }
// }
public void startSession ()
{
if (myLastFiredPacket != null)
{
//reset add and deletes
myLastFiredPacket.addedRows = new BlueTable (mySchema);
myLastFiredPacket.deletedRows = new BlueTable (mySchema);
return;
}
//first time case, need to initialize everything
else if (myLeftOperand.hasReceivedData && myRightOperand.hasReceivedData)
{
myLeftJoinColOrdinal = myLeftOperand.joinColOridinal;
myRightJoinColOrdinal = myRightOperand.joinColOridinal;
mySchema = new JoinTableSchema (myLeftOperand.operandSchema, myLeftOperand.joinCol,
myRightOperand.operandSchema, myRightOperand.joinCol);
myInitFiredPacket ();
}
}
// protected virtual void myInitFiredPacket ()
// {
// myLastFiredPacket = new DataPacket ();
// myLastFiredPacket.newRows = new JoinTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// myLastFiredPacket.deletedRows = new BlueTable (mySchema);
// }
protected virtual void myInitFiredPacket ()
{
myLastFiredPacket = new DataPacket ();
myLastFiredPacket.newRows = new JoinTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
myLastFiredPacket.deletedRows = new BlueTable (mySchema);
}
// public IBlueTableSchema getSchema (bool isLeft)
// {
// IBlueTableSchema retVal;
// retVal = isLeft ? myLeftOperand.operandSchema : myRightOperand.operandSchema;
// return retVal;
// }
public IBlueTableSchema getSchema (bool isLeft)
{
IBlueTableSchema retVal;
retVal = isLeft ? myLeftOperand.operandSchema : myRightOperand.operandSchema;
return retVal;
}
// public void endSession ()
// {
// if (!myOnceFired)
// {
// myOnceFired = true;
// myFireEvent (myLastFiredPacket.Clone());
// }
// else if (myLastFiredPacket.addedRows.Count + myLastFiredPacket.deletedRows.Count != 0)
// myFireEvent (myLastFiredPacket.Clone());
// }
public void endSession ()
{
if (!myOnceFired)
{
myOnceFired = true;
myFireEvent (myLastFiredPacket.Clone());
}
else if (myLastFiredPacket.addedRows.Count + myLastFiredPacket.deletedRows.Count != 0)
myFireEvent (myLastFiredPacket.Clone());
}
// protected virtual void myInit ()
// {
// myLeftOperand.init ();
// myRightOperand.init ();
// myLastFiredPacket = null;
// }
protected virtual void myInit ()
{
myLeftOperand.init ();
myRightOperand.init ();
myLastFiredPacket = null;
}
// public virtual void onTableClear (bool isLeft)
// {
// //incase of natural join, left or right wont matter, the end result zeroes out
// myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
// myLastFiredPacket.newRows = new JoinTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// }
public virtual void onTableClear (bool isLeft)
{
//incase of natural join, left or right wont matter, the end result zeroes out
myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
myLastFiredPacket.newRows = new JoinTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
}
// public virtual void deleteRows (IBlueRowCollection rows, bool isLeft)
// {
// JoinOperand thisOp, otherOp;
// int joinColOrdinal;
// myAssignAccordingly (out thisOp, out otherOp, out joinColOrdinal, isLeft);
// foreach (IBlueRow row in rows)
// {
// thisOp.deleteRow (row);
// if (otherOp.getMatchingRows (row[joinColOrdinal]).Count == 0)
// continue; //row does not participate in join
// ((JoinTable)(myLastFiredPacket.newRows)).deleteRow (isLeft, row, myLastFiredPacket);
// }
// }
public virtual void deleteRows (IBlueRowCollection rows, bool isLeft)
{
JoinOperand thisOp, otherOp;
int joinColOrdinal;
myAssignAccordingly (out thisOp, out otherOp, out joinColOrdinal, isLeft);
foreach (IBlueRow row in rows)
{
thisOp.deleteRow (row);
if (otherOp.getMatchingRows (row[joinColOrdinal]).Count == 0)
continue; //row does not participate in join
((JoinTable)(myLastFiredPacket.newRows)).deleteRow (isLeft, row, myLastFiredPacket);
}
}
// public virtual void addRows (IBlueRowCollection rows, bool isLeft)
// {
// JoinOperand thisOp, otherOp;
// int joinColOrdinal;
// myAssignAccordingly (out thisOp, out otherOp, out joinColOrdinal, isLeft);
// if (!isLeft)
// {
// thisOp = myRightOperand;
// otherOp = myLeftOperand;
// joinColOrdinal = myRightJoinColOrdinal;
// }
// foreach (IBlueRow row in rows)
// {
// thisOp.addRow (row);
// RowList matchedNodes = otherOp.getMatchingRows (row[joinColOrdinal]);
// if (matchedNodes.Count == 0)
// continue; //this row did not participate in the join
// if (isLeft)
// foreach (RowNode matchedNode in matchedNodes)
// ((JoinTable)myLastFiredPacket.newRows).addRow (row, matchedNode.row, myLastFiredPacket);
// else
// foreach (RowNode matchedNode in matchedNodes)
// ((JoinTable)myLastFiredPacket.newRows).addRow (matchedNode.row, row, myLastFiredPacket);
// }
// }
public virtual void addRows (IBlueRowCollection rows, bool isLeft)
{
JoinOperand thisOp, otherOp;
int joinColOrdinal;
myAssignAccordingly (out thisOp, out otherOp, out joinColOrdinal, isLeft);
if (!isLeft)
{
thisOp = myRightOperand;
otherOp = myLeftOperand;
joinColOrdinal = myRightJoinColOrdinal;
}
foreach (IBlueRow row in rows)
{
thisOp.addRow (row);
RowList matchedNodes = otherOp.getMatchingRows (row[joinColOrdinal]);
if (matchedNodes.Count == 0)
continue; //this row did not participate in the join
if (isLeft)
foreach (RowNode matchedNode in matchedNodes)
((JoinTable)myLastFiredPacket.newRows).addRow (row, matchedNode.row, myLastFiredPacket);
else
foreach (RowNode matchedNode in matchedNodes)
((JoinTable)myLastFiredPacket.newRows).addRow (matchedNode.row, row, myLastFiredPacket);
}
}
// private void myAssignAccordingly (out JoinOperand thisOp, out JoinOperand otherOp, out int joinColOrdinal, bool isLeft)
// {
// if (isLeft)
// {
// thisOp = myLeftOperand;
// otherOp = myRightOperand;
// joinColOrdinal = myLeftJoinColOrdinal;
// }
// else
// {
// thisOp = myRightOperand;
// otherOp = myLeftOperand;
// joinColOrdinal = myRightJoinColOrdinal;
// }
// }
private void myAssignAccordingly (out JoinOperand thisOp, out JoinOperand otherOp, out int joinColOrdinal, bool isLeft)
{
if (isLeft)
{
thisOp = myLeftOperand;
otherOp = myRightOperand;
joinColOrdinal = myLeftJoinColOrdinal;
}
else
{
thisOp = myRightOperand;
otherOp = myLeftOperand;
joinColOrdinal = myRightJoinColOrdinal;
}
}
// /**************************************TEST METHOD(S)*********************************************/
// /// <summary>
// /// Used for testing purposes only. This enables the test to work without a DataSource (PubServer,
// /// BaseServer etc), by directly calling the test method and passing data
// /// </summary>
// /// <param name="leftPacket"></param>
// /// <param name="rightPacket"></param>
// public void test (DataPacket dp, bool isLeft)
// {
// JoinOperand jo = isLeft ? myLeftOperand : myRightOperand;
// jo.changeHandler (dp);
// }
// /***********************************************************************************************/
// }
// }
/**************************************TEST METHOD(S)*********************************************/
/// <summary>
/// Used for testing purposes only. This enables the test to work without a DataSource (PubServer,
/// BaseServer etc), by directly calling the test method and passing data
/// </summary>
/// <param name="leftPacket"></param>
/// <param name="rightPacket"></param>
public void test (DataPacket dp, bool isLeft)
{
JoinOperand jo = isLeft ? myLeftOperand : myRightOperand;
jo.changeHandler (dp);
}
/***********************************************************************************************/
}
}
@@ -1,64 +1,64 @@
// using System;
// using System.Collections;
using System;
using System.Collections;
// namespace BCG
// {
// /// <summary>
// /// Hashtable of DoubleyLinkedList tailored for the Join deletions
// /// </summary>
// internal class JoinDeletionIndex
// {
// IDictionary myIndex = new Hashtable ();
// private string myOpIdName ;
// private bool myIsLeft;
namespace BCG
{
/// <summary>
/// Hashtable of DoubleyLinkedList tailored for the Join deletions
/// </summary>
internal class JoinDeletionIndex
{
IDictionary myIndex = new Hashtable ();
private string myOpIdName ;
private bool myIsLeft;
// /// <summary>
// /// </summary>
// /// <param name="opIdName">opIdName represents the name of the column corresponding to id of the operand table</param>
// /// <param name="isLeft">Indicator for left or right operand table</param>
// public JoinDeletionIndex(string opIdName, bool isLeft)
// {
// myOpIdName = opIdName;
// myIsLeft = isLeft;
// }
/// <summary>
/// </summary>
/// <param name="opIdName">opIdName represents the name of the column corresponding to id of the operand table</param>
/// <param name="isLeft">Indicator for left or right operand table</param>
public JoinDeletionIndex(string opIdName, bool isLeft)
{
myOpIdName = opIdName;
myIsLeft = isLeft;
}
// /// <summary>
// /// Adds a joinRow to the hashtable; in addition the joinRow is made to point to the node added
// /// </summary>
// /// <param name="row">JoinRow to add</param>
// public void add (JoinRow row)
// {
// object o = row[myOpIdName];
// if (myIndex[o] == null)
// myIndex[o] = new RowList ();
// RowNode nodeAdded = ((RowList)myIndex[o]).add (row);
// if (myIsLeft)
// row.leftNode = nodeAdded;
// else
// row.rightNode = nodeAdded;
/// <summary>
/// Adds a joinRow to the hashtable; in addition the joinRow is made to point to the node added
/// </summary>
/// <param name="row">JoinRow to add</param>
public void add (JoinRow row)
{
object o = row[myOpIdName];
if (myIndex[o] == null)
myIndex[o] = new RowList ();
RowNode nodeAdded = ((RowList)myIndex[o]).add (row);
if (myIsLeft)
row.leftNode = nodeAdded;
else
row.rightNode = nodeAdded;
// }
}
// /// <summary>
// /// To remove a node, if node does not exist exception is thrown
// /// </summary>
// /// <param name="node"></param>
// public void remove (RowNode node) {((RowList)myIndex[node.row[myOpIdName]]).remove (node);}
/// <summary>
/// To remove a node, if node does not exist exception is thrown
/// </summary>
/// <param name="node"></param>
public void remove (RowNode node) {((RowList)myIndex[node.row[myOpIdName]]).remove (node);}
// public RowList getMatchingRows (object key) {
// RowList retVal = (RowList)myIndex[key];
// if (retVal == null)
// return new RowList ();
// return retVal;
// }
public RowList getMatchingRows (object key) {
RowList retVal = (RowList)myIndex[key];
if (retVal == null)
return new RowList ();
return retVal;
}
// /// <summary>
// /// Empties the entry for the key provided
// /// </summary>
// /// <param name="obj"></param>
// public void removeAll (object obj) {myIndex.Remove(obj);}
/// <summary>
/// Empties the entry for the key provided
/// </summary>
/// <param name="obj"></param>
public void removeAll (object obj) {myIndex.Remove(obj);}
// public void clear () {myIndex.Clear ();}
public void clear () {myIndex.Clear ();}
// }
// }
}
}
@@ -1,59 +1,59 @@
// using System;
// using System.Data;
// using System.Collections;
// using System.Text.RegularExpressions;
// using BCG.Utilities;
// using BCG.Utilities.General;
using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using BCG.Utilities;
using BCG.Utilities.General;
// namespace BCG
// {
// public class ForeignJoinStream : JoinStream
// {
namespace BCG
{
public class ForeignJoinStream : JoinStream
{
// public ForeignJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
// ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, cm1, v2, joinCol2, cm2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, cm1, v2, joinCol2, cm2)
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2, string cmExp2)
// : base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2, string cmExp2)
: base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2)
// :
// this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2)
:
this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1,
// ViewStream v2, string joinCol2, string cmExp2)
// :
// this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1,
ViewStream v2, string joinCol2, string cmExp2)
:
this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, v2, joinCol2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, v2, joinCol2)
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, cm1, v2, joinCol2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, cm1, v2, joinCol2)
{}
// public ForeignJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, v2, joinCol2, cm2)
// {}
public ForeignJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, v2, joinCol2, cm2)
{}
// protected override InternalJoinStream myConstructInternalJoinStream (
// ViewStream vs1,
// string jc1,
// ViewStream vs2,
// string jc2)
// {
// return new InternalJoinForeignStream (vs1, jc1, vs2, jc2);
// }
// }
// }
protected override InternalJoinStream myConstructInternalJoinStream (
ViewStream vs1,
string jc1,
ViewStream vs2,
string jc2)
{
return new InternalJoinForeignStream (vs1, jc1, vs2, jc2);
}
}
}
@@ -1,20 +1,22 @@
// using System;
// using BCG.Utilities;
using System;
using BCG.Utilities;
// namespace BCG
// {
// internal class JoinForeignTable : JoinTable
// {
// public JoinForeignTable (JoinTableSchema schema) : base (schema) {}
using bts;
// public override void addRow (IBlueRow leftRow, IBlueRow rightRow, DataPacket dp)
// {
// JoinRow newRow = new JoinRow (leftRow, rightRow, mySchema);
// BlueEventLog.logAssert (myIdIndex[leftRow["id"]] == null);
// myIdIndex[leftRow["id"]] = newRow;
// ((BlueTable)(dp.addedRows)).addRow (newRow);
// myLeftIndex.add (newRow);
// myRightIndex.add (newRow);
// }
// }
// }
namespace BCG
{
internal class JoinForeignTable : JoinTable
{
public JoinForeignTable (JoinTableSchema schema) : base (schema) {}
public override void addRow (IBlueRow leftRow, IBlueRow rightRow, DataPacket dp)
{
JoinRow newRow = new JoinRow (leftRow, rightRow, mySchema);
Log.assert(myIdIndex[leftRow["id"]] == null);
myIdIndex[leftRow["id"]] = newRow;
((BlueTable)(dp.addedRows)).addRow (newRow);
myLeftIndex.add (newRow);
myRightIndex.add (newRow);
}
}
}
@@ -1,211 +1,205 @@
// using System;
// using System.Collections;
// using BCG.Utilities;
// using BCG.Evaluator.ColumnMapExpression;
using System;
using System.Collections;
using BCG.Utilities;
// namespace BCG
// {
// /// <summary>
// /// JoinNameResolver is used to bring together the 2 naming processes, ie the one done ny Join to resolve
// /// clashes and the second, that the user does to rename columns
// /// </summary>
// public class JoinNameResolver
// {
// /// <summary>
// /// Internal class to represent a column (ie name) and its association, left or right
// /// </summary>
// internal class OriginalNameInfo
// {
// public bool isLeft;
// public string colName;
// public OriginalNameInfo (string colName, bool isLeft) {this.colName = colName; this.isLeft = isLeft;}
// public override int GetHashCode ()
// {
// string prependString = isLeft ? "left" : "right";
// return String.Concat (prependString, colName).GetHashCode ();
// }
// public override bool Equals (object obj) {return GetHashCode () == obj.GetHashCode ();}
// }
using bts;
using Bts.ColumnMapExpressions;
namespace BCG
{
/// <summary>
/// JoinNameResolver is used to bring together the 2 naming processes, ie the one done ny Join to resolve
/// clashes and the second, that the user does to rename columns
/// </summary>
public class JoinNameResolver
{
/// <summary>
/// Internal class to represent a column (ie name) and its association, left or right
/// </summary>
internal class OriginalNameInfo
{
public bool isLeft;
public string colName;
public OriginalNameInfo (string colName, bool isLeft) {this.colName = colName; this.isLeft = isLeft;}
public override int GetHashCode ()
{
string prependString = isLeft ? "left" : "right";
return String.Concat (prependString, colName).GetHashCode ();
}
public override bool Equals (object obj) {return GetHashCode () == obj.GetHashCode ();}
}
// private ArrayList myJoinNames;
// private JoinNameResolver.OriginalNameInfo[] myOriginalColInfo;
// private JoinTableSchema myJoinSchema;
// private IBlueTableSchema myLeftSchema, myRightSchema;
// private string myLeftColExpression, myRightColExpression;
// private string[] myUserRules, myResolvedNames;
// private IDictionary myFinalMap = new Hashtable ();
private ArrayList myJoinNames;
private JoinNameResolver.OriginalNameInfo[] myOriginalColInfo;
private JoinTableSchema myJoinSchema;
private IBlueTableSchema myLeftSchema, myRightSchema;
private string myLeftColExpression, myRightColExpression;
private string[] myUserRules, myResolvedNames;
private IDictionary myFinalMap = new Hashtable ();
// public JoinNameResolver (JoinTableSchema joinSchema, IBlueTableSchema leftSchema, string leftColMapExpression,
// IBlueTableSchema rightSchema, string rightColMapExpression)
// {
// myJoinSchema = joinSchema;
// myLeftSchema = leftSchema;
// myRightSchema = rightSchema;
// myLeftColExpression = leftColMapExpression;
// myRightColExpression = rightColMapExpression;
// /*initialize the joinNames one-D structure. The id is removed as it does not
// * take part in the renaming process */
// myJoinNames = new ArrayList (joinSchema.columnNames);
// /*initialize the originalInfo one-D structure. Its an array of OriginalNameInfo, ie name and a bool indicating that
// * it belongs to the left or right table */
// myOriginalColInfo = new OriginalNameInfo [joinSchema.columnNames.Length - 1];
// myUserRules = new String[myOriginalColInfo.Length];
// myFormOriginalNameInfo (true);
// myFormOriginalNameInfo (false);
// myFormUserRules ();
// myFormResolvedNames ();
// myFormFinalMap ();
// }
public JoinNameResolver (JoinTableSchema joinSchema, IBlueTableSchema leftSchema, string leftColMapExpression,
IBlueTableSchema rightSchema, string rightColMapExpression)
{
myJoinSchema = joinSchema;
myLeftSchema = leftSchema;
myRightSchema = rightSchema;
myLeftColExpression = leftColMapExpression;
myRightColExpression = rightColMapExpression;
/*initialize the joinNames one-D structure. The id is removed as it does not
* take part in the renaming process */
myJoinNames = new ArrayList (joinSchema.columnNames);
/*initialize the originalInfo one-D structure. Its an array of OriginalNameInfo, ie name and a bool indicating that
* it belongs to the left or right table */
myOriginalColInfo = new OriginalNameInfo [joinSchema.columnNames.Length - 1];
myUserRules = new String[myOriginalColInfo.Length];
myFormOriginalNameInfo (true);
myFormOriginalNameInfo (false);
myFormUserRules ();
myFormResolvedNames ();
myFormFinalMap ();
}
// /// <summary>
// /// Forms the array representing the name as they appear in the JoinOperand.
// /// This is done so that its alligned with the myJoinNames
// /// </summary>
// /// <param name="isLeft">indicating whether its the left operand or the right</param>
// private void myFormOriginalNameInfo (bool isLeft)
// {
// IBlueTableSchema operandSchema = isLeft ? myLeftSchema : myRightSchema;
// foreach (string colName in operandSchema.columnNames)
// {
// string joinName = myJoinSchema.getRenamedName (colName, isLeft);
// //joinName is bound to be unique
// int index = myJoinNames.IndexOf (joinName);
// BlueEventLog.logAssert (index >= 0 && index < myOriginalColInfo.Length);
// myOriginalColInfo[index] = new OriginalNameInfo(colName, isLeft);
// }
// }
// static syntax myParser =
// new syntax();
/// <summary>
/// Forms the array representing the name as they appear in the JoinOperand.
/// This is done so that its alligned with the myJoinNames
/// </summary>
/// <param name="isLeft">indicating whether its the left operand or the right</param>
private void myFormOriginalNameInfo (bool isLeft)
{
IBlueTableSchema operandSchema = isLeft ? myLeftSchema : myRightSchema;
foreach (string colName in operandSchema.columnNames)
{
string joinName = myJoinSchema.getRenamedName (colName, isLeft);
//joinName is bound to be unique
int index = myJoinNames.IndexOf (joinName);
Log.assert(index >= 0 && index < myOriginalColInfo.Length);
myOriginalColInfo[index] = new OriginalNameInfo(colName, isLeft);
}
}
// /// <summary>
// /// Creates the user mapping from the grammer and then actually call the methods that form the array of
// /// user defined names
// /// </summary>
// private void myFormUserRules ()
// {
// if (DataStreamLoadFileConfig.instance.useStaticParser)
// {
// lock (myParser)
// {
// myFormUserRules(true, (ColumnMapExpression)
// myParser.Parse(myLeftColExpression));
// myFormUserRules(false, (ColumnMapExpression)
// myParser.Parse(myRightColExpression));
// }
// }
// else
// {
// syntax parser = new syntax();
// myFormUserRules(true, (ColumnMapExpression)
// parser.Parse(myLeftColExpression));
// myFormUserRules(false, (ColumnMapExpression)
// parser.Parse(myRightColExpression));
// }
/// <summary>
/// Creates the user mapping from the grammer and then actually call the methods that form the array of
/// user defined names
/// </summary>
private void myFormUserRules ()
{
if (DataStreamLoadFileConfig.instance.useStaticParser)
{
myFormUserRules(true, ColumnMapExpression.Parse(myLeftColExpression));
myFormUserRules(false, ColumnMapExpression.Parse(myRightColExpression));
}
else
{
// TODO (maybe): Actually use non-static parser (unclear what advantages it will have)
myFormUserRules(true, ColumnMapExpression.Parse(myLeftColExpression));
myFormUserRules(false, ColumnMapExpression.Parse(myRightColExpression));
}
// }
}
// /// <summary>
// /// Forms the array of user defined names
// /// </summary>
// /// <param name="isLeft"></param>
// /// <param name="cme"></param>
// private void myFormUserRules (bool isLeft, ColumnMapExpression cme)
// {
// IDictionary userMap = cme.columns;
// if (cme.isInclusive)
// for(int i = 0; i < myOriginalColInfo.Length ; i++)
// {
// OriginalNameInfo oni = myOriginalColInfo[i];
// if (oni.isLeft == isLeft)
// {
// if (userMap[oni.colName] != null)
// {
// if ((string)userMap[oni.colName] != oni.colName)
// myUserRules[i] = (string)userMap[oni.colName];
// else
// myUserRules[i] = oni.colName;
// }
// }
// }
// else
// {
// for (int i = 0; i < myOriginalColInfo.Length; i ++)
// {
// OriginalNameInfo oni = myOriginalColInfo[i];
// if (oni.isLeft == isLeft)
// {
// if (userMap[oni.colName] == null)
// myUserRules[i] = oni.colName;
// else if ((string)userMap[oni.colName] != oni.colName)
// myUserRules[i] = (string)userMap[oni.colName];
// }
// }
// }
// }
/// <summary>
/// Forms the array of user defined names
/// </summary>
/// <param name="isLeft"></param>
/// <param name="cme"></param>
private void myFormUserRules (bool isLeft, ColumnMapExpression cme)
{
IDictionary userMap = cme.Columns;
if (cme.IsInclusive)
for(int i = 0; i < myOriginalColInfo.Length ; i++)
{
OriginalNameInfo oni = myOriginalColInfo[i];
if (oni.isLeft == isLeft)
{
if (userMap[oni.colName] != null)
{
if ((string)userMap[oni.colName] != oni.colName)
myUserRules[i] = (string)userMap[oni.colName];
else
myUserRules[i] = oni.colName;
}
}
}
else
{
for (int i = 0; i < myOriginalColInfo.Length; i ++)
{
OriginalNameInfo oni = myOriginalColInfo[i];
if (oni.isLeft == isLeft)
{
if (userMap[oni.colName] == null)
myUserRules[i] = oni.colName;
else if ((string)userMap[oni.colName] != oni.colName)
myUserRules[i] = (string)userMap[oni.colName];
}
}
}
}
// private void myFormResolvedNames()
// {
// string prependString;
// myResolvedNames = new string[myUserRules.Length];
// Array.Copy (myUserRules, myResolvedNames, myUserRules.Length);
// string[] temp = myUserRules;
// myUserRules = new String[temp.Length + 1];
// Array.Copy (temp, 0, myUserRules, 0, temp.Length);
// myUserRules[myUserRules.Length - 1] = "id";
private void myFormResolvedNames()
{
string prependString;
myResolvedNames = new string[myUserRules.Length];
Array.Copy (myUserRules, myResolvedNames, myUserRules.Length);
string[] temp = myUserRules;
myUserRules = new String[temp.Length + 1];
Array.Copy (temp, 0, myUserRules, 0, temp.Length);
myUserRules[myUserRules.Length - 1] = "id";
// for (int i = 0; i < myResolvedNames.Length; i ++)
// {
// ArrayList occurances = myFindAllInCollection (myUserRules, myResolvedNames[i]);
// while (occurances.Count > 1)
// {
// prependString = i < myLeftSchema.columnNames.Length ? "L." : "R.";
// myResolvedNames[i] = prependString + myResolvedNames[i];
// occurances = myFindAllInCollection (myUserRules, myResolvedNames[i]);
// occurances.AddRange (myFindAllInCollection (myResolvedNames, myResolvedNames[i]));
// }
// }
// }
for (int i = 0; i < myResolvedNames.Length; i ++)
{
ArrayList occurances = myFindAllInCollection (myUserRules, myResolvedNames[i]);
while (occurances.Count > 1)
{
prependString = i < myLeftSchema.columnNames.Length ? "L." : "R.";
myResolvedNames[i] = prependString + myResolvedNames[i];
occurances = myFindAllInCollection (myUserRules, myResolvedNames[i]);
occurances.AddRange (myFindAllInCollection (myResolvedNames, myResolvedNames[i]));
}
}
}
// private void myFormFinalMap ()
// {
// foreach (string resolvedName in myResolvedNames)
// if (resolvedName != null)
// myFinalMap [resolvedName] = myJoinNames[Array.IndexOf (myResolvedNames, resolvedName)];
// }
private void myFormFinalMap ()
{
foreach (string resolvedName in myResolvedNames)
if (resolvedName != null)
myFinalMap [resolvedName] = myJoinNames[Array.IndexOf (myResolvedNames, resolvedName)];
}
// /// <summary>
// /// Utility method to invert a hashtable
// /// </summary>
// /// <param name="arg"></param>
// /// <returns></returns>
/// <summary>
/// Utility method to invert a hashtable
/// </summary>
/// <param name="arg"></param>
/// <returns></returns>
// private IDictionary reciprocateDictionary (IDictionary arg)
// {
// IDictionary retVal = new Hashtable ();
// foreach (DictionaryEntry de in arg)
// retVal[de.Value] = de.Key;
// return retVal;
// }
private IDictionary reciprocateDictionary (IDictionary arg)
{
IDictionary retVal = new Hashtable ();
foreach (DictionaryEntry de in arg)
retVal[de.Value] = de.Key;
return retVal;
}
// /// <summary>
// /// Utility method to find all occurances of an obkect in an IList
// /// </summary>
// /// <param name="list"></param>
// /// <param name="obj"></param>
// /// <returns></returns>
// private ArrayList myFindAllInCollection (IList list, object obj)
// {
// ArrayList retVal = new ArrayList ();
// for (int i = 0; i < list.Count; i++)
// if (list[i] != null && list[i].Equals (obj))
// retVal.Add (i);
// return retVal;
// }
/// <summary>
/// Utility method to find all occurances of an obkect in an IList
/// </summary>
/// <param name="list"></param>
/// <param name="obj"></param>
/// <returns></returns>
private ArrayList myFindAllInCollection (IList list, object obj)
{
ArrayList retVal = new ArrayList ();
for (int i = 0; i < list.Count; i++)
if (list[i] != null && list[i].Equals (obj))
retVal.Add (i);
return retVal;
}
// public IDictionary getMap () {return myFinalMap;}
public IDictionary getMap () {return myFinalMap;}
// }
// }
}
}
@@ -1,113 +1,113 @@
// // using System;
// // using System.Collections;
// // using BCG.Utilities;
using System;
using System.Collections;
using BCG.Utilities;
// // namespace BCG
// // {
// // /// <summary>
// // /// Represents each operand of the Join Operations. Does some bookkeeping like mantaining indexes on
// // /// rows for fast retrieval and row matching
// // /// </summary>
// // public class JoinOperand
// // {
// // private string myJoinCol;
// // private DataPacket myLastArrivedPacket;
// // private JoinOperand myOtherOperand;
// // private bool myIsLeft;
// // private JoinOperandRowIndex myRowIndex;
// // private InternalJoinStream myMaster;
// // private IBlueTableSchema myOpSchema;
namespace BCG
{
/// <summary>
/// Represents each operand of the Join Operations. Does some bookkeeping like mantaining indexes on
/// rows for fast retrieval and row matching
/// </summary>
public class JoinOperand
{
private string myJoinCol;
private DataPacket myLastArrivedPacket;
private JoinOperand myOtherOperand;
private bool myIsLeft;
private JoinOperandRowIndex myRowIndex;
private InternalJoinStream myMaster;
private IBlueTableSchema myOpSchema;
// // public JoinOperand (string joinCol, bool isLeft)
// // {
// // myJoinCol = joinCol;
// // myIsLeft = isLeft;
// // }
public JoinOperand (string joinCol, bool isLeft)
{
myJoinCol = joinCol;
myIsLeft = isLeft;
}
// // internal void changeHandler (object o)
// // {
// // DataPacket temp = (DataPacket)o;
// // if (myLastArrivedPacket != null)
// // mySubsequentChangeHandler ((DataPacket)o);
// // else
// // myFirstChangeHandler ((DataPacket)o);
// // }
internal void changeHandler (object o)
{
DataPacket temp = (DataPacket)o;
if (myLastArrivedPacket != null)
mySubsequentChangeHandler ((DataPacket)o);
else
myFirstChangeHandler ((DataPacket)o);
}
// // private void myFirstChangeHandler (DataPacket arrivedDp)
// // {
// // myLastArrivedPacket = arrivedDp;
// // myOpSchema = myLastArrivedPacket.newRows.schema;
// // myOtherOperand = myMaster.getOtherOperand (this);
// // myRowIndex = new JoinOperandRowIndex (myOpSchema[myJoinCol].colNo, myOpSchema["id"].colNo);
// // if (myOtherOperand.hasReceivedData)
// // {
// // //the other operand has already received data, so the join would
// // //actually be performed now, note, this is the first and only time
// // //the whole join is being performed. All other joins would be
// // //incremental
// // myMaster.startSession ();
// // myMaster.addRows (myLastArrivedPacket.newRows, myIsLeft);
// // myMaster.endSession ();
// // }
// // else
// // myRowIndex = new JoinOperandRowIndex (myLastArrivedPacket.newRows,
// // myOpSchema[myJoinCol].colNo,
// // myOpSchema["id"].colNo);
// // }
private void myFirstChangeHandler (DataPacket arrivedDp)
{
myLastArrivedPacket = arrivedDp;
myOpSchema = myLastArrivedPacket.newRows.schema;
myOtherOperand = myMaster.getOtherOperand (this);
myRowIndex = new JoinOperandRowIndex (myOpSchema[myJoinCol].colNo, myOpSchema["id"].colNo);
if (myOtherOperand.hasReceivedData)
{
//the other operand has already received data, so the join would
//actually be performed now, note, this is the first and only time
//the whole join is being performed. All other joins would be
//incremental
myMaster.startSession ();
myMaster.addRows (myLastArrivedPacket.newRows, myIsLeft);
myMaster.endSession ();
}
else
myRowIndex = new JoinOperandRowIndex (myLastArrivedPacket.newRows,
myOpSchema[myJoinCol].colNo,
myOpSchema["id"].colNo);
}
// // private void mySubsequentChangeHandler (DataPacket arrivedDp)
// // {
// // myLastArrivedPacket = arrivedDp;
// // if (!myOtherOperand.hasReceivedData)
// // {
// // //no reason to call the master to actually perform
// // //the join, as the other operand is not there. Though
// // //this case has not been witnessed as yet, but
// // //theoriticaly its possible
// // foreach (IBlueRow row in myLastArrivedPacket.deletedRows)
// // deleteRow (row);
// // foreach (IBlueRow row in myLastArrivedPacket.addedRows)
// // addRow (row);
// // return;
// // }
// // myMaster.startSession ();
// // if (myLastArrivedPacket.newRows.Count == 0)
// // {
// // myRowIndex.clear ();
// // myMaster.onTableClear (myIsLeft);
// // }
// // else
// // {
// // //the only condition when the join will actually take place
// // myMaster.deleteRows (myLastArrivedPacket.deletedRows, myIsLeft);
// // myMaster.addRows (myLastArrivedPacket.addedRows, myIsLeft);
// // }
// // myMaster.endSession ();
// // }
private void mySubsequentChangeHandler (DataPacket arrivedDp)
{
myLastArrivedPacket = arrivedDp;
if (!myOtherOperand.hasReceivedData)
{
//no reason to call the master to actually perform
//the join, as the other operand is not there. Though
//this case has not been witnessed as yet, but
//theoriticaly its possible
foreach (IBlueRow row in myLastArrivedPacket.deletedRows)
deleteRow (row);
foreach (IBlueRow row in myLastArrivedPacket.addedRows)
addRow (row);
return;
}
myMaster.startSession ();
if (myLastArrivedPacket.newRows.Count == 0)
{
myRowIndex.clear ();
myMaster.onTableClear (myIsLeft);
}
else
{
//the only condition when the join will actually take place
myMaster.deleteRows (myLastArrivedPacket.deletedRows, myIsLeft);
myMaster.addRows (myLastArrivedPacket.addedRows, myIsLeft);
}
myMaster.endSession ();
}
// // internal void addRow (IBlueRow row) {myRowIndex.add (row);}
internal void addRow (IBlueRow row) {myRowIndex.add (row);}
// // internal void deleteRow (IBlueRow row) {myRowIndex.remove (row);}
internal void deleteRow (IBlueRow row) {myRowIndex.remove (row);}
// // internal IBlueTableSchema operandSchema {get{return myOpSchema;}}
internal IBlueTableSchema operandSchema {get{return myOpSchema;}}
// // internal InternalJoinStream master {set{myMaster = value;}}
internal InternalJoinStream master {set{myMaster = value;}}
// // internal string joinCol {get{return myJoinCol;}}
internal string joinCol {get{return myJoinCol;}}
// // internal int joinColOridinal {get{return myOpSchema[myJoinCol].colNo;}}
internal int joinColOridinal {get{return myOpSchema[myJoinCol].colNo;}}
// // internal RowList getMatchingRows (object key) {return (RowList) myRowIndex.getMatchingRows (key);}
internal RowList getMatchingRows (object key) {return (RowList) myRowIndex.getMatchingRows (key);}
// // internal bool hasReceivedData {get{return myLastArrivedPacket != null;}}
internal bool hasReceivedData {get{return myLastArrivedPacket != null;}}
// // internal void init ()
// // {
// // ///should be brought back to the the state before the first callback
// // ///(ie the state after construction)
// // myRowIndex = null;
// // myLastArrivedPacket = null;
// // }
internal void init ()
{
///should be brought back to the the state before the first callback
///(ie the state after construction)
myRowIndex = null;
myLastArrivedPacket = null;
}
// // }
// // }
}
}
@@ -1,154 +1,155 @@
// using System;
// using BCG.Utilities;
// using System.Collections;
using System;
using BCG.Utilities;
using System.Collections;
using bts;
// namespace BCG
// {
// internal class JoinRow : IBlueRow
// {
// private RowNode myLeftNode, myRightNode;
// protected IBlueRow myLeftRow, myRightRow;
// protected int myId;
// protected JoinTableSchema mySchema;
// private object[] myValues;
namespace BCG
{
internal class JoinRow : IBlueRow
{
private RowNode myLeftNode, myRightNode;
protected IBlueRow myLeftRow, myRightRow;
protected int myId;
protected JoinTableSchema mySchema;
private object[] myValues;
// #region Constructor(s)
#region Constructor(s)
// /// <summary>
// /// Constructs a row, assigning it the same ID as that of the left row.
// /// </summary>
// /// <param name="leftRow">left row of the join</param>
// /// <param name="rightRow">right row of the join</param>
// /// <param name="schema">schema of the joined row</param>
// public JoinRow (IBlueRow leftRow, IBlueRow rightRow, JoinTableSchema schema)
// : this ((int)leftRow["id"], leftRow, rightRow, schema) {}
/// <summary>
/// Constructs a row, assigning it the same ID as that of the left row.
/// </summary>
/// <param name="leftRow">left row of the join</param>
/// <param name="rightRow">right row of the join</param>
/// <param name="schema">schema of the joined row</param>
public JoinRow (IBlueRow leftRow, IBlueRow rightRow, JoinTableSchema schema)
: this ((int)leftRow["id"], leftRow, rightRow, schema) {}
// /// <summary>
// /// Constructs a row assigning it the ID provioded as the first argument
// /// </summary>
// /// <param name="id">id of the joined row</param>
// /// <param name="leftRow">left row of the join</param>
// /// <param name="rightRow">right row of the join</param>
// /// <param name="schema">schema of the joined row</param>
// public JoinRow (int id, IBlueRow leftRow, IBlueRow rightRow, JoinTableSchema schema)
// {
// myId = id;
// myLeftRow = leftRow;
// myRightRow = rightRow;
// mySchema = schema;
// myValues = new object [schema.columnNames.Length];
// }
/// <summary>
/// Constructs a row assigning it the ID provioded as the first argument
/// </summary>
/// <param name="id">id of the joined row</param>
/// <param name="leftRow">left row of the join</param>
/// <param name="rightRow">right row of the join</param>
/// <param name="schema">schema of the joined row</param>
public JoinRow (int id, IBlueRow leftRow, IBlueRow rightRow, JoinTableSchema schema)
{
myId = id;
myLeftRow = leftRow;
myRightRow = rightRow;
mySchema = schema;
myValues = new object [schema.columnNames.Length];
}
// #endregion
#endregion
// #region IBlueRow members
// public IBlueTableSchema schema {get{return mySchema;}}
// #endregion
#region IBlueRow members
public IBlueTableSchema schema {get{return mySchema;}}
#endregion
// public bool isPartialJoin{get{return myRightRow == null;}}
public bool isPartialJoin{get{return myRightRow == null;}}
// public RowNode leftNode
// {
// get{return myLeftNode;}
// set{myLeftNode = value;}
// }
public RowNode leftNode
{
get{return myLeftNode;}
set{myLeftNode = value;}
}
// public RowNode rightNode
// {
// get{return myRightNode;}
// set{myRightNode = value;}
// }
public RowNode rightNode
{
get{return myRightNode;}
set{myRightNode = value;}
}
// #region ICollection members
// public int Count{get{return mySchema.columnNames.Length;}}
#region ICollection members
public int Count{get{return mySchema.columnNames.Length;}}
// public bool IsSynchronized {get{return false;}}
public bool IsSynchronized {get{return false;}}
// public object SyncRoot{get{return this;}}
public object SyncRoot{get{return this;}}
// public void CopyTo (Array array, int index)
// {
// int i = 0;
// foreach (object o in this as IEnumerable)
// array.SetValue (o, i++);
// }
public void CopyTo (Array array, int index)
{
int i = 0;
foreach (object o in this as IEnumerable)
array.SetValue (o, i++);
}
// #endregion
#endregion
// #region IDictionary members
// public bool IsFixedSize {get{return true;}}
#region IDictionary members
public bool IsFixedSize {get{return true;}}
// public bool IsReadOnly {get{return true;}}
public bool IsReadOnly {get{return true;}}
// /// <summary>
// /// The key can either be the string corrsponding to the column name or
// /// the order of the column
// /// </summary>
// public virtual object this [object key]
// {
// get
// {
// if (key is string)
// return this[(string)key];
// return this[(int)key];
// }
// set {throw new NotSupportedException ("The IBlueRow is read only");}
// }
/// <summary>
/// The key can either be the string corrsponding to the column name or
/// the order of the column
/// </summary>
public virtual object this [object key]
{
get
{
if (key is string)
return this[(string)key];
return this[(int)key];
}
set {throw new NotSupportedException ("The IBlueRow is read only");}
}
// public object this [int index]
// {
// get
// {
// if (index == mySchema.columnNames.Length - 1)
// return myId;
// else if (index < myLeftRow.Count)
// {
// if (myValues[index] == null)
// myValues[index] = myLeftRow[index];
// return myValues[index];
// }
// else if (index >= myLeftRow.Count && index < mySchema.columnNames.Length - 1)
// {
// if (myValues[index] == null)
// myValues[index] = (myRightRow == null) ? DBNull.Value : myRightRow[index - myLeftRow.Count];
// return myValues[index];
// }
// BlueEventLog.logAssert (false, "Incorrect index in JoinRow");
// return null;
// }
// }
public object this [int index]
{
get
{
if (index == mySchema.columnNames.Length - 1)
return myId;
else if (index < myLeftRow.Count)
{
if (myValues[index] == null)
myValues[index] = myLeftRow[index];
return myValues[index];
}
else if (index >= myLeftRow.Count && index < mySchema.columnNames.Length - 1)
{
if (myValues[index] == null)
myValues[index] = (myRightRow == null) ? DBNull.Value : myRightRow[index - myLeftRow.Count];
return myValues[index];
}
Log.assert(false, "Incorrect index in JoinRow");
return null;
}
}
// public object this [string colName] {get{return this[mySchema[colName].colNo];}}
public object this [string colName] {get{return this[mySchema[colName].colNo];}}
// public ICollection Keys{get{return mySchema.columnNames;}}
public ICollection Keys{get{return mySchema.columnNames;}}
// public ICollection Values
// {
// get
// {
// object[] retVal = new object[mySchema.columnNames.Length];
// CopyTo (retVal, 0);
// return retVal;
// }
// }
public ICollection Values
{
get
{
object[] retVal = new object[mySchema.columnNames.Length];
CopyTo (retVal, 0);
return retVal;
}
}
// public void Add (object key, object value) {throw new NotSupportedException ("The IBlueRow is readonly");}
public void Add (object key, object value) {throw new NotSupportedException ("The IBlueRow is readonly");}
// public void Clear () {throw new NotSupportedException ("The IBlueRow is readonly");}
public void Clear () {throw new NotSupportedException ("The IBlueRow is readonly");}
// public bool Contains (object key){return mySchema[(string)key] != null;}
public bool Contains (object key){return mySchema[(string)key] != null;}
// /// <summary>
// /// Note, the default enumerator is the IDictionary's enumerator, so if user needs to
// /// iterate through the values, typecast this into an IEnumerable
// /// </summary>
// /// <returns></returns>
// public IDictionaryEnumerator GetEnumerator() {return new BlueRowDictionaryEnumerator(this);}
/// <summary>
/// Note, the default enumerator is the IDictionary's enumerator, so if user needs to
/// iterate through the values, typecast this into an IEnumerable
/// </summary>
/// <returns></returns>
public IDictionaryEnumerator GetEnumerator() {return new BlueRowDictionaryEnumerator(this);}
// IEnumerator IEnumerable.GetEnumerator () {return new BlueRowEnumerator(this);}
IEnumerator IEnumerable.GetEnumerator () {return new BlueRowEnumerator(this);}
// public void Remove (object key) {throw new NotSupportedException ("The IBlueRow is readonly");}
// #endregion
// }
public void Remove (object key) {throw new NotSupportedException ("The IBlueRow is readonly");}
#endregion
}
// }
}
@@ -1,165 +1,166 @@
// using System;
// using System.Data;
// using System.Collections;
// using System.Text.RegularExpressions;
// using BCG.Utilities;
// using BCG.Utilities.General;
using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using BCG.Utilities;
using BCG.Utilities.General;
using bts;
// namespace BCG
// {
// public class JoinStream : ViewStream
// {
// protected InternalJoinStream myIjs;
// protected ProjectStream myPs;
// protected ColumnMap myLeftCm, myRightCm;
// protected bool myIsProject = true;
// private bool myUseSuperJoin = DataStreamLoadFileConfig.instance.useNewJoin;
namespace BCG
{
public class JoinStream : ViewStream
{
protected InternalJoinStream myIjs;
protected ProjectStream myPs;
protected ColumnMap myLeftCm, myRightCm;
protected bool myIsProject = true;
private bool myUseSuperJoin = DataStreamLoadFileConfig.instance.useNewJoin;
// protected JoinStream () {}
// public JoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
// ViewStream v2, string joinCol2, ColumnMap cm2)
// {
// if (myUseSuperJoin)
// {
// ViewStream rs = this is LeftJoinStream ?
// new SuperLeftJoinStream(v1, joinCol1, cm1.columnExpression, v2, joinCol2, cm2.columnExpression) as ViewStream :
// new SuperJoinStream(v1, joinCol1, cm1.columnExpression, v2, joinCol2, cm2.columnExpression) as ViewStream;
// mySetRealSource(rs);
// }
// else
// {
// myLeftCm = cm1;
// myRightCm = cm2;
// //myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
// myIjs = myConstructInternalJoinStream(v1, joinCol1, v2, joinCol2);
// }
// }
protected JoinStream () {}
public JoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
ViewStream v2, string joinCol2, ColumnMap cm2)
{
if (myUseSuperJoin)
{
ViewStream rs = this is LeftJoinStream ?
new SuperLeftJoinStream(v1, joinCol1, cm1.columnExpression, v2, joinCol2, cm2.columnExpression) as ViewStream :
new SuperJoinStream(v1, joinCol1, cm1.columnExpression, v2, joinCol2, cm2.columnExpression) as ViewStream;
mySetRealSource(rs);
}
else
{
myLeftCm = cm1;
myRightCm = cm2;
//myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
myIjs = myConstructInternalJoinStream(v1, joinCol1, v2, joinCol2);
}
}
// public JoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2, string cmExp2)
// :
// this (
// v1,
// joinCol1,
// (cmExp1 == null ? new ColumnMap("!"):new ColumnMap(cmExp1)),
// v2,
// joinCol2,
// (cmExp2 == null ? new ColumnMap("!"):new ColumnMap(cmExp2)))
// {}
public JoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2, string cmExp2)
:
this (
v1,
joinCol1,
(cmExp1 == null ? new ColumnMap("!"):new ColumnMap(cmExp1)),
v2,
joinCol2,
(cmExp2 == null ? new ColumnMap("!"):new ColumnMap(cmExp2)))
{}
// public JoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2)
// :
// this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
// {}
public JoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2)
:
this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
{}
// public JoinStream (ViewStream v1, string joinCol1,
// ViewStream v2, string joinCol2, string cmExp2)
// :
// this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
// {}
public JoinStream (ViewStream v1, string joinCol1,
ViewStream v2, string joinCol2, string cmExp2)
:
this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
{}
// public JoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
// {
// if (myUseSuperJoin)
// {
// ViewStream rs = this is LeftJoinStream ?
// new SuperLeftJoinStream(v1, joinCol1, v2, joinCol2) as ViewStream :
// new SuperJoinStream(v1, joinCol1, v2, joinCol2) as ViewStream;
// mySetRealSource(rs);
// }
// else
// {
// //myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
// myIjs = myConstructInternalJoinStream(v1, joinCol1, v2, joinCol2);
// myIsProject = false;
// }
// }
public JoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
{
if (myUseSuperJoin)
{
ViewStream rs = this is LeftJoinStream ?
new SuperLeftJoinStream(v1, joinCol1, v2, joinCol2) as ViewStream :
new SuperJoinStream(v1, joinCol1, v2, joinCol2) as ViewStream;
mySetRealSource(rs);
}
else
{
//myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
myIjs = myConstructInternalJoinStream(v1, joinCol1, v2, joinCol2);
myIsProject = false;
}
}
// public JoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
// {
// myLeftCm = cm1;
// myRightCm = new ColumnMap ("!");
// //myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
// myIjs = myConstructInternalJoinStream (v1, joinCol1, v2, joinCol2);
// }
public JoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
{
myLeftCm = cm1;
myRightCm = new ColumnMap ("!");
//myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
myIjs = myConstructInternalJoinStream (v1, joinCol1, v2, joinCol2);
}
// public JoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
// {
// myLeftCm = new ColumnMap ("!");
// myRightCm = cm2;
// //myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
// myIjs = myConstructInternalJoinStream (v1, joinCol1, v2, joinCol2);
public JoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
{
myLeftCm = new ColumnMap ("!");
myRightCm = cm2;
//myIjs = new InternalJoinStream (v1, joinCol1, v2, joinCol2);
myIjs = myConstructInternalJoinStream (v1, joinCol1, v2, joinCol2);
// }
}
// protected virtual InternalJoinStream myConstructInternalJoinStream (
// ViewStream vs1,
// string joinCol1,
// ViewStream vs2,
// string joinCol2)
// {
// return new InternalJoinStream (vs1, joinCol1, vs2, joinCol2);
// }
protected virtual InternalJoinStream myConstructInternalJoinStream (
ViewStream vs1,
string joinCol1,
ViewStream vs2,
string joinCol2)
{
return new InternalJoinStream (vs1, joinCol1, vs2, joinCol2);
}
// protected void myInternalJoinChangeHandler (object o)
// {
// if (myIsProject)
// {
// if (myPs == null)
// {
// JoinNameResolver resolver = new JoinNameResolver ((JoinTableSchema)myIjs.schema, myIjs.getSchema (true), myLeftCm.columnExpression,
// myIjs.getSchema (false), myRightCm.columnExpression);
// IDictionary map = resolver.getMap ();
// map["id"] = "id";
// myPs = new ProjectStream (myIjs, map);
// myPs.onChange += new DataStream.ChangeDelegate (myProjectChangeHandler);
// return;
// }
// else
// BlueEventLog.logAssert (false, "This call back should not have been called");
// }
// else
// myFireEvent ((o as ICloneable).Clone());
// }
protected void myInternalJoinChangeHandler (object o)
{
if (myIsProject)
{
if (myPs == null)
{
JoinNameResolver resolver = new JoinNameResolver ((JoinTableSchema)myIjs.schema, myIjs.getSchema (true), myLeftCm.columnExpression,
myIjs.getSchema (false), myRightCm.columnExpression);
IDictionary map = resolver.getMap ();
map["id"] = "id";
myPs = new ProjectStream (myIjs, map);
myPs.onChange += new DataStream.ChangeDelegate (myProjectChangeHandler);
return;
}
else
Log.assert(false, "This call back should not have been called");
}
else
myFireEvent ((o as ICloneable).Clone());
}
// private void myProjectChangeHandler (object o)
// {
// if (myIjs.myOnChangeDelegate.GetInvocationList().Length > 1)
// myIjs.onChange -= new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
// myFireEvent ((o as ICloneable).Clone());
private void myProjectChangeHandler (object o)
{
if (myIjs.myOnChangeDelegate.GetInvocationList().Length > 1)
myIjs.onChange -= new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
myFireEvent ((o as ICloneable).Clone());
// }
}
// protected override void myOnFirstSubscriber ()
// {
// myIjs.onChange += new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
// }
protected override void myOnFirstSubscriber ()
{
myIjs.onChange += new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
}
// protected override void myOnLastSubscriber ()
// {
// // how does this relate to the -= in myProjectChangeHandler?
// myIjs.onChange -= new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
protected override void myOnLastSubscriber ()
{
// how does this relate to the -= in myProjectChangeHandler?
myIjs.onChange -= new DataStream.ChangeDelegate (myInternalJoinChangeHandler);
// // if there is a project after the ijs we need to
// // unsubscribe to it otherwise references will be kept and
// // a memory leak will occur
// if (myPs != null)
// myPs.onChange -= new DataStream.ChangeDelegate (myProjectChangeHandler);
// myPs = null;
// }
// if there is a project after the ijs we need to
// unsubscribe to it otherwise references will be kept and
// a memory leak will occur
if (myPs != null)
myPs.onChange -= new DataStream.ChangeDelegate (myProjectChangeHandler);
myPs = null;
}
// /**************************************TEST METHOD(S)*********************************************/
// /// <summary>
// /// Used for testing purposes only. This enables the test to work without a DataSource (PubServer,
// /// BaseServer etc), by directly calling the test method and passing data
// /// </summary>
// /// <param name="leftPacket"></param>
// /// <param name="rightPacket"></param>
// public void test (DataPacket dp, bool isLeft) {myIjs.test (dp, isLeft);}
// /***********************************************************************************************/
// }
// }
/**************************************TEST METHOD(S)*********************************************/
/// <summary>
/// Used for testing purposes only. This enables the test to work without a DataSource (PubServer,
/// BaseServer etc), by directly calling the test method and passing data
/// </summary>
/// <param name="leftPacket"></param>
/// <param name="rightPacket"></param>
public void test (DataPacket dp, bool isLeft) {myIjs.test (dp, isLeft);}
/***********************************************************************************************/
}
}
@@ -1,84 +1,84 @@
// // using System;
// // using System.Collections;
// // using System.IO;
// // using BCG.Utilities.General;
using System;
using System.Collections;
using System.IO;
using BCG.Utilities.General;
// // namespace BCG
// // {
// // internal class JoinTable : IBlueRowCollection
// // {
// // protected JoinTableSchema mySchema;
// // protected IDictionary myIdIndex = new Hashtable ();
// // protected JoinDeletionIndex myLeftIndex, myRightIndex;
// // private int myNewRowId;
namespace BCG
{
internal class JoinTable : IBlueRowCollection
{
protected JoinTableSchema mySchema;
protected IDictionary myIdIndex = new Hashtable ();
protected JoinDeletionIndex myLeftIndex, myRightIndex;
private int myNewRowId;
// // public JoinTable (JoinTableSchema schema)
// // {
// // mySchema = schema;
// // myLeftIndex = new JoinDeletionIndex (mySchema.getRenamedName ("id", true), true);
// // myRightIndex = new JoinDeletionIndex (mySchema.getRenamedName ("id", false), false);
// // }
public JoinTable (JoinTableSchema schema)
{
mySchema = schema;
myLeftIndex = new JoinDeletionIndex (mySchema.getRenamedName ("id", true), true);
myRightIndex = new JoinDeletionIndex (mySchema.getRenamedName ("id", false), false);
}
// // public IBlueRow this [int id]
// // {
// // get
// // {
// // if (myIdIndex[id] == null)
// // throw new BlueDataException ("ID " + id.ToString() + " does not exist in table " + mySchema.tableName);
// // return (IBlueRow)myIdIndex[id];
// // }
// // }
public IBlueRow this [int id]
{
get
{
if (myIdIndex[id] == null)
throw new BlueDataException ("ID " + id.ToString() + " does not exist in table " + mySchema.tableName);
return (IBlueRow)myIdIndex[id];
}
}
// // #region JoinTable members
// // public virtual void addRow (IBlueRow leftRow, IBlueRow rightRow, DataPacket dp)
// // {
// // JoinRow newRow = new JoinRow (myNewRowId, leftRow, rightRow, mySchema);
// // myIdIndex[myNewRowId ++] = newRow;
// // ((BlueTable)(dp.addedRows)).addRow (newRow);
// // myLeftIndex.add (newRow);
// // if (rightRow != null) //in case of left joins when right row is null
// // myRightIndex.add (newRow);
// // }
#region JoinTable members
public virtual void addRow (IBlueRow leftRow, IBlueRow rightRow, DataPacket dp)
{
JoinRow newRow = new JoinRow (myNewRowId, leftRow, rightRow, mySchema);
myIdIndex[myNewRowId ++] = newRow;
((BlueTable)(dp.addedRows)).addRow (newRow);
myLeftIndex.add (newRow);
if (rightRow != null) //in case of left joins when right row is null
myRightIndex.add (newRow);
}
// // public virtual void deleteRow (bool isLeft, IBlueRow deletedRow, DataPacket dp)
// // {
// // JoinDeletionIndex thisIndex = myRightIndex, otherIndex = myLeftIndex;
// // if (isLeft)
// // {
// // thisIndex = myLeftIndex;
// // otherIndex = myRightIndex;
// // }
// // RowList matchingNodes = thisIndex.getMatchingRows (deletedRow["id"]);
// // foreach (RowNode node in matchingNodes)
// // {
// // JoinRow row = (JoinRow)node.row;
// // RowNode correspondingNode = isLeft ? row.rightNode : row.leftNode;
// // if (correspondingNode != null)
// // otherIndex.remove (correspondingNode); //in case of partial left joinss
// // myIdIndex.Remove (row["id"]);
// // ((BlueTable)dp.deletedRows).addRow (row);
// // }
// // thisIndex.removeAll (deletedRow["id"]);
// // }
// // #endregion
// // #region ICollection members
// // public int Count{get{return myIdIndex.Count;}}
public virtual void deleteRow (bool isLeft, IBlueRow deletedRow, DataPacket dp)
{
JoinDeletionIndex thisIndex = myRightIndex, otherIndex = myLeftIndex;
if (isLeft)
{
thisIndex = myLeftIndex;
otherIndex = myRightIndex;
}
RowList matchingNodes = thisIndex.getMatchingRows (deletedRow["id"]);
foreach (RowNode node in matchingNodes)
{
JoinRow row = (JoinRow)node.row;
RowNode correspondingNode = isLeft ? row.rightNode : row.leftNode;
if (correspondingNode != null)
otherIndex.remove (correspondingNode); //in case of partial left joinss
myIdIndex.Remove (row["id"]);
((BlueTable)dp.deletedRows).addRow (row);
}
thisIndex.removeAll (deletedRow["id"]);
}
#endregion
#region ICollection members
public int Count{get{return myIdIndex.Count;}}
// // public bool IsSynchronized {get{return false;}}
public bool IsSynchronized {get{return false;}}
// // public object SyncRoot{get{return this;}}
public object SyncRoot{get{return this;}}
// // public void CopyTo (Array array, int index) {myIdIndex.Values.CopyTo (array, index);}
// // #endregion
public void CopyTo (Array array, int index) {myIdIndex.Values.CopyTo (array, index);}
#endregion
// // #region IEnumerable members
// // public IEnumerator GetEnumerator () {return myIdIndex.Values.GetEnumerator ();}
// // #endregion
#region IEnumerable members
public IEnumerator GetEnumerator () {return myIdIndex.Values.GetEnumerator ();}
#endregion
// // #region IBlueRowCollection members
// // public IBlueTableSchema schema {get{return mySchema;}}
// // public bool containsID (int id) {return myIdIndex[id] != null;}
// // #endregion
// // }
#region IBlueRowCollection members
public IBlueTableSchema schema {get{return mySchema;}}
public bool containsID (int id) {return myIdIndex[id] != null;}
#endregion
}
// // }
}
@@ -1,107 +1,109 @@
// using System;
// using System.Collections;
// using BCG.Utilities;
using System;
using System.Collections;
using BCG.Utilities;
// namespace BCG
// {
// /// <summary>
// /// Represents the schema of the Join Table. This schema is formed by combining the respective
// /// schemas of the operands.
// /// </summary>
// public class JoinTableSchema : BlueTableSchema
// {
// private string myLeftJc = "", myRightJc = "", myLeftId = "", myRightId = "";
// private IDictionary myLeftNameToAlias = new Hashtable ();
// private IDictionary myRightNameToAlias = new Hashtable ();
// private IDictionary myAliasToLeftName = new Hashtable(),
// myAliasToRightName = new Hashtable();
// /// <summary>
// /// Constructs the schema of the Jointable with the schema of the left and right tables. Incase of
// /// a name being there in both the shemas it prefixes the name with "L." or "R." accordingly. Column "id"
// /// is the last column in the schema
// /// </summary>
// /// <param name="leftSchema"></param>
// /// <param name="leftJc"></param>
// /// <param name="rightSchema"></param>
// /// <param name="rightJc"></param>
// public JoinTableSchema (IBlueTableSchema leftSchema, string leftJc,
// IBlueTableSchema rightSchema, string rightJc)
// {
// myIndexByColOrder = new ColumnInfo[leftSchema.columnNames.Length + rightSchema.columnNames.Length + 1];
// myTableName = leftSchema.tableName + " J " + rightSchema.tableName;
// ColumnInfo[] cis = leftSchema.columnInfo;
// string assignedColName;
// bool renamed = false;
// foreach (ColumnInfo ci in cis)
// {
// assignedColName = ci.colName;
// while (rightSchema[assignedColName] != null)
// {
// assignedColName = "L." + assignedColName;
// renamed = true;
// while (leftSchema[assignedColName] != null)
// assignedColName = "L." + assignedColName;
// }
// ColumnInfo newCi = new ColumnInfo (assignedColName, ci.colNo, ci.colType);
// BlueEventLog.logAssert (myIndexByColName[newCi.colName] == null);
// BlueEventLog.logAssert (myIndexByColOrder[newCi.colNo] == null);
// if (renamed)
// BlueEventLog.logAssert (leftSchema[assignedColName] == null);
// BlueEventLog.logAssert (rightSchema[assignedColName] == null);
// myIndexByColName [newCi.colName] = newCi;
// myIndexByColOrder [newCi.colNo] = newCi;
// myLeftNameToAlias[ci.colName] = newCi.colName;
// myLeftJc = ci.colName == leftJc ? assignedColName : myLeftJc;
// myLeftId = ci.colName == "id" ? assignedColName : myLeftId;
// renamed = false;
// }
// BlueEventLog.logAssert (myLeftJc != "" && myLeftId != "");
// int n = leftSchema.columnNames.Length;
// cis = rightSchema.columnInfo;
// renamed = false;
// foreach (ColumnInfo ci in cis)
// {
// assignedColName = ci.colName;
// while (leftSchema[assignedColName] != null)
// {
// assignedColName = "R." + assignedColName;
// renamed = true;
// while(rightSchema[assignedColName] != null)
// assignedColName = "R." + assignedColName;
// }
// ColumnInfo newCi = new ColumnInfo (assignedColName, ci.colNo + n, ci.colType);
// BlueEventLog.logAssert (myIndexByColName[assignedColName] == null);
// BlueEventLog.logAssert (myIndexByColOrder[newCi.colNo] == null);
// BlueEventLog.logAssert (leftSchema[assignedColName] == null);
// if (renamed)
// BlueEventLog.logAssert (rightSchema[assignedColName] == null);
// myIndexByColName [newCi.colName] = newCi;
// myIndexByColOrder [newCi.colNo] = newCi;
// myRightNameToAlias[ci.colName] = newCi.colName;
// myRightJc = ci.colName == rightJc ? assignedColName : myRightJc;
// myRightId = ci.colName == "id" ? assignedColName : myLeftJc;
// renamed = false;
// }
// myIndexByColName["id"] = new ColumnInfo("id", myIndexByColName.Count, typeof(int));
// myIndexByColOrder[myIndexByColOrder.Length - 1] = (ColumnInfo)myIndexByColName["id"];
// myAliasToLeftName = ProjectHelper.invertDic(myLeftNameToAlias);
// myAliasToRightName = ProjectHelper.invertDic(myRightNameToAlias);
// }
using bts;
// public string leftJoinCol {get{return myLeftJc;}}
namespace BCG
{
/// <summary>
/// Represents the schema of the Join Table. This schema is formed by combining the respective
/// schemas of the operands.
/// </summary>
public class JoinTableSchema : BlueTableSchema
{
private string myLeftJc = "", myRightJc = "", myLeftId = "", myRightId = "";
private IDictionary myLeftNameToAlias = new Hashtable ();
private IDictionary myRightNameToAlias = new Hashtable ();
private IDictionary myAliasToLeftName = new Hashtable(),
myAliasToRightName = new Hashtable();
/// <summary>
/// Constructs the schema of the Jointable with the schema of the left and right tables. Incase of
/// a name being there in both the shemas it prefixes the name with "L." or "R." accordingly. Column "id"
/// is the last column in the schema
/// </summary>
/// <param name="leftSchema"></param>
/// <param name="leftJc"></param>
/// <param name="rightSchema"></param>
/// <param name="rightJc"></param>
public JoinTableSchema (IBlueTableSchema leftSchema, string leftJc,
IBlueTableSchema rightSchema, string rightJc)
{
myIndexByColOrder = new ColumnInfo[leftSchema.columnNames.Length + rightSchema.columnNames.Length + 1];
myTableName = leftSchema.tableName + " J " + rightSchema.tableName;
ColumnInfo[] cis = leftSchema.columnInfo;
string assignedColName;
bool renamed = false;
foreach (ColumnInfo ci in cis)
{
assignedColName = ci.colName;
while (rightSchema[assignedColName] != null)
{
assignedColName = "L." + assignedColName;
renamed = true;
while (leftSchema[assignedColName] != null)
assignedColName = "L." + assignedColName;
}
ColumnInfo newCi = new ColumnInfo (assignedColName, ci.colNo, ci.colType);
Log.assert(myIndexByColName[newCi.colName] == null);
Log.assert(myIndexByColOrder[newCi.colNo] == null);
if (renamed)
Log.assert(leftSchema[assignedColName] == null);
Log.assert(rightSchema[assignedColName] == null);
myIndexByColName [newCi.colName] = newCi;
myIndexByColOrder [newCi.colNo] = newCi;
myLeftNameToAlias[ci.colName] = newCi.colName;
myLeftJc = ci.colName == leftJc ? assignedColName : myLeftJc;
myLeftId = ci.colName == "id" ? assignedColName : myLeftId;
renamed = false;
}
Log.assert(myLeftJc != "" && myLeftId != "");
int n = leftSchema.columnNames.Length;
cis = rightSchema.columnInfo;
renamed = false;
foreach (ColumnInfo ci in cis)
{
assignedColName = ci.colName;
while (leftSchema[assignedColName] != null)
{
assignedColName = "R." + assignedColName;
renamed = true;
while(rightSchema[assignedColName] != null)
assignedColName = "R." + assignedColName;
}
ColumnInfo newCi = new ColumnInfo (assignedColName, ci.colNo + n, ci.colType);
Log.assert(myIndexByColName[assignedColName] == null);
Log.assert(myIndexByColOrder[newCi.colNo] == null);
Log.assert(leftSchema[assignedColName] == null);
if (renamed)
Log.assert(rightSchema[assignedColName] == null);
myIndexByColName [newCi.colName] = newCi;
myIndexByColOrder [newCi.colNo] = newCi;
myRightNameToAlias[ci.colName] = newCi.colName;
myRightJc = ci.colName == rightJc ? assignedColName : myRightJc;
myRightId = ci.colName == "id" ? assignedColName : myLeftJc;
renamed = false;
}
myIndexByColName["id"] = new ColumnInfo("id", myIndexByColName.Count, typeof(int));
myIndexByColOrder[myIndexByColOrder.Length - 1] = (ColumnInfo)myIndexByColName["id"];
myAliasToLeftName = ProjectHelper.invertDic(myLeftNameToAlias);
myAliasToRightName = ProjectHelper.invertDic(myRightNameToAlias);
}
// public string rightJoinCol {get{return myRightJc;}}
public string leftJoinCol {get{return myLeftJc;}}
// public string getRenamedName (string origName, bool isLeft)
// {
// if (isLeft)
// return (string)myLeftNameToAlias[origName];
// return (string)myRightNameToAlias[origName];
// }
public string rightJoinCol {get{return myRightJc;}}
// public string getOriginalName(string rename, bool isLeft)
// {
// return isLeft ? myAliasToLeftName[rename].ToString() : myAliasToRightName[rename].ToString();
// }
// }
// }
public string getRenamedName (string origName, bool isLeft)
{
if (isLeft)
return (string)myLeftNameToAlias[origName];
return (string)myRightNameToAlias[origName];
}
public string getOriginalName(string rename, bool isLeft)
{
return isLeft ? myAliasToLeftName[rename].ToString() : myAliasToRightName[rename].ToString();
}
}
}
@@ -1,54 +1,54 @@
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// namespace BCG
// {
// /// <summary>
// /// Same as a join except can join based on
// /// multiple columns (this abstracts what we
// /// have been doing for ages - concatenating,
// /// joining and then projecting the concatanted
// /// columns out)
// /// </summary>
// public class MultiColumnJoinStream : ViewStream
// {
// public MultiColumnJoinStream(ViewStream leftStream, string leftJoinColumns, string leftProject,
// ViewStream rightStream, string rightJoinColumns, string rightProject)
// : this(leftStream, leftJoinColumns, leftProject,
// rightStream, rightJoinColumns, rightProject, false)
// { }
namespace BCG
{
/// <summary>
/// Same as a join except can join based on
/// multiple columns (this abstracts what we
/// have been doing for ages - concatenating,
/// joining and then projecting the concatanted
/// columns out)
/// </summary>
public class MultiColumnJoinStream : ViewStream
{
public MultiColumnJoinStream(ViewStream leftStream, string leftJoinColumns, string leftProject,
ViewStream rightStream, string rightJoinColumns, string rightProject)
: this(leftStream, leftJoinColumns, leftProject,
rightStream, rightJoinColumns, rightProject, false)
{ }
// public MultiColumnJoinStream(ViewStream leftStream, string leftJoinColumns, string leftProject,
// ViewStream rightStream, string rightJoinColumns, string rightProject, bool leftJoin)
// {
// string[] leftJoinColArray = leftJoinColumns.Split(' ', ',', ';'),
// rightJoinColArray = rightJoinColumns.Split(' ', ',', ';');
// if (leftJoinColArray.Length == 1 && rightJoinColArray.Length == 1)
// /// so that this handles regular joins too
// mySetRealSource(leftJoin ? new SuperLeftJoinStream(leftStream, leftJoinColArray[0], leftProject,
// rightStream, rightJoinColArray[0], rightProject) :
// new SuperJoinStream(leftStream, leftJoinColArray[0], leftProject,
// rightStream, rightJoinColArray[0], rightProject));
// else
// {
// string leftCols = "ljc:";
// foreach (string c in leftJoinColArray)
// leftCols += c + " ";
// leftCols = leftCols.Trim();
// string rightCols = "rjc:";
// foreach (string c in rightJoinColArray)
// rightCols += c + " ";
// rightCols = rightCols.Trim();
// ViewStream res =
// leftJoin ? new SuperLeftJoinStream(new ConcatenateColumnsStream(leftStream, leftCols), "ljc", leftProject,
// new ConcatenateColumnsStream(rightStream, rightCols), "rjc", rightProject) :
// new SuperJoinStream(new ConcatenateColumnsStream(leftStream, leftCols), "ljc", leftProject,
// new ConcatenateColumnsStream(rightStream, rightCols), "rjc", rightProject);
// res = new ProjectStream(res, "!ljc rjc");
// mySetRealSource(res);
// }
// }
// }
// }
public MultiColumnJoinStream(ViewStream leftStream, string leftJoinColumns, string leftProject,
ViewStream rightStream, string rightJoinColumns, string rightProject, bool leftJoin)
{
string[] leftJoinColArray = leftJoinColumns.Split(' ', ',', ';'),
rightJoinColArray = rightJoinColumns.Split(' ', ',', ';');
if (leftJoinColArray.Length == 1 && rightJoinColArray.Length == 1)
/// so that this handles regular joins too
mySetRealSource(leftJoin ? new SuperLeftJoinStream(leftStream, leftJoinColArray[0], leftProject,
rightStream, rightJoinColArray[0], rightProject) :
new SuperJoinStream(leftStream, leftJoinColArray[0], leftProject,
rightStream, rightJoinColArray[0], rightProject));
else
{
string leftCols = "ljc:";
foreach (string c in leftJoinColArray)
leftCols += c + " ";
leftCols = leftCols.Trim();
string rightCols = "rjc:";
foreach (string c in rightJoinColArray)
rightCols += c + " ";
rightCols = rightCols.Trim();
ViewStream res =
leftJoin ? new SuperLeftJoinStream(new ConcatenateColumnsStream(leftStream, leftCols), "ljc", leftProject,
new ConcatenateColumnsStream(rightStream, rightCols), "rjc", rightProject) :
new SuperJoinStream(new ConcatenateColumnsStream(leftStream, leftCols), "ljc", leftProject,
new ConcatenateColumnsStream(rightStream, rightCols), "rjc", rightProject);
res = new ProjectStream(res, "!ljc rjc");
mySetRealSource(res);
}
}
}
}
@@ -1,371 +1,371 @@
// using System;
// using System.Collections;
// using System.Collections.Generic;
// using System.Text;
// using BCG.Utilities.General;
// using BCG.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BCG.Utilities.General;
using BCG.Utilities;
// namespace BCG
// {
namespace BCG
{
// /// <summary>
// /// This class is used to effect a mapping between values in a join column and entries in three different tables:
// /// the left and right tables of a join, as well as the output table (the join table).
// /// </summary>
// class ParallelJoinTestTablePointer
// {
// int myLeftTableId = -1;
// public int LeftTableId
// {
// get { return myLeftTableId; }
// set { myLeftTableId = value; }
// }
/// <summary>
/// This class is used to effect a mapping between values in a join column and entries in three different tables:
/// the left and right tables of a join, as well as the output table (the join table).
/// </summary>
class ParallelJoinTestTablePointer
{
int myLeftTableId = -1;
public int LeftTableId
{
get { return myLeftTableId; }
set { myLeftTableId = value; }
}
// int myRightTableId = -1;
// public int RightTableId
// {
// get { return myRightTableId; }
// set { myRightTableId = value; }
// }
// int myJoinTableId = -1;
// public int JoinTableId
// {
// get { return myJoinTableId; }
// set { myJoinTableId = value; }
// }
int myRightTableId = -1;
public int RightTableId
{
get { return myRightTableId; }
set { myRightTableId = value; }
}
int myJoinTableId = -1;
public int JoinTableId
{
get { return myJoinTableId; }
set { myJoinTableId = value; }
}
// public ParallelJoinTestTablePointer(int leftId, int rightId, int joinId)
// {
// myLeftTableId = leftId;
// myRightTableId = rightId;
// myJoinTableId = joinId;
// }
// public ParallelJoinTestTablePointer() : this(-1,-1,-1)
// {
public ParallelJoinTestTablePointer(int leftId, int rightId, int joinId)
{
myLeftTableId = leftId;
myRightTableId = rightId;
myJoinTableId = joinId;
}
public ParallelJoinTestTablePointer() : this(-1,-1,-1)
{
// }
// }
}
}
// #region IBlueRow implementation for join and leftJoin
#region IBlueRow implementation for join and leftJoin
// public class ParallelJoinTestRow : IBlueRow
// {
// private JoinProjectHelper myHelper;
// private IBlueRow myLeftRow, myRightRow;
// int myID;
public class ParallelJoinTestRow : IBlueRow
{
private JoinProjectHelper myHelper;
private IBlueRow myLeftRow, myRightRow;
int myID;
// public ParallelJoinTestRow(int id, IBlueRow leftRow, IBlueRow rightRow, JoinProjectHelper joinProjectHelper)
// {
// myID = id;
// myLeftRow = leftRow;
// myRightRow = rightRow;
// myHelper = joinProjectHelper;
// }
public ParallelJoinTestRow(int id, IBlueRow leftRow, IBlueRow rightRow, JoinProjectHelper joinProjectHelper)
{
myID = id;
myLeftRow = leftRow;
myRightRow = rightRow;
myHelper = joinProjectHelper;
}
// public int leftID { get { return (int)myLeftRow["id"]; } }
public int leftID { get { return (int)myLeftRow["id"]; } }
// public int rightID { get { return (int)myRightRow["id"]; } }
public int rightID { get { return (int)myRightRow["id"]; } }
// public IBlueRow leftRow { get { return myLeftRow; } }
public IBlueRow leftRow { get { return myLeftRow; } }
// public IBlueRow rightRow { get { return myRightRow; } }
public IBlueRow rightRow { get { return myRightRow; } }
// #region IBlueRow Members
#region IBlueRow Members
// public IBlueTableSchema schema { get { return myHelper.schema; } }
public IBlueTableSchema schema { get { return myHelper.schema; } }
// public object this[int index] { get { return this[schema[index].colName]; } }
public object this[int index] { get { return this[schema[index].colName]; } }
// public object this[string colName]
// {
// get
// {
// if (colName == "id")
// return myID;
// else
// {
// bool isLeft;
// string col = myHelper.getOriginalCol(colName, out isLeft);
// return isLeft ? myLeftRow[col] : (myRightRow == null ? (object)DBNull.Value : myRightRow[col]);
// }
// }
// }
public object this[string colName]
{
get
{
if (colName == "id")
return myID;
else
{
bool isLeft;
string col = myHelper.getOriginalCol(colName, out isLeft);
return isLeft ? myLeftRow[col] : (myRightRow == null ? (object)DBNull.Value : myRightRow[col]);
}
}
}
// #endregion
#endregion
// #region IDictionary Members
#region IDictionary Members
// public void Add(object key, object value) { { throw new NotSupportedException("IBlueRow is readonly"); } }
public void Add(object key, object value) { { throw new NotSupportedException("IBlueRow is readonly"); } }
// public void Clear() { throw new NotSupportedException("IBlueRow is readonly"); }
public void Clear() { throw new NotSupportedException("IBlueRow is readonly"); }
// public bool Contains(object key) { throw new Exception("The method or operation is not implemented."); }
public bool Contains(object key) { throw new Exception("The method or operation is not implemented."); }
// public System.Collections.IDictionaryEnumerator GetEnumerator() { return new BlueRowDictionaryEnumerator(this); }
public System.Collections.IDictionaryEnumerator GetEnumerator() { return new BlueRowDictionaryEnumerator(this); }
// public bool IsFixedSize { get { return true; } }
public bool IsFixedSize { get { return true; } }
// public bool IsReadOnly {get { return true; }}
public bool IsReadOnly {get { return true; }}
// public System.Collections.ICollection Keys { get { return schema.columnNames; } }
public System.Collections.ICollection Keys { get { return schema.columnNames; } }
// public void Remove(object key) { throw new NotSupportedException("IBlueRow is readonly"); }
public void Remove(object key) { throw new NotSupportedException("IBlueRow is readonly"); }
// public System.Collections.ICollection Values
// {
// get
// {
// List<object> rv = new List<object> ();
// foreach (string col in Keys)
// rv.Add(this[col]);
// return rv;
// }
// }
public System.Collections.ICollection Values
{
get
{
List<object> rv = new List<object> ();
foreach (string col in Keys)
rv.Add(this[col]);
return rv;
}
}
// public object this[object key]
// {
// get { return key is string ? this[key.ToString()] : this[(int)key]; }
// set { throw new NotSupportedException("IBlueRow is readonly"); }
// }
public object this[object key]
{
get { return key is string ? this[key.ToString()] : this[(int)key]; }
set { throw new NotSupportedException("IBlueRow is readonly"); }
}
// #endregion
#endregion
// #region ICollection Members
#region ICollection Members
// public void CopyTo(Array array, int index) { Values.CopyTo(array, index); }
public void CopyTo(Array array, int index) { Values.CopyTo(array, index); }
// public int Count { get { return schema.columnNames.Length; } }
public int Count { get { return schema.columnNames.Length; } }
// public bool IsSynchronized { get { return false; } }
public bool IsSynchronized { get { return false; } }
// public object SyncRoot { get { return this; } }
public object SyncRoot { get { return this; } }
// #endregion
#endregion
// #region IEnumerable Members
#region IEnumerable Members
// System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new BlueRowEnumerator(this); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new BlueRowEnumerator(this); }
// #endregion
// }
#endregion
}
// #endregion
// /// <summary>
// /// This class represents a join on two streams. It works by storing a table with the result of the join.
// /// </summary>
// public class ParallelJoinTestStream : ViewStream
// {
// BlueTable myJoinedTable;
// BlueTable myLeftTable;
// BlueTable myRightTable;
// Hashtable myKeyToTablePointerMap;
// ViewStream myVLeft, myVRight;
#endregion
/// <summary>
/// This class represents a join on two streams. It works by storing a table with the result of the join.
/// </summary>
public class ParallelJoinTestStream : ViewStream
{
BlueTable myJoinedTable;
BlueTable myLeftTable;
BlueTable myRightTable;
Hashtable myKeyToTablePointerMap;
ViewStream myVLeft, myVRight;
// int myIdToUse;
// string myLeftKey, myRightKey, myLeftProj, myRightProj;
// public ParallelJoinTestStream(ViewStream leftStream, string leftKey, ViewStream rightStream, string rightKey)
// : this(leftStream, leftKey, "!", rightStream, rightKey, "!") { }
// public ParallelJoinTestStream(ViewStream leftStream, string leftKey, string leftProj, ViewStream rightStream, string rightKey, string rightProj)
// {
// myVLeft = leftStream;
// myVRight = rightStream;
int myIdToUse;
string myLeftKey, myRightKey, myLeftProj, myRightProj;
public ParallelJoinTestStream(ViewStream leftStream, string leftKey, ViewStream rightStream, string rightKey)
: this(leftStream, leftKey, "!", rightStream, rightKey, "!") { }
public ParallelJoinTestStream(ViewStream leftStream, string leftKey, string leftProj, ViewStream rightStream, string rightKey, string rightProj)
{
myVLeft = leftStream;
myVRight = rightStream;
// myLeftProj = leftProj;
// myRightProj = rightProj;
myLeftProj = leftProj;
myRightProj = rightProj;
// myLeftKey = leftKey;
// myRightKey = rightKey;
myLeftKey = leftKey;
myRightKey = rightKey;
// myKeyToTablePointerMap = new Hashtable();
// myIdToUse = 0;
// }
myKeyToTablePointerMap = new Hashtable();
myIdToUse = 0;
}
// protected override void myOnFirstSubscriber()
// {
// myVLeft.onChange += new ChangeDelegate(myVLeft_onChange);
// myVRight.onChange += new ChangeDelegate(myVRight_onChange);
// }
protected override void myOnFirstSubscriber()
{
myVLeft.onChange += new ChangeDelegate(myVLeft_onChange);
myVRight.onChange += new ChangeDelegate(myVRight_onChange);
}
// void myVRight_onChange(object newValue)
// {
// myHandleChange(newValue as DataPacket, false);
void myVRight_onChange(object newValue)
{
myHandleChange(newValue as DataPacket, false);
// }
}
// void myVLeft_onChange(object newValue)
// {
// myHandleChange(newValue as DataPacket, true);
void myVLeft_onChange(object newValue)
{
myHandleChange(newValue as DataPacket, true);
// }
}
// void myHandleChange(DataPacket dp, bool isLeft)
// {
void myHandleChange(DataPacket dp, bool isLeft)
{
// int i = 0; // for going throuhg loops and such
// BlueTable addedRows = null, droppedRows = null;
int i = 0; // for going throuhg loops and such
BlueTable addedRows = null, droppedRows = null;
// if (myJoinedTable == null)
// {
// if (isLeft && myLeftTable == null)
// {
// myLeftTable = new BlueTable(dp.addedRows);
if (myJoinedTable == null)
{
if (isLeft && myLeftTable == null)
{
myLeftTable = new BlueTable(dp.addedRows);
// //go through the list of added rows and get the id of each row, storing this in the TablePointer map
// foreach (IBlueRow row in myLeftTable)
// {
// if (myKeyToTablePointerMap.ContainsKey(row[myLeftKey]))
// {
// ((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myLeftKey]]).LeftTableId = (int)row["id"];
// }
// else
// {
// myKeyToTablePointerMap[row[myLeftKey]] = new ParallelJoinTestTablePointer((int)row["id"],-1,-1);
//go through the list of added rows and get the id of each row, storing this in the TablePointer map
foreach (IBlueRow row in myLeftTable)
{
if (myKeyToTablePointerMap.ContainsKey(row[myLeftKey]))
{
((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myLeftKey]]).LeftTableId = (int)row["id"];
}
else
{
myKeyToTablePointerMap[row[myLeftKey]] = new ParallelJoinTestTablePointer((int)row["id"],-1,-1);
// }
}
// }
}
// }
// else if (!isLeft && myRightTable == null)
// {
// myRightTable = new BlueTable(dp.addedRows);
// //go through the list of added rows and get the id of each row, storing this in the TablePointer map
// foreach (IBlueRow row in myRightTable)
// {
// if (myKeyToTablePointerMap.ContainsKey(row[myRightKey]))
// {
// ((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myRightKey]]).RightTableId = (int)row["id"];
// }
// else
// {
// myKeyToTablePointerMap[row[myRightKey]] = new ParallelJoinTestTablePointer(-1,(int)row["id"],-1);
}
else if (!isLeft && myRightTable == null)
{
myRightTable = new BlueTable(dp.addedRows);
//go through the list of added rows and get the id of each row, storing this in the TablePointer map
foreach (IBlueRow row in myRightTable)
{
if (myKeyToTablePointerMap.ContainsKey(row[myRightKey]))
{
((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myRightKey]]).RightTableId = (int)row["id"];
}
else
{
myKeyToTablePointerMap[row[myRightKey]] = new ParallelJoinTestTablePointer(-1,(int)row["id"],-1);
// }
}
// }
// }
}
}
// if (myLeftTable != null && myRightTable != null)
// {
// //construct the schema for the table based upon the schemas of the two tables that are going to be joined together
// int numColumns = myLeftTable.schema.columnInfo.Length;
if (myLeftTable != null && myRightTable != null)
{
//construct the schema for the table based upon the schemas of the two tables that are going to be joined together
int numColumns = myLeftTable.schema.columnInfo.Length;
// ColumnInfo[] newColumnInfoArray = new ColumnInfo[numColumns * 2 + 1];
// for (i = 0; i < numColumns; i++)
// {
// newColumnInfoArray[i] = new ColumnInfo("L." + myLeftTable.schema.columnNames[i], i, myLeftTable.schema.columnInfo[i].colType);
// newColumnInfoArray[numColumns + i] = new ColumnInfo("R." + myRightTable.schema.columnNames[i], i + numColumns, myRightTable.schema.columnInfo[i].colType);
// }
// newColumnInfoArray[numColumns + i] = new ColumnInfo("id", numColumns + i, (typeof(System.Int64)));
ColumnInfo[] newColumnInfoArray = new ColumnInfo[numColumns * 2 + 1];
for (i = 0; i < numColumns; i++)
{
newColumnInfoArray[i] = new ColumnInfo("L." + myLeftTable.schema.columnNames[i], i, myLeftTable.schema.columnInfo[i].colType);
newColumnInfoArray[numColumns + i] = new ColumnInfo("R." + myRightTable.schema.columnNames[i], i + numColumns, myRightTable.schema.columnInfo[i].colType);
}
newColumnInfoArray[numColumns + i] = new ColumnInfo("id", numColumns + i, (typeof(System.Int64)));
// IBlueTableSchema newSchema = new BlueTableSchema("Joined Table", newColumnInfoArray);
IBlueTableSchema newSchema = new BlueTableSchema("Joined Table", newColumnInfoArray);
// myJoinedTable = new BlueTable(newSchema);
// addedRows = new BlueTable(newSchema);
// droppedRows = new BlueTable(newSchema);
myJoinedTable = new BlueTable(newSchema);
addedRows = new BlueTable(newSchema);
droppedRows = new BlueTable(newSchema);
// //now that we've created the table, we should have some leftover stuff from the side tables
// //that we were storing until now. Add that stuff to the table.
// BlueTable rowsToAdd = isLeft ? myRightTable : myLeftTable;
//now that we've created the table, we should have some leftover stuff from the side tables
//that we were storing until now. Add that stuff to the table.
BlueTable rowsToAdd = isLeft ? myRightTable : myLeftTable;
// foreach (BlueRow row in rowsToAdd)
// {
// Object[] newRowObjects = new Object[newSchema.columnInfo.Length];
foreach (BlueRow row in rowsToAdd)
{
Object[] newRowObjects = new Object[newSchema.columnInfo.Length];
// if (isLeft)
// {
// for (i = 0; i < numColumns; i++)
// {
// newRowObjects[i] = row[i];
// newRowObjects[numColumns + i] = null;
if (isLeft)
{
for (i = 0; i < numColumns; i++)
{
newRowObjects[i] = row[i];
newRowObjects[numColumns + i] = null;
// }
// newRowObjects[numColumns + i] = myIdToUse;
// //store the fact that the row with this key value went to this id
}
newRowObjects[numColumns + i] = myIdToUse;
//store the fact that the row with this key value went to this id
// ((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myLeftKey]]).JoinTableId = myIdToUse;
// myIdToUse++;
((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myLeftKey]]).JoinTableId = myIdToUse;
myIdToUse++;
// }
// else
// {
// for (i = 0; i < numColumns; i++)
// {
// newRowObjects[i] = null;
// newRowObjects[numColumns + i] = row[i];
}
else
{
for (i = 0; i < numColumns; i++)
{
newRowObjects[i] = null;
newRowObjects[numColumns + i] = row[i];
// }
// newRowObjects[numColumns + i] = myIdToUse;
// //store the fact that the row with this key value went to this id
// ((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myRightKey]]).JoinTableId = myIdToUse;
// myIdToUse++;
// }
}
newRowObjects[numColumns + i] = myIdToUse;
//store the fact that the row with this key value went to this id
((ParallelJoinTestTablePointer)myKeyToTablePointerMap[row[myRightKey]]).JoinTableId = myIdToUse;
myIdToUse++;
}
// BlueRow newRow = new BlueRow(newSchema, newRowObjects);
// addedRows.addRow(newRow);
// myJoinedTable.addRow(newRow);
BlueRow newRow = new BlueRow(newSchema, newRowObjects);
addedRows.addRow(newRow);
myJoinedTable.addRow(newRow);
// }
}
// }
// }
// else
// {
// addedRows = new BlueTable(myJoinedTable.schema);
// droppedRows = new BlueTable(myJoinedTable.schema);
// }
}
}
else
{
addedRows = new BlueTable(myJoinedTable.schema);
droppedRows = new BlueTable(myJoinedTable.schema);
}
// //setup is complete. At this point, we have to delete all the rows that were deleted, then add in the rows that were added in.
//setup is complete. At this point, we have to delete all the rows that were deleted, then add in the rows that were added in.
// foreach (BlueRow row in dp.addedRows)
// {
// //check to see if this row has a match in the table already.
// //If it does, get rid of that row in the table because it's OUT OF DATE
// string joinColumn = isLeft ? myLeftKey : myRightKey;
foreach (BlueRow row in dp.addedRows)
{
//check to see if this row has a match in the table already.
//If it does, get rid of that row in the table because it's OUT OF DATE
string joinColumn = isLeft ? myLeftKey : myRightKey;
// if (myKeyToTablePointerMap.ContainsKey(row[joinColumn]))
// {
// //the value is already in the hashtable.
// ParallelJoinTestTablePointer tp = (ParallelJoinTestTablePointer) myKeyToTablePointerMap[row[joinColumn]];
// int rowOfExistingGuy = tp.JoinTableId;
if (myKeyToTablePointerMap.ContainsKey(row[joinColumn]))
{
//the value is already in the hashtable.
ParallelJoinTestTablePointer tp = (ParallelJoinTestTablePointer) myKeyToTablePointerMap[row[joinColumn]];
int rowOfExistingGuy = tp.JoinTableId;
// if (rowOfExistingGuy != -1)
// {
if (rowOfExistingGuy != -1)
{
// //remove this guy from the table
// IBlueRow rowToDelete = myJoinedTable[rowOfExistingGuy];
// myJoinedTable.deleteRow(rowToDelete);
// droppedRows.addRow(rowToDelete);
// tp.JoinTableId = -1;
// }
//remove this guy from the table
IBlueRow rowToDelete = myJoinedTable[rowOfExistingGuy];
myJoinedTable.deleteRow(rowToDelete);
droppedRows.addRow(rowToDelete);
tp.JoinTableId = -1;
}
// }
// }
}
}
// //finally, fire off a packet, but only if you have enough information about the table to do so.
//finally, fire off a packet, but only if you have enough information about the table to do so.
// if (myJoinedTable != null)
// {
// DataPacket outPacket = new DataPacket(myJoinedTable,addedRows, new BlueTable(myJoinedTable.schema));
// myFireEvent(outPacket);
// }
if (myJoinedTable != null)
{
DataPacket outPacket = new DataPacket(myJoinedTable,addedRows, new BlueTable(myJoinedTable.schema));
myFireEvent(outPacket);
}
// }
}
// }
}
// }
}
File diff suppressed because it is too large. Load diff
@@ -1,38 +1,38 @@
// using System;
using System;
// namespace BCG
// {
// [DataStreamUserRespresentation (false)]
// public class LeftInternalJoinForeignStream : LeftInternalJoinStream
// {
// public LeftInternalJoinForeignStream (ViewStream vsLeft,
// string jcLeft,
// ViewStream vsRight,
// string jcRight) :
// base (vsLeft, jcLeft, vsRight, jcRight) {}
namespace BCG
{
[DataStreamUserRespresentation (false)]
public class LeftInternalJoinForeignStream : LeftInternalJoinStream
{
public LeftInternalJoinForeignStream (ViewStream vsLeft,
string jcLeft,
ViewStream vsRight,
string jcRight) :
base (vsLeft, jcLeft, vsRight, jcRight) {}
// public LeftInternalJoinForeignStream (ViewStream vsLeft,
// string jcLeft,
// ViewStream vsRight) :
// this (vsLeft, jcLeft, vsRight, "id") {}
public LeftInternalJoinForeignStream (ViewStream vsLeft,
string jcLeft,
ViewStream vsRight) :
this (vsLeft, jcLeft, vsRight, "id") {}
// public override void onTableClear (bool isLeft)
// {
// myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
// myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// if (!isLeft)
// foreach (IBlueRow row in myLeftDataPacket.newRows)
// ((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
// }
public override void onTableClear (bool isLeft)
{
myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
if (!isLeft)
foreach (IBlueRow row in myLeftDataPacket.newRows)
((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
}
// protected override void myInitFiredPacket ()
// {
// myLastFiredPacket = new DataPacket ();
// myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// myLastFiredPacket.deletedRows = new BlueTable (mySchema);
// }
protected override void myInitFiredPacket ()
{
myLastFiredPacket = new DataPacket ();
myLastFiredPacket.newRows = new JoinForeignTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
myLastFiredPacket.deletedRows = new BlueTable (mySchema);
}
// }
// }
}
}
@@ -1,182 +1,182 @@
// using System;
// using System.Collections;
// using BCG.Utilities;
using System;
using System.Collections;
using BCG.Utilities;
// namespace BCG
// {
// /// <summary>
// /// Stream to internally handle Left Joins. The only difference between this and the left Join is the waty the
// /// DataPacket thats fired is initialized.
// /// </summary>
// [DataStreamUserRespresentation (false)]
// public class LeftInternalJoinStream : InternalJoinStream
// {
// protected DataPacket myLeftDataPacket, myRightDataPacket;
// //Container to contain all the left rows that are orphaned during a deletion operation
// private IDictionary myLeftOrphanedRows;
// public LeftInternalJoinStream (ViewStream vsLeft, string jcLeft, ViewStream vsRight, string jcRight) :
// base (vsLeft, jcLeft, vsRight, jcRight) {}
namespace BCG
{
/// <summary>
/// Stream to internally handle Left Joins. The only difference between this and the left Join is the waty the
/// DataPacket thats fired is initialized.
/// </summary>
[DataStreamUserRespresentation (false)]
public class LeftInternalJoinStream : InternalJoinStream
{
protected DataPacket myLeftDataPacket, myRightDataPacket;
//Container to contain all the left rows that are orphaned during a deletion operation
private IDictionary myLeftOrphanedRows;
public LeftInternalJoinStream (ViewStream vsLeft, string jcLeft, ViewStream vsRight, string jcRight) :
base (vsLeft, jcLeft, vsRight, jcRight) {}
// protected override void myOnFirstSubscriber()
// {
// myLeftOperand.master = this;
// myRightOperand.master = this;
// //the events are not hooked onto the operands delegate, but rather a level of indirection
// //added in the form on myLeftChangeHandler
// myLeftStream.onChange += new DataStream.ChangeDelegate (myLeftChangeHandler);
// myRightStream.onChange += new DataStream.ChangeDelegate (myRightChangeHandler);
// }
protected override void myOnFirstSubscriber()
{
myLeftOperand.master = this;
myRightOperand.master = this;
//the events are not hooked onto the operands delegate, but rather a level of indirection
//added in the form on myLeftChangeHandler
myLeftStream.onChange += new DataStream.ChangeDelegate (myLeftChangeHandler);
myRightStream.onChange += new DataStream.ChangeDelegate (myRightChangeHandler);
}
// protected override void myOnLastSubscriber ()
// {
// myInit ();
// myLeftStream.onChange -= new DataStream.ChangeDelegate (myLeftChangeHandler);
// myRightStream.onChange -= new DataStream.ChangeDelegate (myRightChangeHandler);
// }
protected override void myOnLastSubscriber ()
{
myInit ();
myLeftStream.onChange -= new DataStream.ChangeDelegate (myLeftChangeHandler);
myRightStream.onChange -= new DataStream.ChangeDelegate (myRightChangeHandler);
}
// protected override void myInit()
// {
// base.myInit ();
// myLeftOrphanedRows = null;
// myLeftDataPacket = myRightDataPacket = null;
// }
protected override void myInit()
{
base.myInit ();
myLeftOrphanedRows = null;
myLeftDataPacket = myRightDataPacket = null;
}
// private void myLeftChangeHandler (object o)
// {
// myLeftDataPacket = (DataPacket)o;
// myTestAndFire (true);
// }
private void myLeftChangeHandler (object o)
{
myLeftDataPacket = (DataPacket)o;
myTestAndFire (true);
}
// private void myRightChangeHandler (object o)
// {
// myRightDataPacket = (DataPacket)o;
// myTestAndFire (false);
// }
private void myRightChangeHandler (object o)
{
myRightDataPacket = (DataPacket)o;
myTestAndFire (false);
}
// /// <summary>
// /// enforces the order of firing the events, this is to enforce that first the right operand
// /// has data (possibly 0 rows) before we the join is actually calculated => Performance boost
// /// </summary>
// /// <param name="isLeft"></param>
// private void myTestAndFire (bool isLeft)
// {
// JoinOperand jo = isLeft ? myLeftOperand : myRightOperand;
// DataPacket dp = isLeft ? myLeftDataPacket : myRightDataPacket;
// //to test whether both have received call backs
// if (myLeftOperand.hasReceivedData)
// jo.changeHandler (dp);
// else if (myLeftDataPacket != null && myRightDataPacket != null)
// {
// myRightOperand.changeHandler (myRightDataPacket);
// myLeftOperand.changeHandler (myLeftDataPacket);
// }
// }
/// <summary>
/// enforces the order of firing the events, this is to enforce that first the right operand
/// has data (possibly 0 rows) before we the join is actually calculated => Performance boost
/// </summary>
/// <param name="isLeft"></param>
private void myTestAndFire (bool isLeft)
{
JoinOperand jo = isLeft ? myLeftOperand : myRightOperand;
DataPacket dp = isLeft ? myLeftDataPacket : myRightDataPacket;
//to test whether both have received call backs
if (myLeftOperand.hasReceivedData)
jo.changeHandler (dp);
else if (myLeftDataPacket != null && myRightDataPacket != null)
{
myRightOperand.changeHandler (myRightDataPacket);
myLeftOperand.changeHandler (myLeftDataPacket);
}
}
// /// <summary>
// /// Called by JoinOperand
// /// </summary>
// /// <param name="rows"></param>
// /// <param name="isLeft"></param>
// public override void addRows (IBlueRowCollection rows, bool isLeft)
// {
// foreach (IBlueRow row in rows)
// myAddRow (row, isLeft);
// if (!isLeft)
// foreach (RowNode node in myLeftOrphanedRows.Values)
// ((JoinTable)myLastFiredPacket.newRows).addRow (node.row, null, myLastFiredPacket);
// }
/// <summary>
/// Called by JoinOperand
/// </summary>
/// <param name="rows"></param>
/// <param name="isLeft"></param>
public override void addRows (IBlueRowCollection rows, bool isLeft)
{
foreach (IBlueRow row in rows)
myAddRow (row, isLeft);
if (!isLeft)
foreach (RowNode node in myLeftOrphanedRows.Values)
((JoinTable)myLastFiredPacket.newRows).addRow (node.row, null, myLastFiredPacket);
}
// /// <summary>
// /// called by JoinOperand
// /// </summary>
// /// <param name="rows"></param>
// /// <param name="isLeft"></param>
// public override void deleteRows (IBlueRowCollection rows, bool isLeft)
// {
// myLeftOrphanedRows = new Hashtable ();
// foreach (IBlueRow row in rows)
// myDeleteRow (row, isLeft);
// }
/// <summary>
/// called by JoinOperand
/// </summary>
/// <param name="rows"></param>
/// <param name="isLeft"></param>
public override void deleteRows (IBlueRowCollection rows, bool isLeft)
{
myLeftOrphanedRows = new Hashtable ();
foreach (IBlueRow row in rows)
myDeleteRow (row, isLeft);
}
// private void myAddRow (IBlueRow row, bool isLeft)
// {
// if (isLeft)
// {
// myLeftOperand.addRow (row);
// RowList matchedRows = myRightOperand.getMatchingRows (row[myLeftJoinColOrdinal]);
// if (matchedRows.Count == 0)
// ((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
// else
// foreach (RowNode matchedNode in matchedRows)
// ((JoinTable)myLastFiredPacket.newRows).addRow (row, matchedNode.row, myLastFiredPacket);
// }
// else
// {
// RowList matchedRows = myLeftOperand.getMatchingRows (row[myRightJoinColOrdinal]);
// int rightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
// myRightOperand.addRow (row);
// int newRightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
// if (matchedRows.Count != 0){
// foreach (RowNode matchedNode in matchedRows)
// {
// //if the left rows were orphaned in this transaction (ie in this callback), they should
// //just be removed from the orphanedlist and we dont need to worry about the consistency of
// //the jointable as a new row will replace it
// if (rightMatchingRowCount == 0 && newRightMatchingRowCount > 0)
// {
// if (myLeftOrphanedRows[matchedNode.row["id"]] == null)
// ((JoinTable)myLastFiredPacket.newRows).deleteRow (true, matchedNode.row, myLastFiredPacket);
// else
// myLeftOrphanedRows.Remove (matchedNode.row["id"]);
// }
// //they were orphaned by a previous transaction and hence the orphans need to be
// //removed from the Jointable and the complete row added
// ((JoinTable)myLastFiredPacket.newRows).addRow (matchedNode.row, row, myLastFiredPacket);
private void myAddRow (IBlueRow row, bool isLeft)
{
if (isLeft)
{
myLeftOperand.addRow (row);
RowList matchedRows = myRightOperand.getMatchingRows (row[myLeftJoinColOrdinal]);
if (matchedRows.Count == 0)
((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
else
foreach (RowNode matchedNode in matchedRows)
((JoinTable)myLastFiredPacket.newRows).addRow (row, matchedNode.row, myLastFiredPacket);
}
else
{
RowList matchedRows = myLeftOperand.getMatchingRows (row[myRightJoinColOrdinal]);
int rightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
myRightOperand.addRow (row);
int newRightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
if (matchedRows.Count != 0){
foreach (RowNode matchedNode in matchedRows)
{
//if the left rows were orphaned in this transaction (ie in this callback), they should
//just be removed from the orphanedlist and we dont need to worry about the consistency of
//the jointable as a new row will replace it
if (rightMatchingRowCount == 0 && newRightMatchingRowCount > 0)
{
if (myLeftOrphanedRows[matchedNode.row["id"]] == null)
((JoinTable)myLastFiredPacket.newRows).deleteRow (true, matchedNode.row, myLastFiredPacket);
else
myLeftOrphanedRows.Remove (matchedNode.row["id"]);
}
//they were orphaned by a previous transaction and hence the orphans need to be
//removed from the Jointable and the complete row added
((JoinTable)myLastFiredPacket.newRows).addRow (matchedNode.row, row, myLastFiredPacket);
// }
// }
// }
// }
}
}
}
}
// private void myDeleteRow (IBlueRow row, bool isLeft)
// {
// if (isLeft)
// {
// myLeftOperand.deleteRow (row);
// ((JoinTable)myLastFiredPacket.newRows).deleteRow (true, row, myLastFiredPacket);
// }
// else
// {
// RowList matchedRows = myLeftOperand.getMatchingRows (row[myRightJoinColOrdinal]);
// int rightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
// myRightOperand.deleteRow (row);
// int newRightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
// if (matchedRows.Count != 0)
// {
// if (rightMatchingRowCount > 0 && newRightMatchingRowCount == 0)
// //ie all the matchedRows were joined with 'this' right row (method arg), and hence they need to
// //be handled specially, ie joined with nulls, if there are no right rows with this
// //joincolumn value being inserted.
// foreach (RowNode matchedNode in matchedRows)
// {
// // BlueEventLog.logAssert (myLeftOrphanedRows[matchedNode.row["id"]] == null);
// myLeftOrphanedRows[matchedNode.row["id"]] = matchedNode;
// }
// ((JoinTable)myLastFiredPacket.newRows).deleteRow (false, row, myLastFiredPacket);
// }
// }
// }
private void myDeleteRow (IBlueRow row, bool isLeft)
{
if (isLeft)
{
myLeftOperand.deleteRow (row);
((JoinTable)myLastFiredPacket.newRows).deleteRow (true, row, myLastFiredPacket);
}
else
{
RowList matchedRows = myLeftOperand.getMatchingRows (row[myRightJoinColOrdinal]);
int rightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
myRightOperand.deleteRow (row);
int newRightMatchingRowCount = myRightOperand.getMatchingRows (row[myRightJoinColOrdinal]).Count;
if (matchedRows.Count != 0)
{
if (rightMatchingRowCount > 0 && newRightMatchingRowCount == 0)
//ie all the matchedRows were joined with 'this' right row (method arg), and hence they need to
//be handled specially, ie joined with nulls, if there are no right rows with this
//joincolumn value being inserted.
foreach (RowNode matchedNode in matchedRows)
{
// BlueEventLog.logAssert (myLeftOrphanedRows[matchedNode.row["id"]] == null);
myLeftOrphanedRows[matchedNode.row["id"]] = matchedNode;
}
((JoinTable)myLastFiredPacket.newRows).deleteRow (false, row, myLastFiredPacket);
}
}
}
// public override void onTableClear (bool isLeft)
// {
// myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
// myLastFiredPacket.newRows = new JoinTable (mySchema);
// myLastFiredPacket.addedRows = new BlueTable (mySchema);
// if (!isLeft)
// foreach (IBlueRow row in myLeftDataPacket.newRows)
// ((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
// }
public override void onTableClear (bool isLeft)
{
myLastFiredPacket.deletedRows = myLastFiredPacket.newRows;
myLastFiredPacket.newRows = new JoinTable (mySchema);
myLastFiredPacket.addedRows = new BlueTable (mySchema);
if (!isLeft)
foreach (IBlueRow row in myLeftDataPacket.newRows)
((JoinTable)myLastFiredPacket.newRows).addRow (row, null, myLastFiredPacket);
}
// }
// }
}
}
@@ -1,59 +1,59 @@
// using System;
// using System.Data;
// using System.Collections;
// using System.Text.RegularExpressions;
// using BCG.Utilities;
// using BCG.Utilities.General;
using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using BCG.Utilities;
using BCG.Utilities.General;
// namespace BCG
// {
// public class LeftJoinForeignStream : JoinStream
// {
namespace BCG
{
public class LeftJoinForeignStream : JoinStream
{
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, ColumnMap cm1,
// ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, cm1, v2, joinCol2, cm2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, ColumnMap cm1,
ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, cm1, v2, joinCol2, cm2)
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2, string cmExp2)
// : base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2, string cmExp2)
: base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2)
// :
// this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2)
:
this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1,
// ViewStream v2, string joinCol2, string cmExp2)
// :
// this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1,
ViewStream v2, string joinCol2, string cmExp2)
:
this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, v2, joinCol2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, v2, joinCol2)
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, cm1, v2, joinCol2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, cm1, v2, joinCol2)
{}
// public LeftJoinForeignStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, v2, joinCol2, cm2)
// {}
public LeftJoinForeignStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, v2, joinCol2, cm2)
{}
// protected override InternalJoinStream myConstructInternalJoinStream (
// ViewStream vs1,
// string jc1,
// ViewStream vs2,
// string jc2)
// {
// return new LeftInternalJoinForeignStream (vs1, jc1, vs2, jc2);
// }
// }
// }
protected override InternalJoinStream myConstructInternalJoinStream (
ViewStream vs1,
string jc1,
ViewStream vs2,
string jc2)
{
return new LeftInternalJoinForeignStream (vs1, jc1, vs2, jc2);
}
}
}
@@ -1,58 +1,58 @@
// using System;
// using System.Data;
// using System.Collections;
// using System.Text.RegularExpressions;
// using BCG.Utilities;
// using BCG.Utilities.General;
using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using BCG.Utilities;
using BCG.Utilities.General;
// namespace BCG
// {
// public class LeftJoinStream : JoinStream
// {
// public LeftJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
// ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, cm1, v2, joinCol2, cm2)
// {}
namespace BCG
{
public class LeftJoinStream : JoinStream
{
public LeftJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1,
ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, cm1, v2, joinCol2, cm2)
{}
// public LeftJoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2, string cmExp2)
// : base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
// {}
public LeftJoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2, string cmExp2)
: base (v1, joinCol1, cmExp1, v2, joinCol2, cmExp2)
{}
// public LeftJoinStream (ViewStream v1, string joinCol1, string cmExp1,
// ViewStream v2, string joinCol2)
// :
// this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
// {}
public LeftJoinStream (ViewStream v1, string joinCol1, string cmExp1,
ViewStream v2, string joinCol2)
:
this (v1,joinCol1, new ColumnMap(cmExp1), v2, joinCol2)
{}
// public LeftJoinStream (ViewStream v1, string joinCol1,
// ViewStream v2, string joinCol2, string cmExp2)
// :
// this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
// {}
public LeftJoinStream (ViewStream v1, string joinCol1,
ViewStream v2, string joinCol2, string cmExp2)
:
this (v1,joinCol1, v2, joinCol2, new ColumnMap(cmExp2))
{}
// public LeftJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, v2, joinCol2)
// {}
public LeftJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, v2, joinCol2)
{}
// public LeftJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
// : base (v1, joinCol1, cm1, v2, joinCol2)
// {}
public LeftJoinStream (ViewStream v1, string joinCol1, ColumnMap cm1, ViewStream v2, string joinCol2)
: base (v1, joinCol1, cm1, v2, joinCol2)
{}
// public LeftJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
// : base (v1, joinCol1, v2, joinCol2, cm2)
// {}
public LeftJoinStream (ViewStream v1, string joinCol1, ViewStream v2, string joinCol2, ColumnMap cm2)
: base (v1, joinCol1, v2, joinCol2, cm2)
{}
// protected override InternalJoinStream myConstructInternalJoinStream (
// ViewStream vs1,
// string jc1,
// ViewStream vs2,
// string jc2)
// {
// return new LeftInternalJoinStream (vs1, jc1, vs2, jc2);
// }
// }
// }
protected override InternalJoinStream myConstructInternalJoinStream (
ViewStream vs1,
string jc1,
ViewStream vs2,
string jc2)
{
return new LeftInternalJoinStream (vs1, jc1, vs2, jc2);
}
}
}
@@ -1,68 +1,65 @@
// using System;
// using System.Collections;
// using System.Data;
// using System.Text.RegularExpressions;
// using BCG.Utilities;
// using BCG.Evaluator.ColumnMapExpression;
using System;
using System.Collections;
using System.Data;
using System.Text.RegularExpressions;
using BCG.Utilities;
using Bts.ColumnMapExpressions;
// namespace BCG
// {
// /// <summary>
// /// ColumnMap governs what columns that are to be projected, hidden or aliased
// /// </summary>
// public class ColumnMap
// {
// private string myColMapExpression;
namespace BCG
{
/// <summary>
/// ColumnMap governs what columns that are to be projected, hidden or aliased
/// </summary>
public class ColumnMap
{
private string myColMapExpression;
// /// <summary>
// /// ColumnMap governs what columns that are to be projected, hidden or aliased. If all columns
// /// are to be preserved with their names, ColumnMap("", false) should be passed
// /// </summary>
// /// <param name="excludedList">
// /// Includes the mapping of the columns to their respective aliases as well as the columns that
// /// need to be included/excluded depending on the second parameter. e.g. "a:b c" means to map
// /// a onto b, and include or exclude c depending on the value of the second parameter
// /// </param>
// /// <param name="mapList">
// /// isInclusive decides whether to include the unmapped columns in argument one or to exclude it
// /// from the resulting table
// /// </param>
// public ColumnMap (string colMapExpression)
// {
// myColMapExpression = colMapExpression == null ? "!" : colMapExpression;
// }
/// <summary>
/// ColumnMap governs what columns that are to be projected, hidden or aliased. If all columns
/// are to be preserved with their names, ColumnMap("", false) should be passed
/// </summary>
/// <param name="excludedList">
/// Includes the mapping of the columns to their respective aliases as well as the columns that
/// need to be included/excluded depending on the second parameter. e.g. "a:b c" means to map
/// a onto b, and include or exclude c depending on the value of the second parameter
/// </param>
/// <param name="mapList">
/// isInclusive decides whether to include the unmapped columns in argument one or to exclude it
/// from the resulting table
/// </param>
public ColumnMap (string colMapExpression)
{
myColMapExpression = colMapExpression == null ? "!" : colMapExpression;
}
// public IDictionary getColumnMap (IBlueTableSchema schema)
// {
// IDictionary retVal = new Hashtable ();
// syntax parser =
// new syntax();
// ColumnMapExpression e = (ColumnMapExpression)
// parser.Parse(this.myColMapExpression);
public IDictionary getColumnMap (IBlueTableSchema schema)
{
IDictionary retVal = new Hashtable ();
var e = ColumnMapExpression.Parse(myColMapExpression) ??
throw new Exception($"Failed to parse column expression '{myColMapExpression}'");
// if (e.isInclusive)
// {
// retVal = new Hashtable (e.columns);
// retVal["id"] = "id";
// }
// else
// foreach (ColumnInfo ci in schema.columnInfo)
// if (e.columns[ci.colName] == null)
// retVal[ci.colName] = ci.colName;
// else if ((string)e.columns[ci.colName] != ci.colName)
// retVal[ci.colName] = e.columns[ci.colName];
// return invertDictionary (retVal);
// }
if (e.IsInclusive) {
retVal = new Hashtable(e.Columns) {
["id"] = "id"
};
}
else
foreach (ColumnInfo ci in schema.columnInfo)
if (e.Columns[ci.colName] == null)
retVal[ci.colName] = ci.colName;
else if (e.Columns[ci.colName] != ci.colName)
retVal[ci.colName] = e.Columns[ci.colName];
return invertDictionary (retVal);
}
// public static IDictionary invertDictionary (IDictionary dic)
// {
// IDictionary retVal = new Hashtable ();
// foreach (DictionaryEntry de in dic)
// retVal[de.Value] = de.Key;
// return retVal;
// }
public static IDictionary invertDictionary (IDictionary dic)
{
IDictionary retVal = new Hashtable ();
foreach (DictionaryEntry de in dic)
retVal[de.Value] = de.Key;
return retVal;
}
// public string columnExpression {get{return myColMapExpression;}}
// }
// }
public string columnExpression {get{return myColMapExpression;}}
}
}
@@ -1,118 +1,118 @@
// using System;
// using System.Data;
// using System.Collections;
// using BCG.Utilities;
// using BCG.Utilities.General;
// namespace BCG
// {
// /// <summary>
// /// AppendStream appends 2 tables with each other, with a generated id having no bearing to the original id.
// /// The column ordering the 2 tables need not be the same
// /// </summary>
// public class AppendStream : UnionStream
// {
// private bool myUseNewAppend = DataStreamLoadFileConfig.instance.useNewAppend;
// public AppendStream(ViewStream v1, ViewStream v2)
// {
// if (myUseNewAppend)
// mySetRealSource(new MutableAppendStream(v1, v2));
// else
// {
// myLeftVs = v1;
// myRightVs = v2;
// }
// }
using System;
using System.Data;
using System.Collections;
using BCG.Utilities;
using BCG.Utilities.General;
namespace BCG
{
/// <summary>
/// AppendStream appends 2 tables with each other, with a generated id having no bearing to the original id.
/// The column ordering the 2 tables need not be the same
/// </summary>
public class AppendStream : UnionStream
{
private bool myUseNewAppend = DataStreamLoadFileConfig.instance.useNewAppend;
public AppendStream(ViewStream v1, ViewStream v2)
{
if (myUseNewAppend)
mySetRealSource(new MutableAppendStream(v1, v2));
else
{
myLeftVs = v1;
myRightVs = v2;
}
}
// public AppendStream (params ViewStream[] vss)
// {
public AppendStream (params ViewStream[] vss)
{
// if (myUseNewAppend)
// mySetRealSource(new MutableAppendStream(vss));
// else
// {
// if (vss.Length == 1)
// mySetRealSource(vss[0]);
// else if (vss.Length > 1)
// {
// AppendStream rv = null;
// foreach (ViewStream s in vss)
// rv = rv == null ? new AppendStream(new ViewStream[] { s }) : new AppendStream(rv, s);
// mySetRealSource(rv);
// }
// else
// //don't do anything if they didnt' supply any viewstreams
// mySetRealSource(null);
// }
if (myUseNewAppend)
mySetRealSource(new MutableAppendStream(vss));
else
{
if (vss.Length == 1)
mySetRealSource(vss[0]);
else if (vss.Length > 1)
{
AppendStream rv = null;
foreach (ViewStream s in vss)
rv = rv == null ? new AppendStream(new ViewStream[] { s }) : new AppendStream(rv, s);
mySetRealSource(rv);
}
else
//don't do anything if they didnt' supply any viewstreams
mySetRealSource(null);
}
// }
}
// public override void add (IBlueRowCollection rows, bool isLeft)
// {
// IDictionary index = isLeft ? myLeftIndex : myRightIndex;
// int[] indexToIndexMap = isLeft ? myLeftIndexToIndexMap : myRightIndexToIndexMap;
// foreach (IBlueRow row in rows)
// {
// UnionRow newRow = new UnionRow (myLastFiredPacket.newRows.schema, row,
// myIdCounter ++, myIdIndex, indexToIndexMap);
// ((BlueTable)myLastFiredPacket.newRows).addRow (newRow);
// index[row["id"]] = newRow;
// ((BlueTable)(myLastFiredPacket.addedRows)).addRow (newRow);
// }
// }
public override void add (IBlueRowCollection rows, bool isLeft)
{
IDictionary index = isLeft ? myLeftIndex : myRightIndex;
int[] indexToIndexMap = isLeft ? myLeftIndexToIndexMap : myRightIndexToIndexMap;
foreach (IBlueRow row in rows)
{
UnionRow newRow = new UnionRow (myLastFiredPacket.newRows.schema, row,
myIdCounter ++, myIdIndex, indexToIndexMap);
((BlueTable)myLastFiredPacket.newRows).addRow (newRow);
index[row["id"]] = newRow;
((BlueTable)(myLastFiredPacket.addedRows)).addRow (newRow);
}
}
// public override void delete (IBlueRowCollection rows, bool isLeft)
// {
// IDictionary index = isLeft ? myLeftIndex : myRightIndex;
// foreach (IBlueRow axedRow in rows)
// {
// int rowId = (int)axedRow["id"];
// IBlueRow row = (IBlueRow)index[rowId];
// index.Remove (rowId);
// ((BlueTable)myLastFiredPacket.newRows).deleteRow (row);
// ((BlueTable)(myLastFiredPacket.deletedRows)).addRow (row);
// }
// }
public override void delete (IBlueRowCollection rows, bool isLeft)
{
IDictionary index = isLeft ? myLeftIndex : myRightIndex;
foreach (IBlueRow axedRow in rows)
{
int rowId = (int)axedRow["id"];
IBlueRow row = (IBlueRow)index[rowId];
index.Remove (rowId);
((BlueTable)myLastFiredPacket.newRows).deleteRow (row);
((BlueTable)(myLastFiredPacket.deletedRows)).addRow (row);
}
}
// public override void mergeChanges (IBlueRowCollection dels, IBlueRowCollection adds, bool isLeft)
// {
// IDictionary temp = new Hashtable ();
// IDictionary index = isLeft ? myLeftIndex : myRightIndex;
// int[] indexToIndexMap = isLeft ? myLeftIndexToIndexMap : myRightIndexToIndexMap;
// IBlueRow corrRow;
// foreach (IBlueRow dRow in dels)
// {
// corrRow = index[dRow["id"]] as IBlueRow;
// (myLastFiredPacket.newRows as BlueTable).deleteRow (corrRow);
// (myLastFiredPacket.deletedRows as BlueTable).addRow (corrRow);
// index.Remove (dRow["id"]);
// if (adds.containsID ((int)dRow["id"]))
// {
// IBlueRow r = adds[(int)dRow["id"]];
// corrRow = new UnionRow (myLastFiredPacket.schema, r, (int)corrRow["id"], myIdIndex, indexToIndexMap);
// (myLastFiredPacket.newRows as BlueTable).addRow (corrRow);
// (myLastFiredPacket.addedRows as BlueTable).addRow (corrRow);
// index.Add (r["id"], corrRow);
// temp.Add (r["id"], true);
// }
// }
// foreach (IBlueRow aRow in adds)
// {
// if (!temp.Contains (aRow["id"]))
// {
// corrRow = new UnionRow (myLastFiredPacket.schema, aRow, myIdCounter++, myIdIndex, indexToIndexMap);
// (myLastFiredPacket.newRows as BlueTable).addRow (corrRow);
// (myLastFiredPacket.addedRows as BlueTable).addRow (corrRow);
// index.Add (aRow["id"], corrRow);
// }
// }
// }
// }
public override void mergeChanges (IBlueRowCollection dels, IBlueRowCollection adds, bool isLeft)
{
IDictionary temp = new Hashtable ();
IDictionary index = isLeft ? myLeftIndex : myRightIndex;
int[] indexToIndexMap = isLeft ? myLeftIndexToIndexMap : myRightIndexToIndexMap;
IBlueRow corrRow;
foreach (IBlueRow dRow in dels)
{
corrRow = index[dRow["id"]] as IBlueRow;
(myLastFiredPacket.newRows as BlueTable).deleteRow (corrRow);
(myLastFiredPacket.deletedRows as BlueTable).addRow (corrRow);
index.Remove (dRow["id"]);
if (adds.containsID ((int)dRow["id"]))
{
IBlueRow r = adds[(int)dRow["id"]];
corrRow = new UnionRow (myLastFiredPacket.schema, r, (int)corrRow["id"], myIdIndex, indexToIndexMap);
(myLastFiredPacket.newRows as BlueTable).addRow (corrRow);
(myLastFiredPacket.addedRows as BlueTable).addRow (corrRow);
index.Add (r["id"], corrRow);
temp.Add (r["id"], true);
}
}
foreach (IBlueRow aRow in adds)
{
if (!temp.Contains (aRow["id"]))
{
corrRow = new UnionRow (myLastFiredPacket.schema, aRow, myIdCounter++, myIdIndex, indexToIndexMap);
(myLastFiredPacket.newRows as BlueTable).addRow (corrRow);
(myLastFiredPacket.addedRows as BlueTable).addRow (corrRow);
index.Add (aRow["id"], corrRow);
}
}
}
}
// public class MergeStream : ViewStream
// {
// public MergeStream (ViewStream v1, ViewStream v2, string[] mergeCols)
// {
// mySetRealSource (new DistinctRowStream (new AppendStream (v1, v2), mergeCols));
// }
// }
// }
public class MergeStream : ViewStream
{
public MergeStream (ViewStream v1, ViewStream v2, string[] mergeCols)
{
mySetRealSource (new DistinctRowStream (new AppendStream (v1, v2), mergeCols));
}
}
}
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("DataStream")]
@@ -0,0 +1,12 @@
#nullable enable
namespace BCG;
using Spark.Core.Collections;
using System.Collections.Generic;
public static class BlueRowExtensions {
public static IDictionary<string, object?> AsGenericDictionary(this IBlueRow row) =>
GenericDictionaryWrapper.Create<string, object?>(row);
}
@@ -1,6 +1,8 @@
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace BCG
{
@@ -36,6 +38,11 @@ namespace BCG
myValues[colNo] = newValue;
}
#nullable enable
public IDictionary<string, object?> AsDictionary() =>
new DictionaryWrapper(this);
#nullable disable
private static object[] myCloneArray (IBlueTableSchema schema,object[] vals)
{
object[] retVal = new object[schema.columnNames.Length];
@@ -52,5 +59,69 @@ namespace BCG
return rv;
}
}
class DictionaryWrapper : IDictionary<string, object?> {
readonly MutableBlueRow source;
public DictionaryWrapper(MutableBlueRow source) =>
this.source = source;
public ICollection<string> Keys => source.schema.columnNames;
public ICollection<object> Values => source.myValues;
public int Count => source.Count;
public bool IsReadOnly => false;
public object this[string key] {
get => source[key];
set => source.setValue(key, value);
}
public void Add(string key, object value) =>
source.setValue(key, value);
public void Add(KeyValuePair<string, object> item) =>
source.setValue(item.Key, item.Value);
public void Clear() =>
source.Clear();
public bool Contains(KeyValuePair<string, object> item) =>
source.Contains(item.Key) && Equals(source[item.Key], item.Value);
public bool ContainsKey(string key) =>
source.Contains(key);
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex) {
for (int i = 0; i < source.Count; i++) {
array[arrayIndex++] = new(source.schema.columnNames[i], source.myValues[i]);
}
}
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
throw new NotImplementedException();
}
public bool Remove(string key) {
throw new NotImplementedException();
}
public bool Remove(KeyValuePair<string, object> item) {
throw new NotImplementedException();
}
public bool TryGetValue(string key, [MaybeNullWhen(false)] out object value) {
if (source.Contains(key)) {
value = source[key];
return true;
}
value = default;
return false;
}
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}
}
}