-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
441 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
MarkMpn.Sql4Cds.Engine/ExecutionPlan/IControlOfFlowNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.SqlServer.TransactSql.ScriptDom; | ||
|
||
namespace MarkMpn.Sql4Cds.Engine.ExecutionPlan | ||
{ | ||
/// <summary> | ||
/// Describes a node which moves execution to another node | ||
/// </summary> | ||
interface IControlOfFlowNode : IRootExecutionPlanNodeInternal | ||
{ | ||
/// <summary> | ||
/// Checks which nodes should be executed next | ||
/// </summary> | ||
/// <param name="dataSources">The data sources that can be accessed by the query</param> | ||
/// <param name="options">The options which describe how the query should be executed</param> | ||
/// <param name="parameterTypes">The types of any parameters available to the query</param> | ||
/// <param name="parameterValues">The values of any parameters available to the query</param> | ||
/// <param name="rerun">Indicates if this node should be executed again before moving on to the next statement in the batch</param> | ||
/// <returns>The nodes which should be executed next. If <c>null</c>, the entire node is finished and control should move on to the next statement in the batch</returns> | ||
IRootExecutionPlanNodeInternal[] Execute(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IDictionary<string, object> parameterValues, out bool rerun); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.SqlServer.TransactSql.ScriptDom; | ||
|
||
namespace MarkMpn.Sql4Cds.Engine.ExecutionPlan | ||
{ | ||
class IfNode : BaseNode, IControlOfFlowNode | ||
{ | ||
private int _executionCount; | ||
private readonly Timer _timer = new Timer(); | ||
|
||
public override int ExecutionCount => _executionCount; | ||
|
||
public override TimeSpan Duration => _timer.Duration; | ||
|
||
[Browsable(false)] | ||
public string Sql { get; set; } | ||
|
||
[Browsable(false)] | ||
public int Index { get; set; } | ||
|
||
[Browsable(false)] | ||
public int Length { get; set; } | ||
|
||
[Category("If")] | ||
[Description("The condition that must be true for execution to continue")] | ||
public BooleanExpression Condition { get; set; } | ||
|
||
[Browsable(false)] | ||
public IRootExecutionPlanNodeInternal[] TrueStatements { get; set; } | ||
|
||
[Browsable(false)] | ||
public IRootExecutionPlanNodeInternal[] FalseStatements { get; set; } | ||
|
||
public override void AddRequiredColumns(IDictionary<string, DataSource> dataSources, IDictionary<string, DataTypeReference> parameterTypes, IList<string> requiredColumns) | ||
{ | ||
foreach (var node in TrueStatements) | ||
node.AddRequiredColumns(dataSources, parameterTypes, new List<string>(requiredColumns)); | ||
|
||
if (FalseStatements != null) | ||
{ | ||
foreach (var node in FalseStatements) | ||
node.AddRequiredColumns(dataSources, parameterTypes, new List<string>(requiredColumns)); | ||
} | ||
} | ||
|
||
public IRootExecutionPlanNodeInternal[] Execute(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IDictionary<string, object> parameterValues, out bool rerun) | ||
{ | ||
rerun = false; | ||
var expr = Condition.Compile(null, parameterTypes); | ||
|
||
if (expr(null, parameterValues, options)) | ||
return TrueStatements; | ||
else | ||
return FalseStatements; | ||
} | ||
|
||
public IRootExecutionPlanNodeInternal FoldQuery(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IList<OptimizerHint> hints) | ||
{ | ||
for (var i = 0; i < TrueStatements.Length; i++) | ||
TrueStatements[i] = TrueStatements[i].FoldQuery(dataSources, options, parameterTypes, hints); | ||
|
||
if (FalseStatements != null) | ||
{ | ||
for (var i = 0; i < FalseStatements.Length; i++) | ||
FalseStatements[i] = FalseStatements[i].FoldQuery(dataSources, options, parameterTypes, hints); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public override IEnumerable<IExecutionPlanNode> GetSources() | ||
{ | ||
if (FalseStatements == null) | ||
return TrueStatements; | ||
|
||
return TrueStatements.Concat(FalseStatements); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.