Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.PowerFx.Core.Functions.Delegation;

namespace Microsoft.PowerFx.Connectors
{
Expand All @@ -27,5 +30,15 @@ public static IOpenApiExtension ToIOpenApiExtension(this JsonElement je)
_ => throw new NotImplementedException()
};
}

public static IEnumerable<string> ToStr(this IEnumerable<DelegationOperator> ops)
{
if (ops == null)
{
return null;
}

return ops.Select(op => op.ToString().ToLowerInvariant());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using Microsoft.PowerFx.Core.Functions.Delegation;

namespace Microsoft.PowerFx.Connectors
{
public class CapabilitiesPoco
{
[JsonPropertyName("sortRestrictions")]
public Sort SortRestrictions { get; set; }

[JsonPropertyName("filterRestrictions")]
public Filter FilterRestrictions { get; set; }

[JsonPropertyName("isOnlyServerPagable")]
public bool IsOnlyServerPagable { get; set; }

// "top", "skiptoken"
[JsonPropertyName("serverPagingOptions")]
public string[] ServerPagingOptions { get; set; }

// and,or,eq, etc...
// DelegationOperator
[JsonPropertyName("filterFunctionSupport")]
public string[] FilterFunctionSupport { get; set; }

public CapabilitiesPoco SetOps(IEnumerable<DelegationOperator> ops)
{
this.FilterFunctionSupport = ops.ToStr().ToArray();
return this;
}

public IEnumerable<DelegationOperator> FilterFunctionSupportOps() => Utilities.ToDelegationOp(FilterFunctionSupport);

// 3
[JsonPropertyName("odataVersion")]
public int OdataVersion { get; set; }
}

public class Filter
{
[JsonPropertyName("filterable")]
public bool Filterable { get; set; }

[JsonPropertyName("nonFilterableProperties")]
public string[] NonFilterableProperties { get; set; }
}

public class Sort
{
[JsonPropertyName("sortable")]
public bool Sortable { get; set; }

[JsonPropertyName("unsortableProperties")]
public string[] UnsortableProperties { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using Microsoft.PowerFx.Core.Functions.Delegation;

namespace Microsoft.PowerFx.Connectors
{
public class ColumnCapabilitiesPoco
{
[JsonPropertyName("filterFunctions")]
public string[] FilterFunctions { get; set; }

// Strong-typing
public IEnumerable<DelegationOperator> FilterFunctionOps() =>
Utilities.ToDelegationOp(FilterFunctions);

public static ColumnCapabilitiesPoco New(IEnumerable<DelegationOperator> ops)
{
return new ColumnCapabilitiesPoco
{
FilterFunctions = ops.ToStr().ToArray()
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerFx.Connectors
{
public class GetTablePoco
{
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("x-ms-permission")]
public string Permissions { get; set; } // read-write

// $$$ Fill in rest of stuff here...
[JsonPropertyName("x-ms-capabilities")]
public CapabilitiesPoco Capabilities { get; set; }

[JsonPropertyName("schema")]
public TableSchemaPoco Schema { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerFx.Connectors
{
public class TableSchemaPoco
{
[JsonPropertyName("type")]
public string Type { get; set; } = "array";

[JsonPropertyName("items")]
public ItemsPoco Items { get; set; }
}

public class ItemsPoco
{
[JsonPropertyName("type")]
public string Type { get; set; } = "object";

// need required flag.
[JsonPropertyName("properties")]
public Dictionary<string, ColumnInfoPoco> Properties { get; set; }
}

public class ColumnInfoPoco
{
[JsonPropertyName("title")]
public string Title { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("type")]
public string Type { get; set; } // $$$ "integer", "string",

// What sorting capabilities?
// "asc,desc"
[JsonPropertyName("x-ms-sort")]
public string Sort { get; set; }

// What filter capabilities?
[JsonPropertyName("x-ms-capabilities")]
public ColumnCapabilitiesPoco Capabilities { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,14 @@ internal ConnectorType(JsonElement schema, string tableName, SymbolTable optionS
DisplayName = displayName;
FieldMetadata = fieldMetadata;

foreach (ConnectorType field in Fields.Where(f => f.Capabilities != null))
if (serviceCapabilities != null)
{
serviceCapabilities.AddColumnCapability(field.Name, field.Capabilities);
foreach (ConnectorType field in Fields.Where(f => f.Capabilities != null))
{
serviceCapabilities.AddColumnCapability(field.Name, field.Capabilities);
}
}

FormulaType = new CdpRecordType(this, resolver, ServiceCapabilities.ToDelegationInfo(serviceCapabilities, name, isTableReadOnly, this, datasetName), FieldMetadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public async Task<ConnectorType> ResolveTableAsync(string logicalName, Cancellat
}

string dataset = _doubleEncoding ? CdpServiceBase.DoubleEncode(_tabularTable.DatasetName) : CdpServiceBase.SingleEncode(_tabularTable.DatasetName);

// URI to fetch table metadata.
string uri = (_uriPrefix ?? string.Empty) + (UseV2(_uriPrefix) ? "/v2" : string.Empty) + $"/$metadata.json/datasets/{dataset}/tables/{CdpServiceBase.DoubleEncode(logicalName)}?api-version=2015-09-01";

// $$$ we need to return POCO
string text = await CdpServiceBase.GetObject(_httpClient, $"Get table metadata", uri, null, cancellationToken, Logger).ConfigureAwait(false);

if (string.IsNullOrWhiteSpace(text))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ protected internal static async Task<T> GetObject<T>(HttpClient httpClient, stri

string result = await GetObject(httpClient, message, uri, content, cancellationToken, logger, $"{callingMethod}<{typeof(T).Name}>").ConfigureAwait(false);
T res = string.IsNullOrWhiteSpace(result) ? null : JsonSerializer.Deserialize<T>(result);

if (res is ISupportsPostProcessing postProcessing)
{
postProcessing.PostProcess();
}

return res;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CdpTable : CdpService

internal ConnectorType TabularTableDescriptor;

internal IReadOnlyCollection<RawTable> Tables;
internal IEnumerable<RawTable> Tables;

private string _uriPrefix;

Expand All @@ -56,7 +56,7 @@ public class CdpTable : CdpService

public override ConnectorSettings ConnectorSettings => _connectorSettings;

internal CdpTable(string dataset, string table, IReadOnlyCollection<RawTable> tables, ConnectorSettings connectorSettings, CDPMetadataItem fieldMetadata = null)
internal CdpTable(string dataset, string table, IEnumerable<RawTable> tables, ConnectorSettings connectorSettings, CDPMetadataItem fieldMetadata = null)
{
DatasetName = dataset ?? throw new ArgumentNullException(nameof(dataset));
TableName = table ?? throw new ArgumentNullException(nameof(table));
Expand All @@ -65,7 +65,7 @@ internal CdpTable(string dataset, string table, IReadOnlyCollection<RawTable> ta
_fieldMetadata = fieldMetadata;
}

internal CdpTable(string dataset, string table, DatasetMetadata datasetMetadata, IReadOnlyCollection<RawTable> tables, ConnectorSettings connectorSettings, CDPMetadataItem fieldMetadata)
internal CdpTable(string dataset, string table, DatasetMetadata datasetMetadata, IEnumerable<RawTable> tables, ConnectorSettings connectorSettings, CDPMetadataItem fieldMetadata)
: this(dataset, table, tables, connectorSettings, fieldMetadata)
{
DatasetMetadata = datasetMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,32 @@
namespace Microsoft.PowerFx.Connectors
{
// Used by ConnectorDataSource.GetTablesAsync
internal class GetTables : ISupportsPostProcessing
public class GetTables
{
[JsonPropertyName("@metadata")]
public List<CDPMetadataItem> Metadata { get; set; }
internal List<CDPMetadataItem> Metadata { get; set; }

[JsonPropertyName("value")]
public List<RawTable> Value { get; set; }
private IEnumerable<RawTable> _value;

public void PostProcess()
[JsonPropertyName("value")]
public IEnumerable<RawTable> Value
{
Value = Value.Select(rt => new RawTable() { Name = rt.Name, DisplayName = rt.DisplayName.Split('.').Last().Replace("[", string.Empty).Replace("]", string.Empty) }).ToList();
get => _value;
set =>
_value = value?
.Select(rt => new RawTable
{
Name = rt.Name,
DisplayName = rt.DisplayName
.Split('.')
.Last()
.Replace("[", string.Empty)
.Replace("]", string.Empty)
})
.ToList();
}
}

internal interface ISupportsPostProcessing
{
void PostProcess();
}

internal class CDPMetadataItem
{
[JsonPropertyName("name")]
Expand Down Expand Up @@ -68,12 +75,17 @@ public class CDPSensitivityLabelInfo
public bool IsParent { get; set; }
}

internal class RawTable
public class RawTable
{
// Logical Name
/// <summary>
/// Logical name of the table.
/// </summary>
[JsonPropertyName("Name")]
public string Name { get; set; }

/// <summary>
/// Display name of the table.
/// </summary>
[JsonPropertyName("DisplayName")]
public string DisplayName { get; set; }

Expand Down
33 changes: 33 additions & 0 deletions src/libraries/Microsoft.PowerFx.Connectors/Utilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.PowerFx.Core.Functions.Delegation;

namespace Microsoft.PowerFx.Connectors
{
internal class Utilities
{
public static IEnumerable<DelegationOperator> ToDelegationOp(IEnumerable<string> filterFunctionList)
{
if (filterFunctionList == null)
{
return null;
}

List<DelegationOperator> list = new List<DelegationOperator>();

foreach (string str in filterFunctionList)
{
if (Enum.TryParse(str, true, out DelegationOperator op))
{
list.Add(op);
}
}

return list;
}
}
}
Loading