Skip to content

Commit

Permalink
Handle "Aggregates are not supported" error from audit table
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Jul 13, 2021
1 parent 4b549de commit 2a6aad5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/HashMatchAggregateNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ Source is FetchXmlScan fetch &&
{
TrySource = fetchXml,
CatchSource = this,
ExceptionFilter = IsAggregateQueryRecordLimitExceededException
ExceptionFilter = IsAggregateQueryRetryableException
};
}

Expand All @@ -528,20 +528,31 @@ public override void AddRequiredColumns(IAttributeMetadataCache metadata, IDicti
Source.AddRequiredColumns(metadata, parameterTypes, scalarRequiredColumns);
}

private bool IsAggregateQueryRecordLimitExceededException(Exception ex)
private bool IsAggregateQueryRetryableException(Exception ex)
{
if (ex is QueryExecutionException qee)
ex = qee.InnerException;

if (!(ex is FaultException<OrganizationServiceFault> fault))
if (!(ex is FaultException<OrganizationServiceFault> faultEx))
return false;

var fault = faultEx.Detail;
while (fault.InnerFault != null)
fault = fault.InnerFault;

/*
* 0x8004E023 / -2147164125
* Name: AggregateQueryRecordLimitExceeded
* Message: The maximum record limit is exceeded. Reduce the number of records.
*/
return fault.Detail.ErrorCode == -2147164125;
if (fault.ErrorCode == -2147164125)
return true;

// Triggered when trying to use aggregates on log storage tables
if (fault.ErrorCode == -2147220970 && fault.Message == "Aggregates are not supported")
return true;

return false;
}

public override int EstimateRowsOut(IAttributeMetadataCache metadata, IDictionary<string, Type> parameterTypes, ITableSizeCache tableSize)
Expand Down

0 comments on commit 2a6aad5

Please sign in to comment.