Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FullOuterJoinedSource.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
6
8{
13 {
22 : base(Left, Right, Conditions)
23 {
24 }
25
37 public override async Task<IResultSetEnumerator> Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables,
38 KeyValuePair<VariableReference, bool>[] Order, ScriptNode Node)
39 {
40 ScriptNode LeftWhere = await Reduce(this.Left, Where);
41 KeyValuePair<VariableReference, bool>[] LeftOrder = await Reduce(this.Left, Order);
42
43 IResultSetEnumerator LeftEnum = await this.Left.Find(0, int.MaxValue, Generic, LeftWhere, Variables, LeftOrder, Node);
44
45 ScriptNode RightWhere = await Reduce(this.Right, this.Left, Where);
46
47 LeftEnum = new LeftOuterJoinedSource.LeftOuterJoinEnumerator(LeftEnum, this.Left.Name, this.Right, this.Right.Name, Generic,
48 this.Combine(RightWhere, this.Conditions), Variables, false);
49
50 ScriptNode RightWhere2 = await Reduce(this.Right, Where);
51 KeyValuePair<VariableReference, bool>[] RightOrder2 = await Reduce(this.Right, Order);
52
53 IResultSetEnumerator RightEnum = await this.Right.Find(0, int.MaxValue, Generic, RightWhere2, Variables, RightOrder2, Node);
54
55 ScriptNode LeftWhere2 = await Reduce(this.Left, this.Right, Where);
56
57 RightEnum = new LeftOuterJoinedSource.LeftOuterJoinEnumerator(RightEnum, this.Right.Name, this.Left, this.Left.Name, Generic,
58 this.Combine(LeftWhere2, this.Conditions), Variables, true);
59
60 IResultSetEnumerator e = new FullOuterJoinEnumerator(LeftEnum, RightEnum);
61
62 if (!(Where is null))
63 e = new ConditionalEnumerator(e, Variables, Where);
64
65 if (Offset > 0)
66 e = new OffsetEnumerator(e, Offset);
67
68 if (Top != int.MaxValue)
69 e = new MaxCountEnumerator(e, Top);
70
71 return e;
72 }
73
74 private class FullOuterJoinEnumerator : IResultSetEnumerator
75 {
76 private readonly Dictionary<object, bool> reportedLeft = new Dictionary<object, bool>();
77 private readonly IResultSetEnumerator leftEnum;
78 private readonly IResultSetEnumerator rightEnum;
79 private object current;
80 private bool leftMode;
81
82 public FullOuterJoinEnumerator(IResultSetEnumerator Left, IResultSetEnumerator Right)
83 {
84 this.leftEnum = Left;
85 this.rightEnum = Right;
86 this.leftMode = true;
87 this.current = null;
88 }
89
90 public object Current => this.current;
91
92 public bool MoveNext()
93 {
94 return this.MoveNextAsync().Result;
95 }
96
97 public async Task<bool> MoveNextAsync()
98 {
99 if (this.leftMode)
100 {
101 if (await this.leftEnum.MoveNextAsync())
102 {
103 this.current = this.leftEnum.Current;
104 this.reportedLeft[this.current] = true;
105 return true;
106 }
107 else
108 this.leftMode = false;
109 }
110
111 do
112 {
113 if (await this.rightEnum.MoveNextAsync())
114 this.current = this.rightEnum.Current;
115 else
116 return false;
117 }
118 while (this.reportedLeft.ContainsKey(this.current));
119
120 return true;
121 }
122
123 public void Reset()
124 {
125 this.reportedLeft.Clear();
126 this.current = null;
127 this.leftMode = true;
128 this.leftEnum.Reset();
129 this.rightEnum.Reset();
130 }
131 }
132
133 }
134}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that only returns elements matching a set of conditions.
Enumerator that limits the return set to a maximum number of records.
Enumerator that skips a given number of result records.
Data source formed through an (FULL [OUTER]|OUTER) JOIN of two sources.
override async Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
FullOuterJoinedSource(IDataSource Left, IDataSource Right, ScriptNode Conditions)
Data source formed through an (FULL [OUTER]|OUTER) JOIN of two sources.
Abstract base classes of joined sources.
Definition: JoinedSource.cs:14
ScriptNode Conditions
Conditions for join.
Definition: JoinedSource.cs:45
static async Task< ScriptNode > Reduce(IDataSource Source, ScriptNode Where)
Reduces a where clause to fit the current data source.
Data source formed through an LEFT [OUTER] JOIN of two sources.
Collection of variables.
Definition: Variables.cs:25
Interface for data sources that can be used in SQL statements.
Definition: IDataSource.cs:13
Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
string Name
Collection name or alias.
Definition: IDataSource.cs:76