Skip to content

Commit 90e89db

Browse files
floberndgithub-actions[bot]
authored andcommitted
Implement Esql.QueryAsStreamAsync helper (#8283)
1 parent 9881e96 commit 90e89db

File tree

20 files changed

+154
-123
lines changed

20 files changed

+154
-123
lines changed

Diff for: benchmarks/Benchmarks/packages.lock.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
},
6868
"Elastic.Transport": {
6969
"type": "Transitive",
70-
"resolved": "0.4.20",
71-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
70+
"resolved": "0.4.22",
71+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
7272
"dependencies": {
7373
"System.Diagnostics.DiagnosticSource": "8.0.0",
7474
"System.Text.Json": "8.0.4"
@@ -1196,7 +1196,7 @@
11961196
"elastic.clients.elasticsearch": {
11971197
"type": "Project",
11981198
"dependencies": {
1199-
"Elastic.Transport": "[0.4.20, )"
1199+
"Elastic.Transport": "[0.4.22, )"
12001200
}
12011201
}
12021202
}

Diff for: benchmarks/Profiling/packages.lock.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
},
3232
"Elastic.Transport": {
3333
"type": "Transitive",
34-
"resolved": "0.4.20",
35-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
34+
"resolved": "0.4.22",
35+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
3636
"dependencies": {
3737
"System.Diagnostics.DiagnosticSource": "8.0.0",
3838
"System.Text.Json": "8.0.4"
@@ -122,7 +122,7 @@
122122
"elastic.clients.elasticsearch": {
123123
"type": "Project",
124124
"dependencies": {
125-
"Elastic.Transport": "[0.4.20, )"
125+
"Elastic.Transport": "[0.4.22, )"
126126
}
127127
}
128128
}

Diff for: src/Elastic.Clients.Elasticsearch.JsonNetSerializer/packages.lock.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
},
3838
"Elastic.Transport": {
3939
"type": "Transitive",
40-
"resolved": "0.4.20",
41-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
40+
"resolved": "0.4.22",
41+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
4242
"dependencies": {
4343
"Microsoft.CSharp": "4.7.0",
4444
"System.Buffers": "4.5.1",
@@ -185,7 +185,7 @@
185185
"elastic.clients.elasticsearch": {
186186
"type": "Project",
187187
"dependencies": {
188-
"Elastic.Transport": "[0.4.20, )"
188+
"Elastic.Transport": "[0.4.22, )"
189189
}
190190
}
191191
},
@@ -234,8 +234,8 @@
234234
},
235235
"Elastic.Transport": {
236236
"type": "Transitive",
237-
"resolved": "0.4.20",
238-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
237+
"resolved": "0.4.22",
238+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
239239
"dependencies": {
240240
"Microsoft.CSharp": "4.7.0",
241241
"System.Buffers": "4.5.1",
@@ -381,7 +381,7 @@
381381
"elastic.clients.elasticsearch": {
382382
"type": "Project",
383383
"dependencies": {
384-
"Elastic.Transport": "[0.4.20, )"
384+
"Elastic.Transport": "[0.4.22, )"
385385
}
386386
}
387387
},
@@ -421,8 +421,8 @@
421421
},
422422
"Elastic.Transport": {
423423
"type": "Transitive",
424-
"resolved": "0.4.20",
425-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
424+
"resolved": "0.4.22",
425+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
426426
"dependencies": {
427427
"Microsoft.CSharp": "4.7.0",
428428
"System.Buffers": "4.5.1",
@@ -560,7 +560,7 @@
560560
"elastic.clients.elasticsearch": {
561561
"type": "Project",
562562
"dependencies": {
563-
"Elastic.Transport": "[0.4.20, )"
563+
"Elastic.Transport": "[0.4.22, )"
564564
}
565565
}
566566
},
@@ -600,8 +600,8 @@
600600
},
601601
"Elastic.Transport": {
602602
"type": "Transitive",
603-
"resolved": "0.4.20",
604-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
603+
"resolved": "0.4.22",
604+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
605605
"dependencies": {
606606
"System.Diagnostics.DiagnosticSource": "8.0.0",
607607
"System.Text.Json": "8.0.4"
@@ -691,7 +691,7 @@
691691
"elastic.clients.elasticsearch": {
692692
"type": "Project",
693693
"dependencies": {
694-
"Elastic.Transport": "[0.4.20, )"
694+
"Elastic.Transport": "[0.4.22, )"
695695
}
696696
}
697697
},
@@ -731,8 +731,8 @@
731731
},
732732
"Elastic.Transport": {
733733
"type": "Transitive",
734-
"resolved": "0.4.20",
735-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ=="
734+
"resolved": "0.4.22",
735+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw=="
736736
},
737737
"Microsoft.Build.Tasks.Git": {
738738
"type": "Transitive",
@@ -788,7 +788,7 @@
788788
"elastic.clients.elasticsearch": {
789789
"type": "Project",
790790
"dependencies": {
791-
"Elastic.Transport": "[0.4.20, )"
791+
"Elastic.Transport": "[0.4.22, )"
792792
}
793793
}
794794
}

Diff for: src/Elastic.Clients.Elasticsearch.Serverless/Client/ElasticsearchClient.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ private enum ProductCheckStatus
9595

9696
internal TResponse DoRequest<TRequest, TResponse, TRequestParameters>(TRequest request)
9797
where TRequest : Request<TRequestParameters>
98-
where TResponse : ElasticsearchResponse, new()
98+
where TResponse : TransportResponse, new()
9999
where TRequestParameters : RequestParameters, new() =>
100100
DoRequest<TRequest, TResponse, TRequestParameters>(request, null);
101101

102102
internal TResponse DoRequest<TRequest, TResponse, TRequestParameters>(
103103
TRequest request,
104104
Action<IRequestConfiguration>? forceConfiguration)
105105
where TRequest : Request<TRequestParameters>
106-
where TResponse : ElasticsearchResponse, new()
106+
where TResponse : TransportResponse, new()
107107
where TRequestParameters : RequestParameters, new()
108108
=> DoRequestCoreAsync<TRequest, TResponse, TRequestParameters>(false, request, forceConfiguration).EnsureCompleted();
109109

110110
internal Task<TResponse> DoRequestAsync<TRequest, TResponse, TRequestParameters>(
111111
TRequest request,
112112
CancellationToken cancellationToken = default)
113113
where TRequest : Request<TRequestParameters>
114-
where TResponse : ElasticsearchResponse, new()
114+
where TResponse : TransportResponse, new()
115115
where TRequestParameters : RequestParameters, new()
116116
=> DoRequestAsync<TRequest, TResponse, TRequestParameters>(request, null, cancellationToken);
117117

@@ -120,7 +120,7 @@ internal Task<TResponse> DoRequestAsync<TRequest, TResponse, TRequestParameters>
120120
Action<IRequestConfiguration>? forceConfiguration,
121121
CancellationToken cancellationToken = default)
122122
where TRequest : Request<TRequestParameters>
123-
where TResponse : ElasticsearchResponse, new()
123+
where TResponse : TransportResponse, new()
124124
where TRequestParameters : RequestParameters, new()
125125
=> DoRequestCoreAsync<TRequest, TResponse, TRequestParameters>(true, request, forceConfiguration, cancellationToken).AsTask();
126126

@@ -130,7 +130,7 @@ private ValueTask<TResponse> DoRequestCoreAsync<TRequest, TResponse, TRequestPar
130130
Action<IRequestConfiguration>? forceConfiguration,
131131
CancellationToken cancellationToken = default)
132132
where TRequest : Request<TRequestParameters>
133-
where TResponse : ElasticsearchResponse, new()
133+
where TResponse : TransportResponse, new()
134134
where TRequestParameters : RequestParameters, new()
135135
{
136136
if (_productCheckStatus == ProductCheckStatus.Failed)
@@ -280,7 +280,7 @@ private static OpenTelemetryData PrepareOpenTelemetryData<TRequest, TRequestPara
280280

281281
private void PostRequestProductCheck<TRequest, TResponse>(TRequest request, TResponse response)
282282
where TRequest : Request
283-
where TResponse : ElasticsearchResponse, new()
283+
where TResponse : TransportResponse, new()
284284
{
285285
if (response.ApiCallDetails.HttpStatusCode.HasValue && response.ApiCallDetails.HttpStatusCode.Value >= 200 && response.ApiCallDetails.HttpStatusCode.Value <= 299 && _productCheckStatus == ProductCheckStatus.NotChecked)
286286
{

Diff for: src/Elastic.Clients.Elasticsearch.Serverless/Elastic.Clients.Elasticsearch.Serverless.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Nullable>annotations</Nullable>
2222
</PropertyGroup>
2323
<ItemGroup>
24-
<PackageReference Include="Elastic.Transport" Version="0.4.20" />
24+
<PackageReference Include="Elastic.Transport" Version="0.4.22" />
2525
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

Diff for: src/Elastic.Clients.Elasticsearch.Serverless/packages.lock.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
},
2323
"Elastic.Transport": {
2424
"type": "Direct",
25-
"requested": "[0.4.20, )",
26-
"resolved": "0.4.20",
27-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
25+
"requested": "[0.4.22, )",
26+
"resolved": "0.4.22",
27+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
2828
"dependencies": {
2929
"Microsoft.CSharp": "4.7.0",
3030
"System.Buffers": "4.5.1",
@@ -205,9 +205,9 @@
205205
},
206206
"Elastic.Transport": {
207207
"type": "Direct",
208-
"requested": "[0.4.20, )",
209-
"resolved": "0.4.20",
210-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
208+
"requested": "[0.4.22, )",
209+
"resolved": "0.4.22",
210+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
211211
"dependencies": {
212212
"Microsoft.CSharp": "4.7.0",
213213
"System.Buffers": "4.5.1",
@@ -396,9 +396,9 @@
396396
},
397397
"Elastic.Transport": {
398398
"type": "Direct",
399-
"requested": "[0.4.20, )",
400-
"resolved": "0.4.20",
401-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
399+
"requested": "[0.4.22, )",
400+
"resolved": "0.4.22",
401+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
402402
"dependencies": {
403403
"Microsoft.CSharp": "4.7.0",
404404
"System.Buffers": "4.5.1",
@@ -570,9 +570,9 @@
570570
},
571571
"Elastic.Transport": {
572572
"type": "Direct",
573-
"requested": "[0.4.20, )",
574-
"resolved": "0.4.20",
575-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
573+
"requested": "[0.4.22, )",
574+
"resolved": "0.4.22",
575+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
576576
"dependencies": {
577577
"System.Diagnostics.DiagnosticSource": "8.0.0",
578578
"System.Text.Json": "8.0.4"
@@ -696,9 +696,9 @@
696696
},
697697
"Elastic.Transport": {
698698
"type": "Direct",
699-
"requested": "[0.4.20, )",
700-
"resolved": "0.4.20",
701-
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ=="
699+
"requested": "[0.4.22, )",
700+
"resolved": "0.4.22",
701+
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw=="
702702
},
703703
"Microsoft.NETFramework.ReferenceAssemblies": {
704704
"type": "Direct",

Diff for: src/Elastic.Clients.Elasticsearch.Shared/Api/Esql/EsqlQueryRequest.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
#if ELASTICSEARCH_STACK
6-
75
using System.IO;
86
using System.Runtime.CompilerServices;
97
using System.Threading;
108
using System.Threading.Tasks;
119

1210
using Elastic.Transport;
1311

12+
#if ELASTICSEARCH_SERVERLESS
13+
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
14+
#else
15+
1416
namespace Elastic.Clients.Elasticsearch.Esql;
17+
#endif
1518

1619
internal sealed class EsqlResponseBuilder : CustomResponseBuilder
1720
{
@@ -66,5 +69,3 @@ public sealed partial class EsqlQueryRequestParameters
6669

6770
public EsqlQueryRequestParameters() => CustomResponseBuilder = ResponseBuilder;
6871
}
69-
70-
#endif

Diff for: src/Elastic.Clients.Elasticsearch.Shared/Api/Esql/EsqlQueryResponse.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
#if ELASTICSEARCH_STACK
5+
#if ELASTICSEARCH_SERVERLESS
6+
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
7+
#else
68

79
namespace Elastic.Clients.Elasticsearch.Esql;
10+
#endif
811

912
public sealed partial class EsqlQueryResponse
1013
{
1114
public byte[] Data { get; init; }
1215
}
13-
14-
#endif

Diff for: src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.Esql.cs

+32-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
#if !ELASTICSEARCH_SERVERLESS
6-
75
using System;
86
using System.Collections.Generic;
97
using System.IO;
@@ -12,16 +10,47 @@
1210
using System.Text.Json.Nodes;
1311
using System.Threading.Tasks;
1412
using System.Threading;
13+
using Elastic.Transport;
1514

1615
#if ELASTICSEARCH_SERVERLESS
17-
namespace Elastic.Clients.Elasticsearch.Esql.Serverless;
16+
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
1817
#else
1918

2019
namespace Elastic.Clients.Elasticsearch.Esql;
2120
#endif
2221

2322
public partial class EsqlNamespacedClient
2423
{
24+
/// <summary>
25+
/// Executes an ES|QL request and returns the response as a stream.
26+
/// </summary>
27+
/// <returns>The ES|QL query result as a generic stream response.</returns>
28+
/// <remarks>The response must be disposed after use.</remarks>
29+
public virtual Task<StreamResponse> QueryAsStreamAsync<TDocument>(
30+
Action<EsqlQueryRequestDescriptor<TDocument>> configureRequest,
31+
CancellationToken cancellationToken = default)
32+
{
33+
var descriptor = new EsqlQueryRequestDescriptor<TDocument>();
34+
configureRequest?.Invoke(descriptor);
35+
descriptor.BeforeRequest();
36+
return DoRequestAsync<EsqlQueryRequestDescriptor<TDocument>, StreamResponse, EsqlQueryRequestParameters>(descriptor, cancellationToken);
37+
}
38+
39+
/// <summary>
40+
/// Executes an ES|QL request and returns the response as a stream.
41+
/// </summary>
42+
/// <returns>The ES|QL query result as a generic stream response.</returns>
43+
/// <remarks>The response must be disposed after use.</remarks>
44+
public virtual Task<StreamResponse> QueryAsStreamAsync(
45+
Action<EsqlQueryRequestDescriptor> configureRequest,
46+
CancellationToken cancellationToken = default)
47+
{
48+
var descriptor = new EsqlQueryRequestDescriptor();
49+
configureRequest?.Invoke(descriptor);
50+
descriptor.BeforeRequest();
51+
return DoRequestAsync<EsqlQueryRequestDescriptor, StreamResponse, EsqlQueryRequestParameters>(descriptor, cancellationToken);
52+
}
53+
2554
public virtual async Task<IEnumerable<TDocument>> QueryAsObjectsAsync<TDocument>(
2655
Action<EsqlQueryRequestDescriptor<TDocument>> configureRequest,
2756
CancellationToken cancellationToken = default)
@@ -92,5 +121,3 @@ private static IEnumerable<T> EsqlToObject<T>(ElasticsearchClient client, EsqlQu
92121
}
93122
}
94123
}
95-
96-
#endif

0 commit comments

Comments
 (0)