Skip to content

Commit

Permalink
GetDateTimeOffset and fix pageSizeHint for Pageable (#16446)
Browse files Browse the repository at this point in the history
fixes #14002
fixes #13921
  • Loading branch information
christothes authored Oct 29, 2020
1 parent b2dfb08 commit f2d4fb4
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void Clear() { }
public byte[] GetBinary(string key) { throw null; }
public bool? GetBoolean(string key) { throw null; }
public System.DateTime? GetDateTime(string key) { throw null; }
public System.DateTimeOffset? GetDateTimeOffset(string key) { throw null; }
public double? GetDouble(string key) { throw null; }
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> GetEnumerator() { throw null; }
public System.Guid? GetGuid(string key) { throw null; }
Expand Down
146 changes: 78 additions & 68 deletions sdk/tables/Azure.Data.Tables/src/TableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,31 +804,34 @@ public virtual async Task<Response> DeleteAsync(CancellationToken cancellationTo
scope.Start();
try
{
return PageableHelpers.CreateAsyncEnumerable(async _ =>
{
var response = await _tableOperations.QueryEntitiesAsync(
_table,
queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = selectArg },
cancellationToken: cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
}, async (continuationToken, _) =>
{
var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken);

var response = await _tableOperations.QueryEntitiesAsync(
_table,
queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = selectArg },
nextPartitionKey: NextPartitionKey,
nextRowKey: NextRowKey,
cancellationToken: cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
});
return PageableHelpers.CreateAsyncEnumerable(
async pageSizeHint =>
{
var response = await _tableOperations.QueryEntitiesAsync(
_table,
queryOptions: new QueryOptions() { Format = _format, Top = pageSizeHint, Filter = filter, Select = selectArg },
cancellationToken: cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
},
async (continuationToken, pageSizeHint) =>
{
var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken);

var response = await _tableOperations.QueryEntitiesAsync(
_table,
queryOptions: new QueryOptions() { Format = _format, Top = pageSizeHint, Filter = filter, Select = selectArg },
nextPartitionKey: NextPartitionKey,
nextRowKey: NextRowKey,
cancellationToken: cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
},
maxPerPage);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -861,51 +864,58 @@ public virtual async Task<Response> DeleteAsync(CancellationToken cancellationTo
{
string selectArg = select == null ? null : string.Join(",", select);

return PageableHelpers.CreateEnumerable((int? _) =>
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}");
scope.Start();
try
{
var response = _tableOperations.QueryEntities(_table,
queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = selectArg },
cancellationToken: cancellationToken);

return Page.FromValues(
response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
}
catch (Exception ex)
return PageableHelpers.CreateEnumerable(
pageSizeHint =>
{
scope.Failed(ex);
throw;
}
}, (continuationToken, _) =>
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}");
scope.Start();
try
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}");
scope.Start();
try
{
var queryOptions = new QueryOptions() { Format = _format, Top = pageSizeHint, Filter = filter, Select = selectArg };

var response = _tableOperations.QueryEntities(_table,
queryOptions: queryOptions,
cancellationToken: cancellationToken);

return Page.FromValues(
response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
},
(continuationToken, pageSizeHint) =>
{
var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken);

var response = _tableOperations.QueryEntities(
_table,
queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = selectArg },
nextPartitionKey: NextPartitionKey,
nextRowKey: NextRowKey,
cancellationToken: cancellationToken);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
});
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}");
scope.Start();
try
{
var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken);

var queryOptions = new QueryOptions() { Format = _format, Top = pageSizeHint, Filter = filter, Select = selectArg };

var response = _tableOperations.QueryEntities(
_table,
queryOptions: queryOptions,
nextPartitionKey: NextPartitionKey,
nextRowKey: NextRowKey,
cancellationToken: cancellationToken);

return Page.FromValues(response.Value.Value.ToTableEntityList<T>(),
CreateContinuationTokenFromHeaders(response.Headers),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
},
maxPerPage);
}

/// <summary>
Expand Down
24 changes: 17 additions & 7 deletions sdk/tables/Azure.Data.Tables/src/TableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ETag ETag
}

/// <summary>
/// Creates an instance of the <see cref="TableEntity" /> class.
/// Creates an instance of the <see cref="TableEntity" /> class without any properties initialized.
/// </summary>
public TableEntity()
: this(null)
Expand All @@ -84,7 +84,7 @@ public TableEntity(string partitionKey, string rowKey)
}

/// <summary>
/// Initializes a new instance of the <see cref="TableEntity"/> class with properties in the <see cref="IDictionary"/>.
/// Initializes a new instance of the <see cref="TableEntity"/> class with properties specified in <paramref name="values"/>.
/// </summary>
/// <param name="values">A <see cref="IDictionary"/> containing the initial values of the entity.</param>
public TableEntity(IDictionary<string, object> values)
Expand All @@ -96,7 +96,7 @@ public TableEntity(IDictionary<string, object> values)

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="String"/> property called
/// <see cref="string"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
Expand All @@ -116,7 +116,7 @@ public TableEntity(IDictionary<string, object> values)

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="String"/> property called
/// <see cref="string"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
Expand All @@ -136,7 +136,17 @@ public TableEntity(IDictionary<string, object> values)

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="Double"/> property called
/// <see cref="DateTimeOffset"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
/// <returns>The value of the property.</returns>
/// <exception cref="InvalidOperationException">Value associated with given <paramref name="key"/> is not of type <see cref="DateTimeOffset" />.</exception>
public DateTimeOffset? GetDateTimeOffset(string key) => GetValue<DateTimeOffset?>(key);

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="double"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
Expand All @@ -156,7 +166,7 @@ public TableEntity(IDictionary<string, object> values)

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="Int32"/> property called
/// <see cref="int"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
Expand All @@ -166,7 +176,7 @@ public TableEntity(IDictionary<string, object> values)

/// <summary>
/// Get the value of a <see cref="TableEntity"/>'s
/// <see cref="Int64"/> property called
/// <see cref="long"/> property called
/// <paramref name="key"/>.
/// </summary>
/// <param name="key">The name of the property.</param>
Expand Down
102 changes: 54 additions & 48 deletions sdk/tables/Azure.Data.Tables/src/TableServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,24 @@ public virtual AsyncPageable<TableItem> GetTablesAsync(string filter = null, int
scope.Start();
try
{
return PageableHelpers.CreateAsyncEnumerable(async _ =>
{
var response = await _tableOperations.QueryAsync(
null,
new QueryOptions() { Filter = filter, Select = null, Top = maxPerPage, Format = _format },
cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
}, async (nextLink, _) =>
{
var response = await _tableOperations.QueryAsync(
nextTableName: nextLink,
new QueryOptions() { Filter = filter, Select = null, Top = maxPerPage, Format = _format },
cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
});
return PageableHelpers.CreateAsyncEnumerable(
async pageSizeHint =>
{
var response = await _tableOperations.QueryAsync(
null,
new QueryOptions() { Filter = filter, Select = null, Top = pageSizeHint, Format = _format },
cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
},
async (nextLink, pageSizeHint) =>
{
var response = await _tableOperations.QueryAsync(
nextTableName: nextLink,
new QueryOptions() { Filter = filter, Select = null, Top = pageSizeHint, Format = _format },
cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
},
maxPerPage);
}
catch (Exception ex)
{
Expand All @@ -257,41 +260,44 @@ public virtual AsyncPageable<TableItem> GetTablesAsync(string filter = null, int
public virtual Pageable<TableItem> GetTables(string filter = null, int? maxPerPage = null, CancellationToken cancellationToken = default)
{

return PageableHelpers.CreateEnumerable(_ =>
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableServiceClient)}.{nameof(GetTables)}");
scope.Start();
try
{
var response = _tableOperations.Query(
null,
new QueryOptions() { Filter = filter, Select = null, Top = maxPerPage, Format = _format },
cancellationToken);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
}
catch (Exception ex)
return PageableHelpers.CreateEnumerable(
pageSizeHint =>
{
scope.Failed(ex);
throw;
}
}, (nextLink, _) =>
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableServiceClient)}.{nameof(GetTables)}");
scope.Start();
try
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableServiceClient)}.{nameof(GetTables)}");
scope.Start();
try
{
var response = _tableOperations.Query(
null,
new QueryOptions() { Filter = filter, Select = null, Top = pageSizeHint, Format = _format },
cancellationToken);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
},
(nextLink, pageSizeHint) =>
{
var response = _tableOperations.Query(
nextTableName: nextLink,
new QueryOptions() { Filter = filter, Select = null, Top = maxPerPage, Format = _format },
cancellationToken);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
});
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableServiceClient)}.{nameof(GetTables)}");
scope.Start();
try
{
var response = _tableOperations.Query(
nextTableName: nextLink,
new QueryOptions() { Filter = filter, Select = null, Top = pageSizeHint, Format = _format },
cancellationToken);
return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
},
maxPerPage);
}

/// <summary>
Expand Down
Loading

0 comments on commit f2d4fb4

Please sign in to comment.