-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathTestTabularDataSource.cs
344 lines (251 loc) · 11.7 KB
/
TestTabularDataSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Microsoft.PowerFx.Core.Binding.BindInfo;
using Microsoft.PowerFx.Core.Entities;
using Microsoft.PowerFx.Core.Entities.Delegation;
using Microsoft.PowerFx.Core.Entities.QueryOptions;
using Microsoft.PowerFx.Core.Functions.Delegation;
using Microsoft.PowerFx.Core.Functions.Delegation.DelegationMetadata;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.UtilityDataStructures;
using Microsoft.PowerFx.Core.Utils;
using Microsoft.PowerFx.Types;
namespace Microsoft.PowerFx.Core.Tests.Helpers
{
internal class ExternalDataEntityMetadataProvider : IExternalDataEntityMetadataProvider
{
public bool TryGetEntityMetadata(string expandInfoIdentity, out IDataEntityMetadata entityMetadata)
{
var st = Environment.StackTrace;
if (st.Contains("Microsoft.PowerFx.Types.CollectionTableValue`1.Matches"))
{
entityMetadata = new DataEntityMetadata();
return true;
}
// Getting Metadata isn't allowed for performance reasons only
throw new GettingMetadataNotAllowedException();
}
}
internal class TestDelegationMetadata : IDelegationMetadata
{
private DelegationCapability _capability;
private readonly DType _schema;
private readonly FilterOpMetadata _filterDelegationMetadata;
public TestDelegationMetadata(DelegationCapability capability = default, DType schema = default, Core.Functions.Delegation.DelegationMetadata.FilterOpMetadata filterDelegationMetadata = default)
{
_capability = capability;
_schema = schema ?? EntityRecordType._type;
_filterDelegationMetadata = filterDelegationMetadata;
}
public static RecordType EntityRecordType => RecordType.Empty()
.Add("logicStr2", FormulaType.String, "MyStr2")
.Add("logicDate2", FormulaType.DateTime, "MyDate2");
public DType Schema => _schema;
public DelegationCapability TableAttributes => _capability;
public DelegationCapability TableCapabilities => _capability;
public SortOpMetadata SortDelegationMetadata => throw new NotImplementedException();
public FilterOpMetadata FilterDelegationMetadata => _filterDelegationMetadata;
public GroupOpMetadata GroupDelegationMetadata => throw new NotImplementedException();
public Dictionary<DPath, DPath> ODataPathReplacementMap => throw new NotImplementedException();
}
internal class TestExternalEntityScope : IExternalEntityScope
{
private readonly SymbolTable _symbol;
public TestExternalEntityScope(SymbolTable symbol)
{
_symbol = symbol;
}
public bool TryGetNamedEnum(DName identName, out DType enumType) => throw new NotImplementedException();
public bool TryGetCdsDataSourceWithLogicalName(string datasetName, string expandInfoIdentity, out IExternalCdsDataSource dataSource) => throw new NotImplementedException();
public IExternalTabularDataSource GetTabularDataSource(string identName) => throw new NotImplementedException();
public bool TryGetEntity<T>(DName currentEntityEntityName, out T externalEntity)
where T : class, IExternalEntity
{
externalEntity = default;
if (_symbol.TryGetVariable(currentEntityEntityName, out NameLookupInfo lookupInfo, out _))
{
externalEntity = lookupInfo.Data as T;
return true;
}
return false;
}
public bool IsNameAvailable(string name, bool ignoreNamedFormulas = false)
{
return false;
}
}
internal class DelegatableSymbolTable : SymbolTable
{
private readonly IExternalEntityScope _externalEntityScope;
public DelegatableSymbolTable()
: base()
{
_externalEntityScope = new TestExternalEntityScope(this);
}
internal override IExternalEntityScope InternalEntityScope => _externalEntityScope;
}
internal class DataEntityMetadata : IDataEntityMetadata
{
public string EntityName => throw new NotImplementedException();
public DType Schema => throw new NotImplementedException();
public BidirectionalDictionary<string, string> DisplayNameMapping => throw new NotImplementedException();
public BidirectionalDictionary<string, string> PreviousDisplayNameMapping => throw new NotImplementedException();
public bool IsConvertingDisplayNameMapping { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public IDelegationMetadata DelegationMetadata => new TestDelegationMetadata();
public IExternalTableDefinition EntityDefinition => throw new NotImplementedException();
public string DatasetName => throw new NotImplementedException();
public bool IsValid => throw new NotImplementedException();
public string OriginalDataDescriptionJson => throw new NotImplementedException();
public string InternalRepresentationJson => throw new NotImplementedException();
public void ActualizeTemplate(string datasetName)
{
throw new NotImplementedException();
}
public void ActualizeTemplate(string datasetName, string entityName)
{
throw new NotImplementedException();
}
public void LoadClientSemantics(bool isPrimaryTable = false)
{
throw new NotImplementedException();
}
public void SetClientSemantics(IExternalTableDefinition tableDefinition)
{
throw new NotImplementedException();
}
public string ToJsonDefinition()
{
throw new NotImplementedException();
}
}
internal class TestDataSource : IExternalDataSource, IExternalTabularDataSource
{
internal IExternalDataEntityMetadataProvider ExternalDataEntityMetadataProvider;
private readonly string[] _keyColumns;
private readonly HashSet<string> _selectableColumns;
private readonly TabularDataQueryOptions _tabularDataQueryOptions;
internal TestDataSource(string name, DType schema, string[] keyColumns = null, IEnumerable<string> selectableColumns = null)
{
ExternalDataEntityMetadataProvider = new ExternalDataEntityMetadataProvider();
Type = DType.AttachDataSourceInfo(schema, this);
Name = name;
DisplayNameMapping = new BidirectionalDictionary<string, string>();
_keyColumns = keyColumns ?? Array.Empty<string>();
_selectableColumns = new HashSet<string>(selectableColumns ?? Enumerable.Empty<string>());
_tabularDataQueryOptions = new TabularDataQueryOptions(this);
}
public string Name { get; }
public virtual bool IsSelectable => true;
public virtual bool IsDelegatable => throw new NotImplementedException();
public bool RequiresAsync => throw new NotImplementedException();
public IExternalDataEntityMetadataProvider DataEntityMetadataProvider => ExternalDataEntityMetadataProvider;
public virtual DataSourceKind Kind => throw new NotImplementedException();
public IExternalTableMetadata TableMetadata => throw new NotImplementedException();
public virtual IDelegationMetadata DelegationMetadata => throw new NotImplementedException();
public DName EntityName => new DName(Name);
public DType Type { get; }
public bool IsPageable => false;
public virtual TabularDataQueryOptions QueryOptions => _tabularDataQueryOptions;
public bool IsConvertingDisplayNameMapping => false;
public BidirectionalDictionary<string, string> DisplayNameMapping { get; }
public BidirectionalDictionary<string, string> PreviousDisplayNameMapping => null;
public bool IsRefreshable => throw new NotImplementedException();
IDelegationMetadata IExternalDataSource.DelegationMetadata => DelegationMetadata;
public bool IsWritable => throw new NotImplementedException();
public bool CanIncludeExpand(IExpandInfo expandToAdd)
{
throw new NotImplementedException();
}
public bool CanIncludeExpand(IExpandInfo parentExpandInfo, IExpandInfo expandToAdd)
{
throw new NotImplementedException();
}
public virtual bool CanIncludeSelect(string selectColumnName)
{
return _selectableColumns.Contains(selectColumnName);
}
public bool CanIncludeSelect(IExpandInfo expandInfo, string selectColumnName)
{
throw new NotImplementedException();
}
public virtual IReadOnlyList<string> GetKeyColumns()
{
return _keyColumns;
}
public IEnumerable<string> GetKeyColumns(IExpandInfo expandInfo)
{
throw new NotImplementedException();
}
}
internal class TestDelegableDataSource : TestDataSource
{
private readonly TabularDataQueryOptions _queryOptions;
private readonly IDelegationMetadata _delegationMetadata;
internal TestDelegableDataSource(string name, DType schema, IDelegationMetadata delegationMetadata)
: base(name, schema)
{
_queryOptions = new TabularDataQueryOptions(this);
_delegationMetadata = delegationMetadata;
}
public override bool IsSelectable => true;
public override bool IsDelegatable => true;
public override bool CanIncludeSelect(string selectColumnName)
{
return true;
}
public override TabularDataQueryOptions QueryOptions => new TabularDataQueryOptions(this);
public override IDelegationMetadata DelegationMetadata => _delegationMetadata;
public override DataSourceKind Kind => DataSourceKind.Connected;
public override IReadOnlyList<string> GetKeyColumns()
{
return new List<string>();
}
}
internal class TestExpandInfo : IExpandInfo
{
internal TestDataSource DataSource;
internal TestExpandInfo()
{
DataSource = new TestDataSource("test", DType.EmptyTable);
}
public string Identity => "Some Identity";
public bool IsTable => true;
public string Name => throw new NotImplementedException();
public string PolymorphicParent => throw new NotImplementedException();
public IExternalDataSource ParentDataSource => DataSource;
public ExpandPath ExpandPath => throw new NotImplementedException();
public IExpandInfo Clone()
{
return new TestExpandInfo();
}
public string ToDebugString()
{
throw new NotImplementedException();
}
public void UpdateEntityInfo(IExternalDataSource dataSource, string relatedEntityPath)
{
}
}
internal class GettingMetadataNotAllowedException : Exception
{
public GettingMetadataNotAllowedException()
{
}
public GettingMetadataNotAllowedException(string message)
: base(message)
{
}
public GettingMetadataNotAllowedException(string message, Exception innerException)
: base(message, innerException)
{
}
protected GettingMetadataNotAllowedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}