Skip to content

Commit

Permalink
Check for consistent sort order from CatchSource
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Jan 6, 2022
1 parent d9ecc51 commit 48525b5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlan/TryCatchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,18 @@ protected override IEnumerable<Entity> ExecuteInternal(IDictionary<string, DataS

public override INodeSchema GetSchema(IDictionary<string, DataSource> dataSources, IDictionary<string, Type> parameterTypes)
{
return TrySource.GetSchema(dataSources, parameterTypes);
var trySchema = TrySource.GetSchema(dataSources, parameterTypes);
var catchSchema = CatchSource.GetSchema(dataSources, parameterTypes);

// Columns should be the same but sort order may be different
if (trySchema.SortOrder.SequenceEqual(catchSchema.SortOrder, StringComparer.OrdinalIgnoreCase))
return trySchema;

var consistentSorts = trySchema.SortOrder
.TakeWhile((sort, index) => index < catchSchema.SortOrder.Count && sort.Equals(catchSchema.SortOrder[index], StringComparison.OrdinalIgnoreCase))
.ToList();

return new NodeSchema(trySchema) { SortOrder = consistentSorts };
}

public override IEnumerable<IExecutionPlanNode> GetSources()
Expand Down

0 comments on commit 48525b5

Please sign in to comment.