Skip to content

[Backport 8.15] Implement Esql.QueryAsStreamAsync helper #8285

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
6 changes: 3 additions & 3 deletions benchmarks/Benchmarks/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"System.Diagnostics.DiagnosticSource": "8.0.0",
"System.Text.Json": "8.0.4"
Expand Down Expand Up @@ -1196,7 +1196,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/Profiling/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"System.Diagnostics.DiagnosticSource": "8.0.0",
"System.Text.Json": "8.0.4"
Expand Down Expand Up @@ -122,7 +122,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -185,7 +185,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
},
Expand Down Expand Up @@ -234,8 +234,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -381,7 +381,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
},
Expand Down Expand Up @@ -421,8 +421,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -560,7 +560,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
},
Expand Down Expand Up @@ -600,8 +600,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"System.Diagnostics.DiagnosticSource": "8.0.0",
"System.Text.Json": "8.0.4"
Expand Down Expand Up @@ -691,7 +691,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
},
Expand Down Expand Up @@ -731,8 +731,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ=="
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
Expand Down Expand Up @@ -788,7 +788,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.20, )"
"Elastic.Transport": "[0.4.22, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ private enum ProductCheckStatus

internal TResponse DoRequest<TRequest, TResponse, TRequestParameters>(TRequest request)
where TRequest : Request<TRequestParameters>
where TResponse : ElasticsearchResponse, new()
where TResponse : TransportResponse, new()
where TRequestParameters : RequestParameters, new() =>
DoRequest<TRequest, TResponse, TRequestParameters>(request, null);

internal TResponse DoRequest<TRequest, TResponse, TRequestParameters>(
TRequest request,
Action<IRequestConfiguration>? forceConfiguration)
where TRequest : Request<TRequestParameters>
where TResponse : ElasticsearchResponse, new()
where TResponse : TransportResponse, new()
where TRequestParameters : RequestParameters, new()
=> DoRequestCoreAsync<TRequest, TResponse, TRequestParameters>(false, request, forceConfiguration).EnsureCompleted();

internal Task<TResponse> DoRequestAsync<TRequest, TResponse, TRequestParameters>(
TRequest request,
CancellationToken cancellationToken = default)
where TRequest : Request<TRequestParameters>
where TResponse : ElasticsearchResponse, new()
where TResponse : TransportResponse, new()
where TRequestParameters : RequestParameters, new()
=> DoRequestAsync<TRequest, TResponse, TRequestParameters>(request, null, cancellationToken);

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

Expand All @@ -130,7 +130,7 @@ private ValueTask<TResponse> DoRequestCoreAsync<TRequest, TResponse, TRequestPar
Action<IRequestConfiguration>? forceConfiguration,
CancellationToken cancellationToken = default)
where TRequest : Request<TRequestParameters>
where TResponse : ElasticsearchResponse, new()
where TResponse : TransportResponse, new()
where TRequestParameters : RequestParameters, new()
{
if (_productCheckStatus == ProductCheckStatus.Failed)
Expand Down Expand Up @@ -280,7 +280,7 @@ private static OpenTelemetryData PrepareOpenTelemetryData<TRequest, TRequestPara

private void PostRequestProductCheck<TRequest, TResponse>(TRequest request, TResponse response)
where TRequest : Request
where TResponse : ElasticsearchResponse, new()
where TResponse : TransportResponse, new()
{
if (response.ApiCallDetails.HttpStatusCode.HasValue && response.ApiCallDetails.HttpStatusCode.Value >= 200 && response.ApiCallDetails.HttpStatusCode.Value <= 299 && _productCheckStatus == ProductCheckStatus.NotChecked)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Transport" Version="0.4.20" />
<PackageReference Include="Elastic.Transport" Version="0.4.22" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
30 changes: 15 additions & 15 deletions src/Elastic.Clients.Elasticsearch.Serverless/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.20, )",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"requested": "[0.4.22, )",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -205,9 +205,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.20, )",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"requested": "[0.4.22, )",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -396,9 +396,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.20, )",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"requested": "[0.4.22, )",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -570,9 +570,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.20, )",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ==",
"requested": "[0.4.22, )",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw==",
"dependencies": {
"System.Diagnostics.DiagnosticSource": "8.0.0",
"System.Text.Json": "8.0.4"
Expand Down Expand Up @@ -696,9 +696,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.20, )",
"resolved": "0.4.20",
"contentHash": "/Msl7KoUk0Stg28+g64AujlnR2+1jyR8OkQKcWYPpOy/H1EGpJAvlnVDgF0xJxHIG+MUrejn52uzmJVkWPNjpQ=="
"requested": "[0.4.22, )",
"resolved": "0.4.22",
"contentHash": "9J5GPHJcT8sewn2zVfWTrsCQvfQYgUiY/jx+IRjWUk7XNPd837qfEL42I5baH69cyW/e4RoDy8v76yxqz95tDw=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if ELASTICSEARCH_STACK

using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

using Elastic.Transport;

#if ELASTICSEARCH_SERVERLESS
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
#else

namespace Elastic.Clients.Elasticsearch.Esql;
#endif

internal sealed class EsqlResponseBuilder : CustomResponseBuilder
{
Expand Down Expand Up @@ -66,5 +69,3 @@ public sealed partial class EsqlQueryRequestParameters

public EsqlQueryRequestParameters() => CustomResponseBuilder = ResponseBuilder;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if ELASTICSEARCH_STACK
#if ELASTICSEARCH_SERVERLESS
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
#else

namespace Elastic.Clients.Elasticsearch.Esql;
#endif

public sealed partial class EsqlQueryResponse
{
public byte[] Data { get; init; }
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if !ELASTICSEARCH_SERVERLESS

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -12,16 +10,47 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Threading;
using Elastic.Transport;

#if ELASTICSEARCH_SERVERLESS
namespace Elastic.Clients.Elasticsearch.Esql.Serverless;
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
#else

namespace Elastic.Clients.Elasticsearch.Esql;
#endif

public partial class EsqlNamespacedClient
{
/// <summary>
/// Executes an ES|QL request and returns the response as a stream.
/// </summary>
/// <returns>The ES|QL query result as a generic stream response.</returns>
/// <remarks>The response must be disposed after use.</remarks>
public virtual Task<StreamResponse> QueryAsStreamAsync<TDocument>(
Action<EsqlQueryRequestDescriptor<TDocument>> configureRequest,
CancellationToken cancellationToken = default)
{
var descriptor = new EsqlQueryRequestDescriptor<TDocument>();
configureRequest?.Invoke(descriptor);
descriptor.BeforeRequest();
return DoRequestAsync<EsqlQueryRequestDescriptor<TDocument>, StreamResponse, EsqlQueryRequestParameters>(descriptor, cancellationToken);
}

/// <summary>
/// Executes an ES|QL request and returns the response as a stream.
/// </summary>
/// <returns>The ES|QL query result as a generic stream response.</returns>
/// <remarks>The response must be disposed after use.</remarks>
public virtual Task<StreamResponse> QueryAsStreamAsync(
Action<EsqlQueryRequestDescriptor> configureRequest,
CancellationToken cancellationToken = default)
{
var descriptor = new EsqlQueryRequestDescriptor();
configureRequest?.Invoke(descriptor);
descriptor.BeforeRequest();
return DoRequestAsync<EsqlQueryRequestDescriptor, StreamResponse, EsqlQueryRequestParameters>(descriptor, cancellationToken);
}

public virtual async Task<IEnumerable<TDocument>> QueryAsObjectsAsync<TDocument>(
Action<EsqlQueryRequestDescriptor<TDocument>> configureRequest,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -92,5 +121,3 @@ private static IEnumerable<T> EsqlToObject<T>(ElasticsearchClient client, EsqlQu
}
}
}

#endif
Loading
Loading