Skip to content

Commit d727c13

Browse files
authored
[TSI] Hierarchy implementation and tests (#20368)
1 parent fa1caf7 commit d727c13

File tree

28 files changed

+3176
-615
lines changed

28 files changed

+3176
-615
lines changed

sdk/timeseriesinsights/Azure.IoT.TimeSeriesInsights/api/Azure.IoT.TimeSeriesInsights.netstandard2.0.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,24 @@ public partial class HierarchiesBatchResponse
102102
{
103103
internal HierarchiesBatchResponse() { }
104104
public System.Collections.Generic.IReadOnlyList<Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError> Delete { get { throw null; } }
105-
public System.Collections.Generic.IReadOnlyList<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOrError> Get { get { throw null; } }
106-
public System.Collections.Generic.IReadOnlyList<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOrError> Put { get { throw null; } }
105+
public System.Collections.Generic.IReadOnlyList<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult> Get { get { throw null; } }
106+
public System.Collections.Generic.IReadOnlyList<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult> Put { get { throw null; } }
107+
}
108+
public partial class HierarchiesClient
109+
{
110+
protected HierarchiesClient() { }
111+
public virtual Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]> CreateOrReplace(System.Collections.Generic.IEnumerable<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchy> timeSeriesHierarchies, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
112+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]>> CreateOrReplaceAsync(System.Collections.Generic.IEnumerable<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchy> timeSeriesHierarchies, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
113+
public virtual Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError[]> DeleteById(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyIds, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
114+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError[]>> DeleteByIdAsync(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyIds, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
115+
public virtual Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError[]> DeleteByName(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyNames, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
116+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError[]>> DeleteByNameAsync(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyNames, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
117+
public virtual Azure.Pageable<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchy> Get(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
118+
public virtual Azure.AsyncPageable<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchy> GetAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
119+
public virtual Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]> GetById(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyIds, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
120+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]>> GetByIdAsync(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyIds, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
121+
public virtual Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]> GetByName(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyNames, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
122+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchyOperationResult[]>> GetByNameAsync(System.Collections.Generic.IEnumerable<string> timeSeriesHierarchyNames, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
107123
}
108124
public partial class HierarchiesExpandParameter
109125
{
@@ -384,9 +400,9 @@ public TimeSeriesHierarchy(string name, Azure.IoT.TimeSeriesInsights.Models.Time
384400
public string Name { get { throw null; } set { } }
385401
public Azure.IoT.TimeSeriesInsights.Models.TimeSeriesHierarchySource Source { get { throw null; } set { } }
386402
}
387-
public partial class TimeSeriesHierarchyOrError
403+
public partial class TimeSeriesHierarchyOperationResult
388404
{
389-
internal TimeSeriesHierarchyOrError() { }
405+
internal TimeSeriesHierarchyOperationResult() { }
390406
public Azure.IoT.TimeSeriesInsights.TimeSeriesOperationError Error { get { throw null; } }
391407
public Azure.IoT.TimeSeriesInsights.TimeSeriesHierarchy Hierarchy { get { throw null; } }
392408
}
@@ -409,6 +425,7 @@ public partial class TimeSeriesInsightsClient
409425
protected TimeSeriesInsightsClient() { }
410426
public TimeSeriesInsightsClient(string environmentFqdn, Azure.Core.TokenCredential credential) { }
411427
public TimeSeriesInsightsClient(string environmentFqdn, Azure.Core.TokenCredential credential, Azure.IoT.TimeSeriesInsights.TimeSeriesInsightsClientOptions options) { }
428+
public virtual Azure.IoT.TimeSeriesInsights.HierarchiesClient Hierarchies { get { throw null; } }
412429
public virtual Azure.IoT.TimeSeriesInsights.InstancesClient Instances { get { throw null; } }
413430
public virtual Azure.IoT.TimeSeriesInsights.ModelSettingsClient ModelSettings { get { throw null; } }
414431
public virtual Azure.IoT.TimeSeriesInsights.QueryClient Query { get { throw null; } }
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Time Series Insights
2+
3+
## Hierarchies
4+
5+
Time Series Model hierarchies organize instances by specifying property names and their relationships.
6+
Hierarchies are represented in JSON as:
7+
8+
```json
9+
{
10+
"hierarchies": [
11+
{
12+
"id": "6e292e54-9a26-4be1-9034-607d71492707",
13+
"name": "Location",
14+
"source": {
15+
"instanceFieldNames": [
16+
"state",
17+
"city"
18+
]
19+
}
20+
},
21+
{
22+
"id": "a28fd14c-6b98-4ab5-9301-3840f142d30e",
23+
"name": "ManufactureDate",
24+
"source": {
25+
"instanceFieldNames": [
26+
"year",
27+
"month"
28+
]
29+
}
30+
}
31+
]
32+
}
33+
```
34+
35+
## GET /timeseries/hierarchies
36+
37+
Returns time series hierarchies definitions in pages.
38+
39+
```csharp
40+
/// <summary>
41+
/// Gets time series insight hierarchies in pages asynchronously.
42+
/// </summary>
43+
/// <param name="cancellationToken">The cancellation token.</param>
44+
/// <returns> The pageable list <see cref="AsyncPageable{TimeSeriesHierarchy}"/> of Time Series instances hierarchies with the http response.</returns>
45+
public virtual AsyncPageable<TimeSeriesHierarchy> GetTimeSeriesHierarchiesAsync(
46+
CancellationToken cancellationToken = default)
47+
```
48+
49+
## POST /timeseries/hierarchies/$batch
50+
51+
Executes a batch get, create, update, delete operation on multiple time series hierarchies.
52+
53+
### Get Time Series Insights Hierarchies
54+
55+
```csharp
56+
/// <summary>
57+
/// Gets time series insight hierarchies by Time Series hierarchy Ids asynchronously.
58+
/// </summary>
59+
/// <param name="timeSeriesHierarchyIds">List of Ids of the Time Series hierarchies to return.</param>
60+
/// <param name="cancellationToken">The cancellation token.</param>
61+
/// <returns>List of hierarchy or error objects corresponding by position to the array in the request. Hierarchy object is set when operation is successful and error object is set when operation is unsuccessful.
62+
public virtual async Task<Response<TimeSeriesHierarchyOperationResult[]>> GetTimeSeriesHierarchiesByIdAsync(
63+
IEnumerable<string> timeSeriesHierarchyIds,
64+
CancellationToken cancellationToken = default)
65+
```
66+
67+
```csharp
68+
/// <summary>
69+
/// Gets time series insight hierarchies by Time Series hierarchy Names asynchronously.
70+
/// </summary>
71+
/// <param name="timeSeriesHierarchyNames">List of names of the Time Series hierarchies to return.</param>
72+
/// <param name="cancellationToken">The cancellation token.</param>
73+
/// <returns>List of hierarchy or error objects corresponding by position to the array in the request. Hierarchy object is set when operation is successful and error object is set when operation is unsuccessful.
74+
public virtual async Task<Response<TimeSeriesHierarchyOperationResult[]>> GetTimeSeriesHierarchiesByNameAsync(
75+
IEnumerable<string> timeSeriesHierarchyNames,
76+
CancellationToken cancellationToken = default)
77+
```
78+
79+
### Create OR Replace Time Series Insights Hierarchies
80+
81+
```csharp
82+
/// <summary>
83+
/// Creates or Updates Time Series insight hierarchies asynchronously.
84+
/// </summary>
85+
/// <param name="timeSeriesHierarchies">The Time Series insight hierarchies to be created or replaced.</param>
86+
/// <param name="cancellationToken">The cancellation token.</param>
87+
/// <returns>
88+
/// List of hierarchy or error objects corresponding by position to the array in the request. Hierarchy object is set when operation is successful and error object is set when operation is unsuccessful.
89+
/// </returns>
90+
public virtual async Task<Response<TimeSeriesHierarchyOperationResult[]>> CreateOrReplaceTimeSeriesHierarchiesAsync(
91+
IEnumerable<TimeSeriesHierarchy> timeSeriesHierarchies,
92+
CancellationToken cancellationToken = default)
93+
```
94+
95+
### Delete Time Series Insights Hierarchies
96+
97+
```csharp
98+
/// <summary>
99+
/// Deletes Time Series insight hierarchies by Time Series hierarchy Ids asynchronously.
100+
/// </summary>
101+
/// <param name="timeSeriesHierarchyIds">List of names of the Time Series hierarchies to return.</param>
102+
/// <param name="cancellationToken">The cancellation token.</param>
103+
/// <returns>
104+
/// List of error objects corresponding by position to the "delete" array in the request - null when the operation is successful.
105+
/// </returns>
106+
public virtual async Task<Response<TimeSeriesOperationError[]>> DeleteTimeSeriesHierarchiesByIdAsync(
107+
IEnumerable<string> timeSeriesHierarchyIds,
108+
CancellationToken cancellationToken = default)
109+
```
110+
111+
```csharp
112+
/// <summary>
113+
/// Deletes time series insight hierarchies by Time Series hierarchy Names asynchronously.
114+
/// </summary>
115+
/// <param name="timeSeriesHierarchyNames">List of names of the Time Series hierarchies to return.</param>
116+
/// <param name="cancellationToken">The cancellation token.</param>
117+
/// <returns>
118+
/// List of error objects corresponding by position to the "delete" array in the request - null when the operation is successful.
119+
/// </returns>
120+
public virtual async Task<Response<TimeSeriesOperationError[]>> DeleteTimeSeriesHierarchiesByNameAsync(
121+
IEnumerable<string> timeSeriesHierarchyNames,
122+
CancellationToken cancellationToken = default)
123+
```
124+
125+
## Definitions
126+
127+
### TimeSeriesHierarchyOperationResult:
128+
129+
```json
130+
TimeSeriesHierarchyOperationResult:
131+
description: Result of a batch operation on a particular time series hierarchy. Hierarchy is set when operation is successful and error object is set when operation is unsuccessful.
132+
type: object
133+
properties:
134+
hierarchy:
135+
description: Time series hierarchy object - set when the operation is successful.
136+
readOnly: true
137+
$ref: '#/definitions/TimeSeriesHierarchy'
138+
error:
139+
description: Error object - set when the operation is unsuccessful.
140+
readOnly: true
141+
$ref: '#/definitions/TsiErrorBody'
142+
```
143+
144+
### TimeSeriesOperationError:
145+
146+
```json
147+
TsiErrorBody:
148+
description: A particular API error with an error code and a message.
149+
type: object
150+
properties:
151+
code:
152+
description: 'Language-independent, human-readable string that defines a service-specific error code. This code serves as a more specific indicator for the HTTP error code specified in the response. Can be used to programmatically handle specific error cases.'
153+
readOnly: true
154+
type: string
155+
message:
156+
description: 'Human-readable, language-independent representation of the error. It is intended as an aid to developers and is not suitable for exposure to end users.'
157+
readOnly: true
158+
type: string
159+
target:
160+
description: 'Target of the particular error (for example, the name of the property in error). May be null.'
161+
readOnly: true
162+
type: string
163+
innerError:
164+
description: Contains more specific error that narrows down the cause. May be null.
165+
readOnly: true
166+
$ref: '#/definitions/TsiErrorBody'
167+
details:
168+
description: Contains additional error information. May be null.
169+
readOnly: true
170+
type: array
171+
items:
172+
$ref: '#/definitions/TsiErrorDetails'
173+
additionalProperties: true
174+
x-ms-external: false
175+
```
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using System.Text.Json;
6+
using Azure.Core;
7+
8+
namespace Azure.IoT.TimeSeriesInsights
9+
{
10+
/// <summary>
11+
/// This class definition overrides serialization implementation in order to turn a raw response
12+
/// from Time Series Insights into a HierarchiesBatchResponse object.
13+
/// </summary>
14+
[CodeGenModel("HierarchiesBatchResponse")]
15+
public partial class HierarchiesBatchResponse
16+
{
17+
// The purpose of overriding this method is to protect against an InvalidOperationException
18+
// that is being thrown by the generated code. More specifically, the exception is being thrown
19+
// when trying to deserialize the "delete" property. A coversation has started with the Time Series
20+
// Insights team on take a closer look on the thrown exception.
21+
internal static HierarchiesBatchResponse DeserializeHierarchiesBatchResponse(JsonElement element)
22+
{
23+
Optional<IReadOnlyList<TimeSeriesHierarchyOperationResult>> @get = default;
24+
Optional<IReadOnlyList<TimeSeriesHierarchyOperationResult>> put = default;
25+
Optional<IReadOnlyList<TimeSeriesOperationError>> delete = default;
26+
foreach (var property in element.EnumerateObject())
27+
{
28+
if (property.NameEquals("get"))
29+
{
30+
if (property.Value.ValueKind == JsonValueKind.Null)
31+
{
32+
property.ThrowNonNullablePropertyIsNull();
33+
continue;
34+
}
35+
List<TimeSeriesHierarchyOperationResult> array = new List<TimeSeriesHierarchyOperationResult>();
36+
foreach (var item in property.Value.EnumerateArray())
37+
{
38+
array.Add(TimeSeriesHierarchyOperationResult.DeserializeTimeSeriesHierarchyOperationResult(item));
39+
}
40+
@get = array;
41+
continue;
42+
}
43+
if (property.NameEquals("put"))
44+
{
45+
if (property.Value.ValueKind == JsonValueKind.Null)
46+
{
47+
property.ThrowNonNullablePropertyIsNull();
48+
continue;
49+
}
50+
List<TimeSeriesHierarchyOperationResult> array = new List<TimeSeriesHierarchyOperationResult>();
51+
foreach (var item in property.Value.EnumerateArray())
52+
{
53+
array.Add(TimeSeriesHierarchyOperationResult.DeserializeTimeSeriesHierarchyOperationResult(item));
54+
}
55+
put = array;
56+
continue;
57+
}
58+
if (property.NameEquals("delete"))
59+
{
60+
if (property.Value.ValueKind == JsonValueKind.Null)
61+
{
62+
property.ThrowNonNullablePropertyIsNull();
63+
continue;
64+
}
65+
List<TimeSeriesOperationError> array = new List<TimeSeriesOperationError>();
66+
foreach (var item in property.Value.EnumerateArray())
67+
{
68+
array.Add(item.ValueKind != JsonValueKind.Null ? TimeSeriesOperationError.DeserializeTimeSeriesOperationError(item) : null);
69+
}
70+
delete = array;
71+
continue;
72+
}
73+
}
74+
return new HierarchiesBatchResponse(Optional.ToList(@get), Optional.ToList(put), Optional.ToList(delete));
75+
}
76+
}
77+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.IoT.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// Result of an operation on a particular time series hierarchy. Hierarchy object is set when operation
10+
/// is successful and error object is set when operation is unsuccessful.
11+
/// </summary>
12+
[CodeGenModel("TimeSeriesHierarchyOrError")]
13+
public partial class TimeSeriesHierarchyOperationResult
14+
{
15+
// This class declaration changes the class name; do not remove.
16+
// The class name change is to make it clearer to the user that it represents
17+
// a hierarchy operation result.
18+
}
19+
}

0 commit comments

Comments
 (0)