-
Notifications
You must be signed in to change notification settings - Fork 332
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
Issue 2780 #2785
base: main
Are you sure you want to change the base?
Issue 2780 #2785
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,21 @@ internal class CdpTableResolver : ICdpTableResolver | |
|
||
private readonly HttpClient _httpClient; | ||
|
||
private readonly string _uriPrefix; | ||
[Obsolete] | ||
private readonly string _uriPrefix = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so |
||
|
||
private readonly bool _doubleEncoding; | ||
|
||
public CdpTableResolver(CdpTable tabularTable, HttpClient httpClient, bool doubleEncoding, ConnectorLogger logger = null) | ||
{ | ||
_tabularTable = tabularTable; | ||
_httpClient = httpClient; | ||
_doubleEncoding = doubleEncoding; | ||
|
||
Logger = logger; | ||
} | ||
|
||
[Obsolete] | ||
public CdpTableResolver(CdpTable tabularTable, HttpClient httpClient, string uriPrefix, bool doubleEncoding, ConnectorLogger logger = null) | ||
{ | ||
_tabularTable = tabularTable; | ||
|
@@ -53,7 +64,12 @@ public async Task<ConnectorType> ResolveTableAsync(string tableName, Cancellatio | |
} | ||
|
||
string dataset = _doubleEncoding ? CdpServiceBase.DoubleEncode(_tabularTable.DatasetName) : _tabularTable.DatasetName; | ||
string uri = (_uriPrefix ?? string.Empty) + (UseV2(_uriPrefix) ? "/v2" : string.Empty) + $"/$metadata.json/datasets/{dataset}/tables/{CdpServiceBase.DoubleEncode(tableName)}?api-version=2015-09-01"; | ||
|
||
#pragma warning disable CS0612 // Type or member is obsolete | ||
string prefix = string.IsNullOrEmpty(_uriPrefix) ? string.Empty : (_uriPrefix ?? string.Empty) + (UseV2(_uriPrefix) ? "/v2" : string.Empty); | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
|
||
string uri = $"{prefix}/$metadata.json/datasets/{dataset}/tables/{CdpServiceBase.DoubleEncode(tableName)}?api-version=2015-09-01"; | ||
|
||
string text = await CdpServiceBase.GetObject(_httpClient, $"Get table metadata", uri, null, cancellationToken, Logger).ConfigureAwait(false); | ||
|
||
|
@@ -92,7 +108,10 @@ public async Task<ConnectorType> ResolveTableAsync(string tableName, Cancellatio | |
// sqlRelationships = GetSqlRelationships(text2); | ||
//} | ||
|
||
var parts = _uriPrefix.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); | ||
#pragma warning disable CS0612 // Type or member is obsolete | ||
var parts = string.IsNullOrEmpty(_uriPrefix) ? Array.Empty<string>() : _uriPrefix.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
|
||
string connectorName = (parts.Length > 1) ? parts[1] : string.Empty; | ||
|
||
ConnectorType connectorType = ConnectorFunction.GetCdpTableType(this, connectorName, _tabularTable.TableName, "Schema/Items", FormulaValue.New(text), ConnectorCompatibility.CdpCompatibility, _tabularTable.DatasetName, | ||
|
@@ -103,8 +122,7 @@ public async Task<ConnectorType> ResolveTableAsync(string tableName, Cancellatio | |
return connectorType; | ||
} | ||
|
||
internal static bool IsSql(string uriPrefix) => uriPrefix.Contains("/sql/"); | ||
|
||
[Obsolete] | ||
internal static bool UseV2(string uriPrefix) => uriPrefix.Contains("/sql/") || | ||
uriPrefix.Contains("/zendesk/"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is ultimately used to determine the endpoint, can we remove from here and push higher? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where you'd put it If we want to absorb the breaking change fully we can jsut delete all these [Obsolete] things |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,13 @@ public CdpDataSource(string dataset) | |
DatasetName = dataset ?? throw new ArgumentNullException(nameof(dataset)); | ||
} | ||
|
||
public static async Task<DatasetMetadata> GetDatasetsMetadataAsync(HttpClient httpClient, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
string uri = $"/$metadata.json/datasets"; | ||
return await GetObject<DatasetMetadata>(httpClient, "Get datasets metadata", uri, null, cancellationToken, logger).ConfigureAwait(false); | ||
} | ||
|
||
[Obsolete("Use GetDatasetsMetadataAsync without urlPrefix")] | ||
public static async Task<DatasetMetadata> GetDatasetsMetadataAsync(HttpClient httpClient, string uriPrefix, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
string uri = (uriPrefix ?? string.Empty) | ||
|
@@ -32,6 +39,21 @@ public static async Task<DatasetMetadata> GetDatasetsMetadataAsync(HttpClient ht | |
return await GetObject<DatasetMetadata>(httpClient, "Get datasets metadata", uri, null, cancellationToken, logger).ConfigureAwait(false); | ||
} | ||
|
||
public virtual async Task<IEnumerable<CdpTable>> GetTablesAsync(HttpClient httpClient, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
if (DatasetMetadata == null) | ||
{ | ||
DatasetMetadata = await GetDatasetsMetadataAsync(httpClient, cancellationToken, logger).ConfigureAwait(false); | ||
} | ||
|
||
string queryName = httpClient is PowerPlatformConnectorClient ppcc && ppcc.RequestUrlPrefix.Contains("/sharepointonline/") ? "/alltables" : "/tables"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue description in #2780 suggested dealing with this case by looking at HttpClient.BaseAddress - would that work? It would let us avoid the type cast. nit- either way - can you encapsulate this in a tiny helper method IsSharepoint(httpClient)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not in the HttpClient base address unfortunately |
||
string uri = $"/datasets/{(DatasetMetadata.IsDoubleEncoding ? DoubleEncode(DatasetName) : DatasetName)}" + queryName; | ||
|
||
GetTables tables = await GetObject<GetTables>(httpClient, "Get tables", uri, null, cancellationToken, logger).ConfigureAwait(false); | ||
return tables?.Value?.Select((RawTable rawTable) => new CdpTable(DatasetName, rawTable.Name, DatasetMetadata, tables?.Value) { DisplayName = rawTable.DisplayName }); | ||
} | ||
|
||
[Obsolete("Use GetTablesAsync without urlPrefix")] | ||
public virtual async Task<IEnumerable<CdpTable>> GetTablesAsync(HttpClient httpClient, string uriPrefix, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
if (DatasetMetadata == null) | ||
|
@@ -50,6 +72,36 @@ public virtual async Task<IEnumerable<CdpTable>> GetTablesAsync(HttpClient httpC | |
return tables?.Value?.Select((RawTable rawTable) => new CdpTable(DatasetName, rawTable.Name, DatasetMetadata, tables?.Value) { DisplayName = rawTable.DisplayName }); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a single CdpTable. | ||
/// </summary> | ||
/// <param name="httpClient">HttpClient.</param> | ||
/// <param name="tableName">Table name to search.</param> | ||
/// <param name="logicalOrDisplay">bool? value: true = logical only, false = display name only, null = logical or display name. All comparisons are case sensitive.</param> | ||
/// <param name="cancellationToken">Cancellation token.</param> | ||
/// <param name="logger">Logger.</param> | ||
/// <returns>CdpTable class.</returns> | ||
/// <exception cref="InvalidOperationException">When no or more than one tables are identified.</exception> | ||
public virtual async Task<CdpTable> GetTableAsync(HttpClient httpClient, string tableName, bool? logicalOrDisplay, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
IEnumerable<CdpTable> tables = await GetTablesAsync(httpClient, cancellationToken, logger).ConfigureAwait(false); | ||
IEnumerable<CdpTable> filtered = tables.Where(ct => IsNameMatching(ct.TableName, ct.DisplayName, tableName, logicalOrDisplay)); | ||
|
||
if (!filtered.Any()) | ||
{ | ||
throw new InvalidOperationException("Cannot find any table with the specified name"); | ||
} | ||
|
||
if (filtered.Count() > 1) | ||
{ | ||
throw new InvalidOperationException($"Too many tables correspond to the specified name - Found {filtered.Count()} tables"); | ||
} | ||
|
||
return filtered.First(); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a single CdpTable. | ||
/// </summary> | ||
|
@@ -61,11 +113,12 @@ public virtual async Task<IEnumerable<CdpTable>> GetTablesAsync(HttpClient httpC | |
/// <param name="logger">Logger.</param> | ||
/// <returns>CdpTable class.</returns> | ||
/// <exception cref="InvalidOperationException">When no or more than one tables are identified.</exception> | ||
[Obsolete("Use GetTableAsync without urlPrefix")] | ||
public virtual async Task<CdpTable> GetTableAsync(HttpClient httpClient, string uriPrefix, string tableName, bool? logicalOrDisplay, CancellationToken cancellationToken, ConnectorLogger logger = null) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
IEnumerable<CdpTable> tables = await GetTablesAsync(httpClient, uriPrefix, cancellationToken, logger).ConfigureAwait(false); | ||
|
||
IEnumerable<CdpTable> tables = await GetTablesAsync(httpClient, uriPrefix, cancellationToken, logger).ConfigureAwait(false); | ||
IEnumerable<CdpTable> filtered = tables.Where(ct => IsNameMatching(ct.TableName, ct.DisplayName, tableName, logicalOrDisplay)); | ||
|
||
if (!filtered.Any()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider making this an Init property, and then we don't need the extra ctors. #Resolved