Skip to content

Support ScannedCount on DynamoDb Document Model #3751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions generator/.DevConfigs/778f8bc5-440c-4d7f-8f02-2224fbc2649d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "DynamoDBv2",
"type": "patch",
"changeLogMessages": [
"Exposed ScannedCount property on the Search class within the Document Model."
]
}
]
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,18 @@
<#
else
{
if(this.Project.AssemblyName == "AWSSDK.UnitTests.DynamoDBv2.NetFramework")
{
#>
<AssemblyOriginatorKeyFile>../../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
<#
}
else
{
#>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
<#
}
}
#>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,24 @@ public override string TransformText()

#line default
#line hidden
this.Write(@""")]
#else
#error Unknown platform constant - unable to set correct AssemblyDescription
#endif

[assembly: AssemblyConfiguration("""")]
this.Write("\")]\r\n#else\r\n#error Unknown platform constant - unable to set correct AssemblyDesc" +
"ription\r\n#endif\r\n\r\n");

#line 25 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
if (this.Config.AssemblyTitle=="AWSSDK.DynamoDBv2") {

#line default
#line hidden
this.Write(@"[assembly: InternalsVisibleTo(""AWSSDK.UnitTests.DynamoDBv2.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"")]
[assembly: InternalsVisibleTo(""AWSSDK.UnitTests.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"")]
");

#line 28 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
}

#line default
#line hidden
this.Write(@"[assembly: AssemblyConfiguration("""")]
[assembly: AssemblyProduct(""Amazon Web Services SDK for .NET"")]
[assembly: AssemblyCompany(""Amazon.com, Inc"")]
[assembly: AssemblyCopyright(""Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved."")]
Expand All @@ -98,14 +110,14 @@ public override string TransformText()
// [assembly: AssemblyVersion(""1.0.*"")]
[assembly: AssemblyVersion(""");

#line 47 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
#line 51 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(this.Config.ServiceVersion));

#line default
#line hidden
this.Write("\")]\r\n[assembly: AssemblyFileVersion(\"");

#line 48 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
#line 52 "C:\codebase\v4\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\AssemblyInfo.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(this.Config.ServiceFileVersion));

#line default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ using System.Runtime.CompilerServices;
#error Unknown platform constant - unable to set correct AssemblyDescription
#endif

<# if (this.Config.AssemblyTitle=="AWSSDK.DynamoDBv2") { #>
[assembly: InternalsVisibleTo("AWSSDK.UnitTests.DynamoDBv2.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4")]
[assembly: InternalsVisibleTo("AWSSDK.UnitTests.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4")]
<# } #>
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("Amazon Web Services SDK for .NET")]
[assembly: AssemblyCompany("Amazon.com, Inc")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void Execute(string unitTestRoot, IEnumerable<ServiceConfiguration> servi
}
projectProperties.FxcopAnalyzerRuleSetFilePath = Utils.PathCombineAlt("..", "..", "..", "..", "AWSDotNetSDK.ruleset");
projectProperties.FxcopAnalyzerRuleSetFilePathForBuild = Utils.PathCombineAlt("..", "..", "..", "..", "AWSDotNetSDKForBuild.ruleset");
projectProperties.SignBinaries = true;

}

if (serviceProjectReferences != null)
Expand Down
41 changes: 40 additions & 1 deletion sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ public partial interface ISearch
/// </summary>
int Count { get; }

/// <summary>
/// Gets the total number of items evaluated, before any ScanFilter is applied, for the current call.
/// <para>
/// The number of items evaluated, before any <c>ScanFilter</c> is applied. A high <c>ScannedCount</c>
/// value with few, or no, <c>Count</c> results indicates an inefficient <c>Scan</c> operation.
/// For more information, see <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Count">Count
/// and ScannedCount</a> in the <i>Amazon DynamoDB Developer Guide</i>.
/// </para>
/// <para>
/// This value is specific to each call of <c>GetNextSetAsync</c> or <c>GetRemainingAsync</c>.
/// It is not an accumulated value across multiple calls.
/// </para>
/// <para>
/// If you did not use a filter in the request, then <c>ScannedCount</c> is the same as
/// <c>Count</c>.
/// </para>
/// </summary>
int ScannedCount { get; }

/// <summary>
/// Name of the index to query or scan against.
/// </summary>
Expand Down Expand Up @@ -258,7 +277,10 @@ internal set
public int Segment { get; set; }

/// <inheritdoc/>
public int Count { get { return GetCount(); } }
public int Count => GetCount();

/// <inheritdoc/>
public int ScannedCount => scannedCount;

/// <inheritdoc/>
public string IndexName { get; internal set; }
Expand Down Expand Up @@ -345,6 +367,7 @@ internal List<Document> GetNextSetHelper()
}

NextKey = scanResult.LastEvaluatedKey;
scannedCount = scanResult.ScannedCount.GetValueOrDefault();
if (NextKey == null || NextKey.Count == 0)
{
IsDone = true;
Expand Down Expand Up @@ -399,6 +422,7 @@ internal List<Document> GetNextSetHelper()
}

NextKey = queryResult.LastEvaluatedKey;
scannedCount = queryResult.ScannedCount.GetValueOrDefault();
if (NextKey == null || NextKey.Count == 0)
{
IsDone = true;
Expand Down Expand Up @@ -467,6 +491,8 @@ internal async Task<List<Document>> GetNextSetHelperAsync(CancellationToken canc
}

NextKey = scanResult.LastEvaluatedKey;
scannedCount = scanResult.ScannedCount.GetValueOrDefault();

if (NextKey == null || NextKey.Count == 0)
{
IsDone = true;
Expand Down Expand Up @@ -512,6 +538,8 @@ internal async Task<List<Document>> GetNextSetHelperAsync(CancellationToken canc
}
}
NextKey = queryResult.LastEvaluatedKey;
scannedCount = queryResult.ScannedCount.GetValueOrDefault();

if (NextKey == null || NextKey.Count == 0)
{
IsDone = true;
Expand All @@ -532,10 +560,12 @@ internal List<Document> GetRemainingHelper()

while (!IsDone)
{
var previousScannedCount = scannedCount;
foreach (Document doc in GetNextSetHelper())
{
ret.Add(doc);
}
scannedCount += previousScannedCount;
}

return ret;
Expand All @@ -548,10 +578,12 @@ internal async Task<List<Document>> GetRemainingHelperAsync(CancellationToken ca

while (!IsDone)
{
var previousScannedCount = scannedCount;
foreach (Document doc in await GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false))
{
ret.Add(doc);
}
scannedCount += previousScannedCount;
}

return ret;
Expand All @@ -560,6 +592,8 @@ internal async Task<List<Document>> GetRemainingHelperAsync(CancellationToken ca

private int count;

private int scannedCount;

private SearchType SearchMethod { get; set; }

internal Table SourceTable { get; set; }
Expand Down Expand Up @@ -668,6 +702,8 @@ private int GetCount()

var scanResult = internalClient.Scan(scanReq);
count = Matches.Count + scanResult.Count.GetValueOrDefault();
scannedCount = scanResult.ScannedCount.GetValueOrDefault();

return count;
case SearchType.Query:
QueryRequest queryReq = new QueryRequest
Expand All @@ -693,6 +729,8 @@ private int GetCount()

var queryResult = internalClient.Query(queryReq);
count = Matches.Count + queryResult.Count.GetValueOrDefault();
scannedCount = queryResult.ScannedCount.GetValueOrDefault();

return count;
default:
throw new InvalidOperationException("Unknown Search Method");
Expand All @@ -707,6 +745,7 @@ private int GetCount()
internal void Reset()
{
count = -1;
scannedCount = 0;
IsDone = false;
NextKey = null;
Matches = new List<Document>();
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/Services/DynamoDBv2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#error Unknown platform constant - unable to set correct AssemblyDescription
#endif

[assembly: InternalsVisibleTo("AWSSDK.UnitTests.DynamoDBv2.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4")]
[assembly: InternalsVisibleTo("AWSSDK.UnitTests.NetFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("Amazon Web Services SDK for .NET")]
[assembly: AssemblyCompany("Amazon.com, Inc")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Choose>
<When Condition=" '$(AWSKeyFile)' == '' ">
<PropertyGroup>
<AssemblyOriginatorKeyFile>../../../awssdk.dll.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Compile Remove="**/obj/**"/>
<None Remove="**/obj/**" />
Expand Down
Loading