diff --git a/build/scripts/Targets.fs b/build/scripts/Targets.fs index a2a12d5d916..f0c745ecbe0 100644 --- a/build/scripts/Targets.fs +++ b/build/scripts/Targets.fs @@ -49,7 +49,7 @@ module Main = Tests.SetTestEnvironmentVariables parsed let testChain = ["clean"; "version"; "restore"; "full-build"; ] - let buildChain = ["test"; "inherit-doc"; "documentation"; ] + let buildChain = ["test"; "inherit-doc"; ] let releaseChain = [ "build"; diff --git a/src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs new file mode 100644 index 00000000000..227c96550c7 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs @@ -0,0 +1,15 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch.Sql; + +public partial class SqlGetAsyncResponse +{ + [JsonInclude] + [JsonPropertyName("rows")] + public IReadOnlyCollection Rows { get; init; } +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/LazyDocument.cs b/src/Elastic.Clients.Elasticsearch/Common/LazyDocument.cs index b04937530bd..d847629a6e1 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/LazyDocument.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/LazyDocument.cs @@ -5,81 +5,37 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; -using System.Threading; -using System.Threading.Tasks; -using Elastic.Transport; namespace Elastic.Clients.Elasticsearch { /// - /// A lazily deserialized document. + /// A lazily deserialized document. + /// Holds raw JSON bytes which can be lazily converted to a specific at a later time. /// [JsonConverter(typeof(LazyDocumentConverter))] - public class LazyDocument + public readonly struct LazyDocument { - private readonly Serializer _sourceSerializer; - private readonly Serializer _requestResponseSerializer; - private readonly IMemoryStreamFactory _memoryStreamFactory; - internal LazyDocument(byte[] bytes, IElasticsearchClientSettings settings) { Bytes = bytes; - - _sourceSerializer = settings.SourceSerializer; - _requestResponseSerializer = settings.RequestResponseSerializer; - _memoryStreamFactory = settings.MemoryStreamFactory; + Settings = settings; } - internal byte[] Bytes { get; } - - internal T AsUsingRequestResponseSerializer() - { - using var ms = _memoryStreamFactory.Create(Bytes); - return _requestResponseSerializer.Deserialize(ms); - } + internal byte[]? Bytes { get; } + internal IElasticsearchClientSettings? Settings { get; } /// /// Creates an instance of from this /// instance. /// /// The type - public T As() - { - using var ms = _memoryStreamFactory.Create(Bytes); - return _sourceSerializer.Deserialize(ms); - } - - /// - /// Creates an instance of from this - /// instance. - /// - /// The type - public object As(Type objectType) + public T? As() { - using var ms = _memoryStreamFactory.Create(Bytes); - return _sourceSerializer.Deserialize(objectType, ms); - } + if (Bytes is null || Settings is null || Bytes.Length == 0) + return default; - /// - /// Creates an instance of from this - /// instance. - /// - /// The type - public ValueTask AsAsync(CancellationToken ct = default) - { - using var ms = _memoryStreamFactory.Create(Bytes); - return _sourceSerializer.DeserializeAsync(ms, ct); - } - - /// - /// Creates an instance of from this - /// instance. - /// - /// The type - public ValueTask AsAsync(Type objectType, CancellationToken ct = default) - { - using var ms = _memoryStreamFactory.Create(Bytes); - return _sourceSerializer.DeserializeAsync(objectType, ms, ct); + using var ms = Settings.MemoryStreamFactory.Create(Bytes); + return Settings.SourceSerializer.Deserialize(ms); } } @@ -101,6 +57,6 @@ public override LazyDocument Read(ref Utf8JsonReader reader, Type typeToConvert, return new LazyDocument(stream.ToArray(), _settings); } - public override void Write(Utf8JsonWriter writer, LazyDocument value, JsonSerializerOptions options) => throw new NotImplementedException(); + public override void Write(Utf8JsonWriter writer, LazyDocument value, JsonSerializerOptions options) => throw new NotImplementedException("We only ever expect to deserialize a LazyDocument on responses."); } } diff --git a/src/Elastic.Clients.Elasticsearch/FutureGenerated/FutureGenerated.cs b/src/Elastic.Clients.Elasticsearch/FutureGenerated/FutureGenerated.cs index ed847468513..bbcd9c37f03 100644 --- a/src/Elastic.Clients.Elasticsearch/FutureGenerated/FutureGenerated.cs +++ b/src/Elastic.Clients.Elasticsearch/FutureGenerated/FutureGenerated.cs @@ -17,6 +17,84 @@ using System.Linq.Expressions; using System.IO; +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlTranslateResponse + { + [JsonInclude] + [JsonPropertyName("query")] + public QueryContainer Query { get; set; } + } + + public static class SqlTranslateResponseExtensions + { + public static SearchRequest AsSearchRequest(this SqlTranslateResponse response) + => new() + { + Query = response.Query, + //Size = response.Size, + //Fields = response.Fields + }; + } +} + +namespace Elastic.Clients.Elasticsearch +{ + [JsonConverter(typeof(SourceConfigConverter))] + public partial class SourceConfig + { + public bool HasBoolValue => Item1.HasValue; + + public bool HasSourceFilterValue => Item2 is not null; + + public bool TryGetBool(out bool? value) + { + if (Item1.HasValue) + { + value = Item1.Value; + return true; + } + + value = null; + return false; + } + + public bool TryGetSourceFilter(out SourceFilter? value) + { + if (Item2 is not null) + { + value = Item2; + return true; + } + + value = null; + return false; + } + } + + internal class SourceConfigConverter : JsonConverter + { + public override SourceConfig? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.True: + case JsonTokenType.False: + var value = reader.GetBoolean(); + return new SourceConfig(value); + + case JsonTokenType.StartObject: + var sourceFilter = JsonSerializer.Deserialize(ref reader, options); + return new SourceConfig(sourceFilter); + } + + return null; + } + + public override void Write(Utf8JsonWriter writer, SourceConfig value, JsonSerializerOptions options) => throw new NotImplementedException(); + } +} + namespace Elastic.Clients.Elasticsearch.Aggregations { //public partial class TopMetricsValue @@ -1129,7 +1207,8 @@ public void Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions options public enum FieldType { Date, - Text + Text, + Long } public partial class CountRequest : CountRequest @@ -1472,6 +1551,10 @@ public override FieldType Read(ref Utf8JsonReader reader, Type typeToConvert, Js { case "date": return FieldType.Date; + case "long": + return FieldType.Long; + case "text": + return FieldType.Text; } ThrowHelper.ThrowJsonException("Unexpected field type value."); @@ -1485,6 +1568,12 @@ public override void Write(Utf8JsonWriter writer, FieldType value, JsonSerialize case FieldType.Date: writer.WriteStringValue("date"); return; + case FieldType.Long: + writer.WriteStringValue("long"); + return; + case FieldType.Text: + writer.WriteStringValue("text"); + return; } writer.WriteNullValue(); @@ -1965,6 +2054,12 @@ public partial class MatchAllQuery public static implicit operator QueryContainer(MatchAllQuery matchAllQuery) => new(matchAllQuery); } + public partial class QueryContainer + { + // TODO - Generate more of these! + public TermQuery Term => Variant as TermQuery; + } + //public sealed partial class BoolQueryDescriptor //{ // internal BoolQuery ToQuery() diff --git a/src/Elastic.Clients.Elasticsearch/Serialization/DictionaryConverter.cs b/src/Elastic.Clients.Elasticsearch/Serialization/DictionaryConverter.cs index 5a382d05296..84059ed8480 100644 --- a/src/Elastic.Clients.Elasticsearch/Serialization/DictionaryConverter.cs +++ b/src/Elastic.Clients.Elasticsearch/Serialization/DictionaryConverter.cs @@ -89,6 +89,10 @@ public override Dictionary Read( { key = IndexName.Parse(propertyName) as TKey; } + else if (typeof(TKey) == typeof(Field)) + { + key = new Field(propertyName) as TKey; + } else { key = (TKey)Activator.CreateInstance(typeof(TKey), diff --git a/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs b/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs index e217adb588e..4f420cc9bc1 100644 --- a/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs +++ b/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs @@ -13,7 +13,13 @@ namespace Elastic.Clients.Elasticsearch; internal sealed class UnionConverter : JsonConverterFactory { - public override bool CanConvert(Type typeToConvert) => typeToConvert.Name == typeof(Union<,>).Name || (typeToConvert.BaseType is not null && typeToConvert.BaseType.Name == typeof(Union<,>).Name); + private static readonly HashSet TypesToSkip = new HashSet + { + typeof(SourceConfig) + }; + + public override bool CanConvert(Type typeToConvert) => !TypesToSkip.Contains(typeToConvert) && + (typeToConvert.Name == typeof(Union<,>).Name || (typeToConvert.BaseType is not null && typeToConvert.BaseType.Name == typeof(Union<,>).Name)); public override JsonConverter CreateConverter( Type type, diff --git a/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlRow.cs b/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlRow.cs new file mode 100644 index 00000000000..d002fd031d9 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlRow.cs @@ -0,0 +1,46 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch.Sql; + +[JsonConverter(typeof(SqlRowConverter))] +public sealed class SqlRow : ReadOnlyCollection +{ + public SqlRow(IList list) : base(list) { } +} + +internal sealed class SqlRowConverter : JsonConverter +{ + public override SqlRow? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) + { + reader.Read(); + return null; + } + + if (reader.TokenType == JsonTokenType.StartArray) + { + var values = new List(); + + while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) + { + var value = JsonSerializer.Deserialize(ref reader, options); + values.Add(value); + } + + return new SqlRow(values); + } + + throw new JsonException($"Unexpected JSON token when deserializing {nameof(SqlRow)}."); + } + + public override void Write(Utf8JsonWriter writer, SqlRow value, JsonSerializerOptions options) => throw new NotImplementedException(); +} diff --git a/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlValue.cs b/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlValue.cs new file mode 100644 index 00000000000..775f043b357 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Types/Sql/SqlValue.cs @@ -0,0 +1,36 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch.Sql; + +[JsonConverter(typeof(SqlValueConverter))] +public readonly struct SqlValue +{ + private readonly LazyDocument _lazyDocument; + + internal SqlValue(LazyDocument lazyDocument) => _lazyDocument = lazyDocument; + + public T? As() => _lazyDocument.As(); +} + +internal sealed class SqlValueConverter : JsonConverter +{ + public override SqlValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) + { + reader.Read(); + return default; + } + + var lazyDoc = JsonSerializer.Deserialize(ref reader, options); + return new SqlValue(lazyDoc); + } + + public override void Write(Utf8JsonWriter writer, SqlValue value, JsonSerializerOptions options) => throw new NotImplementedException(); +} diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs index 5e9252816e7..7359ce5b7b8 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs @@ -46,6 +46,11 @@ internal static class ApiUrlsLookups internal static ApiUrls NoNamespacePing = new ApiUrls(new[] { "/" }); internal static ApiUrls NoNamespaceSearch = new ApiUrls(new[] { "/_search", "/{index}/_search" }); internal static ApiUrls NoNamespaceGetSource = new ApiUrls(new[] { "/{index}/_source/{id}" }); + internal static ApiUrls SqlClearCursor = new ApiUrls(new[] { "/_sql/close" }); + internal static ApiUrls SqlDeleteAsync = new ApiUrls(new[] { "/_sql/async/delete/{id}" }); + internal static ApiUrls SqlGetAsync = new ApiUrls(new[] { "/_sql/async/{id}" }); + internal static ApiUrls SqlGetAsyncStatus = new ApiUrls(new[] { "/_sql/async/status/{id}" }); + internal static ApiUrls SqlQuery = new ApiUrls(new[] { "/_sql" }); internal static ApiUrls NoNamespaceUpdate = new ApiUrls(new[] { "/{index}/_update/{id}" }); } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/SourceRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/SourceRequest.g.cs index 0e4be4b923b..9e8930d80c0 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/SourceRequest.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/SourceRequest.g.cs @@ -199,4 +199,4 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o { } } -} +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorRequest.g.cs new file mode 100644 index 00000000000..f76f0d452c9 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorRequest.g.cs @@ -0,0 +1,68 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlClearCursorRequestParameters : RequestParameters + { + } + + public partial class SqlClearCursorRequest : PlainRequestBase + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlClearCursor; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + [JsonInclude] + [JsonPropertyName("cursor")] + public string Cursor { get; set; } + } + + public sealed partial class SqlClearCursorRequestDescriptor : RequestDescriptorBase + { + internal SqlClearCursorRequestDescriptor(Action configure) => configure.Invoke(this); + public SqlClearCursorRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlClearCursor; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + private string CursorValue { get; set; } + + public SqlClearCursorRequestDescriptor Cursor(string cursor) + { + CursorValue = cursor; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("cursor"); + writer.WriteStringValue(CursorValue); + writer.WriteEndObject(); + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorResponse.g.cs new file mode 100644 index 00000000000..6b7e8dd1cbb --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlClearCursorResponse.g.cs @@ -0,0 +1,31 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlClearCursorResponse : ResponseBase + { + [JsonInclude] + [JsonPropertyName("succeeded")] + public bool Succeeded { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncRequest.g.cs new file mode 100644 index 00000000000..739aa8bbdf5 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncRequest.g.cs @@ -0,0 +1,92 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlDeleteAsyncRequestParameters : RequestParameters + { + } + + public partial class SqlDeleteAsyncRequest : PlainRequestBase + { + public SqlDeleteAsyncRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlDeleteAsync; + protected override HttpMethod HttpMethod => HttpMethod.DELETE; + protected override bool SupportsBody => false; + } + + public sealed partial class SqlDeleteAsyncRequestDescriptor : RequestDescriptorBase, SqlDeleteAsyncRequestParameters> + { + internal SqlDeleteAsyncRequestDescriptor(Action> configure) => configure.Invoke(this); + public SqlDeleteAsyncRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlDeleteAsyncRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlDeleteAsync; + protected override HttpMethod HttpMethod => HttpMethod.DELETE; + protected override bool SupportsBody => false; + public SqlDeleteAsyncRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } + + public sealed partial class SqlDeleteAsyncRequestDescriptor : RequestDescriptorBase + { + internal SqlDeleteAsyncRequestDescriptor(Action configure) => configure.Invoke(this); + public SqlDeleteAsyncRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlDeleteAsyncRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlDeleteAsync; + protected override HttpMethod HttpMethod => HttpMethod.DELETE; + protected override bool SupportsBody => false; + public SqlDeleteAsyncRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncResponse.g.cs new file mode 100644 index 00000000000..a5db1e3f334 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlDeleteAsyncResponse.g.cs @@ -0,0 +1,28 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlDeleteAsyncResponse : AcknowledgedResponseBase + { + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncRequest.g.cs new file mode 100644 index 00000000000..1b42fb631fe --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncRequest.g.cs @@ -0,0 +1,122 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlGetAsyncRequestParameters : RequestParameters + { + [JsonIgnore] + public string? Delimiter { get => Q("delimiter"); set => Q("delimiter", value); } + + [JsonIgnore] + public string? Format { get => Q("format"); set => Q("format", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Time? KeepAlive { get => Q("keep_alive"); set => Q("keep_alive", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Time? WaitForCompletionTimeout { get => Q("wait_for_completion_timeout"); set => Q("wait_for_completion_timeout", value); } + } + + public partial class SqlGetAsyncRequest : PlainRequestBase + { + public SqlGetAsyncRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsync; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + [JsonIgnore] + public string? Delimiter { get => Q("delimiter"); set => Q("delimiter", value); } + + [JsonIgnore] + public string? Format { get => Q("format"); set => Q("format", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Time? KeepAlive { get => Q("keep_alive"); set => Q("keep_alive", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Time? WaitForCompletionTimeout { get => Q("wait_for_completion_timeout"); set => Q("wait_for_completion_timeout", value); } + } + + public sealed partial class SqlGetAsyncRequestDescriptor : RequestDescriptorBase, SqlGetAsyncRequestParameters> + { + internal SqlGetAsyncRequestDescriptor(Action> configure) => configure.Invoke(this); + public SqlGetAsyncRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlGetAsyncRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsync; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + public SqlGetAsyncRequestDescriptor Delimiter(string? delimiter) => Qs("delimiter", delimiter); + public SqlGetAsyncRequestDescriptor Format(string? format) => Qs("format", format); + public SqlGetAsyncRequestDescriptor KeepAlive(Elastic.Clients.Elasticsearch.Time? keepAlive) => Qs("keep_alive", keepAlive); + public SqlGetAsyncRequestDescriptor WaitForCompletionTimeout(Elastic.Clients.Elasticsearch.Time? waitForCompletionTimeout) => Qs("wait_for_completion_timeout", waitForCompletionTimeout); + public SqlGetAsyncRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } + + public sealed partial class SqlGetAsyncRequestDescriptor : RequestDescriptorBase + { + internal SqlGetAsyncRequestDescriptor(Action configure) => configure.Invoke(this); + public SqlGetAsyncRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlGetAsyncRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsync; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + public SqlGetAsyncRequestDescriptor Delimiter(string? delimiter) => Qs("delimiter", delimiter); + public SqlGetAsyncRequestDescriptor Format(string? format) => Qs("format", format); + public SqlGetAsyncRequestDescriptor KeepAlive(Elastic.Clients.Elasticsearch.Time? keepAlive) => Qs("keep_alive", keepAlive); + public SqlGetAsyncRequestDescriptor WaitForCompletionTimeout(Elastic.Clients.Elasticsearch.Time? waitForCompletionTimeout) => Qs("wait_for_completion_timeout", waitForCompletionTimeout); + public SqlGetAsyncRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncResponse.g.cs new file mode 100644 index 00000000000..b1fe27f83b0 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncResponse.g.cs @@ -0,0 +1,47 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlGetAsyncResponse : ResponseBase + { + [JsonInclude] + [JsonPropertyName("columns")] + public IReadOnlyCollection? Columns { get; init; } + + [JsonInclude] + [JsonPropertyName("cursor")] + public string? Cursor { get; init; } + + [JsonInclude] + [JsonPropertyName("id")] + public string Id { get; init; } + + [JsonInclude] + [JsonPropertyName("is_partial")] + public bool IsPartial { get; init; } + + [JsonInclude] + [JsonPropertyName("is_running")] + public bool IsRunning { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusRequest.g.cs new file mode 100644 index 00000000000..b6c5cfe25ff --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusRequest.g.cs @@ -0,0 +1,92 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlGetAsyncStatusRequestParameters : RequestParameters + { + } + + public partial class SqlGetAsyncStatusRequest : PlainRequestBase + { + public SqlGetAsyncStatusRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsyncStatus; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + } + + public sealed partial class SqlGetAsyncStatusRequestDescriptor : RequestDescriptorBase, SqlGetAsyncStatusRequestParameters> + { + internal SqlGetAsyncStatusRequestDescriptor(Action> configure) => configure.Invoke(this); + public SqlGetAsyncStatusRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlGetAsyncStatusRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsyncStatus; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + public SqlGetAsyncStatusRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } + + public sealed partial class SqlGetAsyncStatusRequestDescriptor : RequestDescriptorBase + { + internal SqlGetAsyncStatusRequestDescriptor(Action configure) => configure.Invoke(this); + public SqlGetAsyncStatusRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id)) + { + } + + internal SqlGetAsyncStatusRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGetAsyncStatus; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override bool SupportsBody => false; + public SqlGetAsyncStatusRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + RouteValues.Required("id", id); + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusResponse.g.cs new file mode 100644 index 00000000000..0c4b8a6eb02 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlGetAsyncStatusResponse.g.cs @@ -0,0 +1,51 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlGetAsyncStatusResponse : ResponseBase + { + [JsonInclude] + [JsonPropertyName("completion_status")] + public int? CompletionStatus { get; init; } + + [JsonInclude] + [JsonPropertyName("expiration_time_in_millis")] + public long ExpirationTimeInMillis { get; init; } + + [JsonInclude] + [JsonPropertyName("id")] + public string Id { get; init; } + + [JsonInclude] + [JsonPropertyName("is_partial")] + public bool IsPartial { get; init; } + + [JsonInclude] + [JsonPropertyName("is_running")] + public bool IsRunning { get; init; } + + [JsonInclude] + [JsonPropertyName("start_time_in_millis")] + public long StartTimeInMillis { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryRequest.g.cs new file mode 100644 index 00000000000..c668df70d92 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryRequest.g.cs @@ -0,0 +1,654 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlQueryRequestParameters : RequestParameters + { + [JsonIgnore] + public string? Format { get => Q("format"); set => Q("format", value); } + } + + public partial class SqlQueryRequest : PlainRequestBase + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlQuery; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + [JsonIgnore] + public string? Format { get => Q("format"); set => Q("format", value); } + + [JsonInclude] + [JsonPropertyName("catalog")] + public string? Catalog { get; set; } + + [JsonInclude] + [JsonPropertyName("columnar")] + public bool? Columnar { get; set; } + + [JsonInclude] + [JsonPropertyName("cursor")] + public string? Cursor { get; set; } + + [JsonInclude] + [JsonPropertyName("fetch_size")] + public int? FetchSize { get; set; } + + [JsonInclude] + [JsonPropertyName("filter")] + public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? Filter { get; set; } + + [JsonInclude] + [JsonPropertyName("query")] + public string? Query { get; set; } + + [JsonInclude] + [JsonPropertyName("request_timeout")] + public Elastic.Clients.Elasticsearch.Time? RequestTimeout { get; set; } + + [JsonInclude] + [JsonPropertyName("page_timeout")] + public Elastic.Clients.Elasticsearch.Time? PageTimeout { get; set; } + + [JsonInclude] + [JsonPropertyName("time_zone")] + public string? TimeZone { get; set; } + + [JsonInclude] + [JsonPropertyName("field_multi_value_leniency")] + public bool? FieldMultiValueLeniency { get; set; } + + [JsonInclude] + [JsonPropertyName("runtime_mappings")] + public Dictionary>? RuntimeMappings { get; set; } + + [JsonInclude] + [JsonPropertyName("wait_for_completion_timeout")] + public Elastic.Clients.Elasticsearch.Time? WaitForCompletionTimeout { get; set; } + + [JsonInclude] + [JsonPropertyName("params")] + public Dictionary? Params { get; set; } + + [JsonInclude] + [JsonPropertyName("keep_alive")] + public Elastic.Clients.Elasticsearch.Time? KeepAlive { get; set; } + + [JsonInclude] + [JsonPropertyName("keep_on_completion")] + public bool? KeepOnCompletion { get; set; } + + [JsonInclude] + [JsonPropertyName("index_using_frozen")] + public bool? IndexUsingFrozen { get; set; } + } + + public sealed partial class SqlQueryRequestDescriptor : RequestDescriptorBase, SqlQueryRequestParameters> + { + internal SqlQueryRequestDescriptor(Action> configure) => configure.Invoke(this); + public SqlQueryRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlQuery; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + public SqlQueryRequestDescriptor Format(string? format) => Qs("format", format); + private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? FilterValue { get; set; } + + private QueryDsl.QueryContainerDescriptor FilterDescriptor { get; set; } + + private Action> FilterDescriptorAction { get; set; } + + private string? CatalogValue { get; set; } + + private bool? ColumnarValue { get; set; } + + private string? CursorValue { get; set; } + + private int? FetchSizeValue { get; set; } + + private bool? FieldMultiValueLeniencyValue { get; set; } + + private bool? IndexUsingFrozenValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? KeepAliveValue { get; set; } + + private bool? KeepOnCompletionValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? PageTimeoutValue { get; set; } + + private Dictionary? ParamsValue { get; set; } + + private string? QueryValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? RequestTimeoutValue { get; set; } + + private Dictionary>? RuntimeMappingsValue { get; set; } + + private string? TimeZoneValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? WaitForCompletionTimeoutValue { get; set; } + + public SqlQueryRequestDescriptor Filter(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? filter) + { + FilterDescriptor = null; + FilterDescriptorAction = null; + FilterValue = filter; + return Self; + } + + public SqlQueryRequestDescriptor Filter(QueryDsl.QueryContainerDescriptor descriptor) + { + FilterValue = null; + FilterDescriptorAction = null; + FilterDescriptor = descriptor; + return Self; + } + + public SqlQueryRequestDescriptor Filter(Action> configure) + { + FilterValue = null; + FilterDescriptorAction = null; + FilterDescriptorAction = configure; + return Self; + } + + public SqlQueryRequestDescriptor Catalog(string? catalog) + { + CatalogValue = catalog; + return Self; + } + + public SqlQueryRequestDescriptor Columnar(bool? columnar = true) + { + ColumnarValue = columnar; + return Self; + } + + public SqlQueryRequestDescriptor Cursor(string? cursor) + { + CursorValue = cursor; + return Self; + } + + public SqlQueryRequestDescriptor FetchSize(int? fetchSize) + { + FetchSizeValue = fetchSize; + return Self; + } + + public SqlQueryRequestDescriptor FieldMultiValueLeniency(bool? fieldMultiValueLeniency = true) + { + FieldMultiValueLeniencyValue = fieldMultiValueLeniency; + return Self; + } + + public SqlQueryRequestDescriptor IndexUsingFrozen(bool? indexUsingFrozen = true) + { + IndexUsingFrozenValue = indexUsingFrozen; + return Self; + } + + public SqlQueryRequestDescriptor KeepAlive(Elastic.Clients.Elasticsearch.Time? keepAlive) + { + KeepAliveValue = keepAlive; + return Self; + } + + public SqlQueryRequestDescriptor KeepOnCompletion(bool? keepOnCompletion = true) + { + KeepOnCompletionValue = keepOnCompletion; + return Self; + } + + public SqlQueryRequestDescriptor PageTimeout(Elastic.Clients.Elasticsearch.Time? pageTimeout) + { + PageTimeoutValue = pageTimeout; + return Self; + } + + public SqlQueryRequestDescriptor Params(Func, FluentDictionary> selector) + { + ParamsValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public SqlQueryRequestDescriptor Query(string? query) + { + QueryValue = query; + return Self; + } + + public SqlQueryRequestDescriptor RequestTimeout(Elastic.Clients.Elasticsearch.Time? requestTimeout) + { + RequestTimeoutValue = requestTimeout; + return Self; + } + + public SqlQueryRequestDescriptor RuntimeMappings(Func>, FluentDictionary>> selector) + { + RuntimeMappingsValue = selector?.Invoke(new FluentDictionary>()); + return Self; + } + + public SqlQueryRequestDescriptor TimeZone(string? timeZone) + { + TimeZoneValue = timeZone; + return Self; + } + + public SqlQueryRequestDescriptor WaitForCompletionTimeout(Elastic.Clients.Elasticsearch.Time? waitForCompletionTimeout) + { + WaitForCompletionTimeoutValue = waitForCompletionTimeout; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FilterDescriptor is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, FilterDescriptor, options); + } + else if (FilterDescriptorAction is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor(FilterDescriptorAction), options); + } + else if (FilterValue is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, FilterValue, options); + } + + if (!string.IsNullOrEmpty(CatalogValue)) + { + writer.WritePropertyName("catalog"); + writer.WriteStringValue(CatalogValue); + } + + if (ColumnarValue.HasValue) + { + writer.WritePropertyName("columnar"); + writer.WriteBooleanValue(ColumnarValue.Value); + } + + if (!string.IsNullOrEmpty(CursorValue)) + { + writer.WritePropertyName("cursor"); + writer.WriteStringValue(CursorValue); + } + + if (FetchSizeValue.HasValue) + { + writer.WritePropertyName("fetch_size"); + writer.WriteNumberValue(FetchSizeValue.Value); + } + + if (FieldMultiValueLeniencyValue.HasValue) + { + writer.WritePropertyName("field_multi_value_leniency"); + writer.WriteBooleanValue(FieldMultiValueLeniencyValue.Value); + } + + if (IndexUsingFrozenValue.HasValue) + { + writer.WritePropertyName("index_using_frozen"); + writer.WriteBooleanValue(IndexUsingFrozenValue.Value); + } + + if (KeepAliveValue is not null) + { + writer.WritePropertyName("keep_alive"); + JsonSerializer.Serialize(writer, KeepAliveValue, options); + } + + if (KeepOnCompletionValue.HasValue) + { + writer.WritePropertyName("keep_on_completion"); + writer.WriteBooleanValue(KeepOnCompletionValue.Value); + } + + if (PageTimeoutValue is not null) + { + writer.WritePropertyName("page_timeout"); + JsonSerializer.Serialize(writer, PageTimeoutValue, options); + } + + if (ParamsValue is not null) + { + writer.WritePropertyName("params"); + JsonSerializer.Serialize(writer, ParamsValue, options); + } + + if (!string.IsNullOrEmpty(QueryValue)) + { + writer.WritePropertyName("query"); + writer.WriteStringValue(QueryValue); + } + + if (RequestTimeoutValue is not null) + { + writer.WritePropertyName("request_timeout"); + JsonSerializer.Serialize(writer, RequestTimeoutValue, options); + } + + if (RuntimeMappingsValue is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, RuntimeMappingsValue, options); + } + + if (!string.IsNullOrEmpty(TimeZoneValue)) + { + writer.WritePropertyName("time_zone"); + writer.WriteStringValue(TimeZoneValue); + } + + if (WaitForCompletionTimeoutValue is not null) + { + writer.WritePropertyName("wait_for_completion_timeout"); + JsonSerializer.Serialize(writer, WaitForCompletionTimeoutValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class SqlQueryRequestDescriptor : RequestDescriptorBase + { + internal SqlQueryRequestDescriptor(Action configure) => configure.Invoke(this); + public SqlQueryRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlQuery; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + public SqlQueryRequestDescriptor Format(string? format) => Qs("format", format); + private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? FilterValue { get; set; } + + private QueryDsl.QueryContainerDescriptor FilterDescriptor { get; set; } + + private Action FilterDescriptorAction { get; set; } + + private string? CatalogValue { get; set; } + + private bool? ColumnarValue { get; set; } + + private string? CursorValue { get; set; } + + private int? FetchSizeValue { get; set; } + + private bool? FieldMultiValueLeniencyValue { get; set; } + + private bool? IndexUsingFrozenValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? KeepAliveValue { get; set; } + + private bool? KeepOnCompletionValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? PageTimeoutValue { get; set; } + + private Dictionary? ParamsValue { get; set; } + + private string? QueryValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? RequestTimeoutValue { get; set; } + + private Dictionary>? RuntimeMappingsValue { get; set; } + + private string? TimeZoneValue { get; set; } + + private Elastic.Clients.Elasticsearch.Time? WaitForCompletionTimeoutValue { get; set; } + + public SqlQueryRequestDescriptor Filter(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? filter) + { + FilterDescriptor = null; + FilterDescriptorAction = null; + FilterValue = filter; + return Self; + } + + public SqlQueryRequestDescriptor Filter(QueryDsl.QueryContainerDescriptor descriptor) + { + FilterValue = null; + FilterDescriptorAction = null; + FilterDescriptor = descriptor; + return Self; + } + + public SqlQueryRequestDescriptor Filter(Action configure) + { + FilterValue = null; + FilterDescriptorAction = null; + FilterDescriptorAction = configure; + return Self; + } + + public SqlQueryRequestDescriptor Catalog(string? catalog) + { + CatalogValue = catalog; + return Self; + } + + public SqlQueryRequestDescriptor Columnar(bool? columnar = true) + { + ColumnarValue = columnar; + return Self; + } + + public SqlQueryRequestDescriptor Cursor(string? cursor) + { + CursorValue = cursor; + return Self; + } + + public SqlQueryRequestDescriptor FetchSize(int? fetchSize) + { + FetchSizeValue = fetchSize; + return Self; + } + + public SqlQueryRequestDescriptor FieldMultiValueLeniency(bool? fieldMultiValueLeniency = true) + { + FieldMultiValueLeniencyValue = fieldMultiValueLeniency; + return Self; + } + + public SqlQueryRequestDescriptor IndexUsingFrozen(bool? indexUsingFrozen = true) + { + IndexUsingFrozenValue = indexUsingFrozen; + return Self; + } + + public SqlQueryRequestDescriptor KeepAlive(Elastic.Clients.Elasticsearch.Time? keepAlive) + { + KeepAliveValue = keepAlive; + return Self; + } + + public SqlQueryRequestDescriptor KeepOnCompletion(bool? keepOnCompletion = true) + { + KeepOnCompletionValue = keepOnCompletion; + return Self; + } + + public SqlQueryRequestDescriptor PageTimeout(Elastic.Clients.Elasticsearch.Time? pageTimeout) + { + PageTimeoutValue = pageTimeout; + return Self; + } + + public SqlQueryRequestDescriptor Params(Func, FluentDictionary> selector) + { + ParamsValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public SqlQueryRequestDescriptor Query(string? query) + { + QueryValue = query; + return Self; + } + + public SqlQueryRequestDescriptor RequestTimeout(Elastic.Clients.Elasticsearch.Time? requestTimeout) + { + RequestTimeoutValue = requestTimeout; + return Self; + } + + public SqlQueryRequestDescriptor RuntimeMappings(Func>, FluentDictionary>> selector) + { + RuntimeMappingsValue = selector?.Invoke(new FluentDictionary>()); + return Self; + } + + public SqlQueryRequestDescriptor TimeZone(string? timeZone) + { + TimeZoneValue = timeZone; + return Self; + } + + public SqlQueryRequestDescriptor WaitForCompletionTimeout(Elastic.Clients.Elasticsearch.Time? waitForCompletionTimeout) + { + WaitForCompletionTimeoutValue = waitForCompletionTimeout; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FilterDescriptor is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, FilterDescriptor, options); + } + else if (FilterDescriptorAction is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor(FilterDescriptorAction), options); + } + else if (FilterValue is not null) + { + writer.WritePropertyName("filter"); + JsonSerializer.Serialize(writer, FilterValue, options); + } + + if (!string.IsNullOrEmpty(CatalogValue)) + { + writer.WritePropertyName("catalog"); + writer.WriteStringValue(CatalogValue); + } + + if (ColumnarValue.HasValue) + { + writer.WritePropertyName("columnar"); + writer.WriteBooleanValue(ColumnarValue.Value); + } + + if (!string.IsNullOrEmpty(CursorValue)) + { + writer.WritePropertyName("cursor"); + writer.WriteStringValue(CursorValue); + } + + if (FetchSizeValue.HasValue) + { + writer.WritePropertyName("fetch_size"); + writer.WriteNumberValue(FetchSizeValue.Value); + } + + if (FieldMultiValueLeniencyValue.HasValue) + { + writer.WritePropertyName("field_multi_value_leniency"); + writer.WriteBooleanValue(FieldMultiValueLeniencyValue.Value); + } + + if (IndexUsingFrozenValue.HasValue) + { + writer.WritePropertyName("index_using_frozen"); + writer.WriteBooleanValue(IndexUsingFrozenValue.Value); + } + + if (KeepAliveValue is not null) + { + writer.WritePropertyName("keep_alive"); + JsonSerializer.Serialize(writer, KeepAliveValue, options); + } + + if (KeepOnCompletionValue.HasValue) + { + writer.WritePropertyName("keep_on_completion"); + writer.WriteBooleanValue(KeepOnCompletionValue.Value); + } + + if (PageTimeoutValue is not null) + { + writer.WritePropertyName("page_timeout"); + JsonSerializer.Serialize(writer, PageTimeoutValue, options); + } + + if (ParamsValue is not null) + { + writer.WritePropertyName("params"); + JsonSerializer.Serialize(writer, ParamsValue, options); + } + + if (!string.IsNullOrEmpty(QueryValue)) + { + writer.WritePropertyName("query"); + writer.WriteStringValue(QueryValue); + } + + if (RequestTimeoutValue is not null) + { + writer.WritePropertyName("request_timeout"); + JsonSerializer.Serialize(writer, RequestTimeoutValue, options); + } + + if (RuntimeMappingsValue is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, RuntimeMappingsValue, options); + } + + if (!string.IsNullOrEmpty(TimeZoneValue)) + { + writer.WritePropertyName("time_zone"); + writer.WriteStringValue(TimeZoneValue); + } + + if (WaitForCompletionTimeoutValue is not null) + { + writer.WritePropertyName("wait_for_completion_timeout"); + JsonSerializer.Serialize(writer, WaitForCompletionTimeoutValue, options); + } + + writer.WriteEndObject(); + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryResponse.g.cs new file mode 100644 index 00000000000..abc36f529ea --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Sql/SqlQueryResponse.g.cs @@ -0,0 +1,51 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class SqlQueryResponse : ResponseBase + { + [JsonInclude] + [JsonPropertyName("columns")] + public IReadOnlyCollection? Columns { get; init; } + + [JsonInclude] + [JsonPropertyName("cursor")] + public string? Cursor { get; init; } + + [JsonInclude] + [JsonPropertyName("id")] + public string? Id { get; init; } + + [JsonInclude] + [JsonPropertyName("is_partial")] + public bool? IsPartial { get; init; } + + [JsonInclude] + [JsonPropertyName("is_running")] + public bool? IsRunning { get; init; } + + [JsonInclude] + [JsonPropertyName("rows")] + public IReadOnlyCollection> Rows { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.Sql.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.Sql.g.cs new file mode 100644 index 00000000000..0cf4e37e538 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.Sql.g.cs @@ -0,0 +1,171 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using System; +using System.Threading; +using System.Threading.Tasks; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public class SqlNamespace : NamespacedClientProxy + { + internal SqlNamespace(ElasticsearchClient client) : base(client) + { + } + + public SqlClearCursorResponse ClearCursor(SqlClearCursorRequest request) + { + request.BeforeRequest(); + return DoRequest(request); + } + + public Task ClearCursorAsync(SqlClearCursorRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync(request, cancellationToken); + } + + public SqlClearCursorResponse ClearCursor(Action configureRequest = null) + { + var descriptor = new SqlClearCursorRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest(descriptor); + } + + public Task ClearCursorAsync(Action configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new SqlClearCursorRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync(descriptor); + } + + public SqlDeleteAsyncResponse DeleteAsyncSearch(SqlDeleteAsyncRequest request) + { + request.BeforeRequest(); + return DoRequest(request); + } + + public Task DeleteAsyncSearchAsync(SqlDeleteAsyncRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync(request, cancellationToken); + } + + public SqlDeleteAsyncResponse DeleteAsyncSearch(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null) + { + var descriptor = new SqlDeleteAsyncRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest(descriptor); + } + + public Task DeleteAsyncSearchAsync(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new SqlDeleteAsyncRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync(descriptor); + } + + public SqlGetAsyncResponse GetAsyncSearch(SqlGetAsyncRequest request) + { + request.BeforeRequest(); + return DoRequest(request); + } + + public Task GetAsyncSearchAsync(SqlGetAsyncRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync(request, cancellationToken); + } + + public SqlGetAsyncResponse GetAsyncSearch(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null) + { + var descriptor = new SqlGetAsyncRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest(descriptor); + } + + public Task GetAsyncSearchAsync(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new SqlGetAsyncRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync(descriptor); + } + + public SqlGetAsyncStatusResponse GetAsyncSearchStatus(SqlGetAsyncStatusRequest request) + { + request.BeforeRequest(); + return DoRequest(request); + } + + public Task GetAsyncSearchStatusAsync(SqlGetAsyncStatusRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync(request, cancellationToken); + } + + public SqlGetAsyncStatusResponse GetAsyncSearchStatus(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null) + { + var descriptor = new SqlGetAsyncStatusRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest(descriptor); + } + + public Task GetAsyncSearchStatusAsync(Elastic.Clients.Elasticsearch.Id id, Action configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new SqlGetAsyncStatusRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync(descriptor); + } + + public SqlQueryResponse Query(SqlQueryRequest request) + { + request.BeforeRequest(); + return DoRequest(request); + } + + public Task QueryAsync(SqlQueryRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync(request, cancellationToken); + } + + public SqlQueryResponse Query(Action configureRequest = null) + { + var descriptor = new SqlQueryRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest(descriptor); + } + + public Task QueryAsync(Action configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new SqlQueryRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync(descriptor); + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs index f92174c1e36..a0299cf153a 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs @@ -19,6 +19,7 @@ using Elastic.Clients.Elasticsearch.Cluster; using Elastic.Clients.Elasticsearch.Eql; using Elastic.Clients.Elasticsearch.IndexManagement; +using Elastic.Clients.Elasticsearch.Sql; using System; using System.Threading; using System.Threading.Tasks; @@ -36,12 +37,15 @@ public partial class ElasticsearchClient public IndexManagementNamespace IndexManagement { get; private set; } + public SqlNamespace Sql { get; private set; } + private partial void SetupNamespaces() { AsyncSearch = new AsyncSearchNamespace(this); Cluster = new ClusterNamespace(this); Eql = new EqlNamespace(this); IndexManagement = new IndexManagementNamespace(this); + Sql = new SqlNamespace(this); } public BulkResponse Bulk(BulkRequest request) diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Sql/Column.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Sql/Column.g.cs new file mode 100644 index 00000000000..ca3454f9e3a --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Sql/Column.g.cs @@ -0,0 +1,37 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.Sql +{ + public partial class Column + { + [JsonInclude] + [JsonPropertyName("name")] + public string Name { get; init; } + + [JsonInclude] + [JsonPropertyName("type")] + public string Type { get; init; } + } +} \ No newline at end of file diff --git a/tests/Tests/Eql/EqlSearchApiCoordinatedTests.cs b/tests/Tests/Eql/EqlSearchApiCoordinatedTests.cs index 5111a5ac43c..fca6c372e40 100644 --- a/tests/Tests/Eql/EqlSearchApiCoordinatedTests.cs +++ b/tests/Tests/Eql/EqlSearchApiCoordinatedTests.cs @@ -105,8 +105,6 @@ [I] public async Task EqlSearchStatusResponse() => await Assert +{ + private static readonly string SqlQuery = + $@"SELECT type, name, startedOn, numberOfCommits +FROM {TestValueHelper.ProjectsIndex} +WHERE type = '{Project.TypeName}' +ORDER BY numberOfContributors DESC"; + + private string _currentCursor = "default-for-unit-tests"; + + public ClearSqlCursorApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + + protected override object ExpectJson => new { cursor = _currentCursor }; + protected override int ExpectStatusCode => 200; + + protected override Action Fluent => d => d.Cursor(_currentCursor); + + protected override HttpMethod HttpMethod => HttpMethod.POST; + + protected override SqlClearCursorRequest Initializer => new() + { + Cursor = _currentCursor, + }; + + protected override string ExpectedUrlPathAndQuery => $"/_sql/close"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.Sql.ClearCursor(f), + (client, f) => client.Sql.ClearCursorAsync(f), + (client, r) => client.Sql.ClearCursor(r), + (client, r) => client.Sql.ClearCursorAsync(r) + ); + + protected override void OnBeforeCall(ElasticsearchClient client) + { + var sqlQueryResponse = Client.Sql.Query(q => q.Query(SqlQuery).FetchSize(5)); + if (!sqlQueryResponse.IsValid) + throw new Exception("Setup: Initial scroll failed."); + + _currentCursor = sqlQueryResponse.Cursor ?? _currentCursor; + } + + protected override void ExpectResponse(SqlClearCursorResponse response) => + response.Succeeded.Should().BeTrue("succeeded property on response"); +} diff --git a/tests/Tests/Sql/SqlSearchApiCoordinatedTests.cs b/tests/Tests/Sql/SqlSearchApiCoordinatedTests.cs new file mode 100644 index 00000000000..42dd8397706 --- /dev/null +++ b/tests/Tests/Sql/SqlSearchApiCoordinatedTests.cs @@ -0,0 +1,159 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// 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. + +using System.Threading.Tasks; +using Tests.Core.Extensions; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; +using Elastic.Clients.Elasticsearch.Sql; +using System; + +namespace Tests.Sql; + +public class SqlSearchApiCoordinatedTests : CoordinatedIntegrationTestBase +{ + private const string DeleteStep = nameof(DeleteStep); + private const string GetStep = nameof(GetStep); + private const string StatusStep = nameof(StatusStep); + private const string SubmitStep = nameof(SubmitStep); + private const string WaitStep = nameof(WaitStep); + + private static readonly string SqlQuery = + $@"SELECT type, name, startedOn, numberOfCommits +FROM {TestValueHelper.ProjectsIndex} +WHERE type = '{Project.TypeName}' +ORDER BY numberOfContributors DESC"; + + public SqlSearchApiCoordinatedTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage, testOnlyOne: true) + { + { + SubmitStep, u => + u.Calls( + _ => new SqlQueryRequest { Query = SqlQuery, FetchSize = 5, WaitForCompletionTimeout = "0s" }, + (_, d) => d + .Query(SqlQuery) + .FetchSize(5) + .WaitForCompletionTimeout("0s"), + (_, c, f) => c.Sql.Query(f), + (_, c, f) => c.Sql.QueryAsync(f), + (_, c, r) => c.Sql.Query(r), + (_, c, r) => c.Sql.QueryAsync(r), + (r, values) => values.ExtendedValue("id", r.Id) + ) + }, + { + StatusStep, u => + u.Calls( + v => new SqlGetAsyncStatusRequest(v), + (v, d) => d, + (v, c, f) => c.Sql.GetAsyncSearchStatus(v, f), + (v, c, f) => c.Sql.GetAsyncSearchStatusAsync(v, f), + (v, c, r) => c.Sql.GetAsyncSearchStatus(r), + (v, c, r) => c.Sql.GetAsyncSearchStatusAsync(r), + uniqueValueSelector: values => values.ExtendedValue("id") + ) + }, + { + // allows the search to complete + WaitStep, u => u.Call(async (_, c) => + { + // wait for the search to complete + var complete = false; + var count = 0; + + while (!complete && count++ < 10) + { + await Task.Delay(100); + var status = await c.Sql.GetAsyncSearchStatusAsync(u.Usage.CallUniqueValues.ExtendedValue("id")); + complete = !status.IsRunning && status.CompletionStatus.HasValue; + } + }) + }, + { + GetStep, u => + u.Calls( + v => new SqlGetAsyncRequest(v), + (_, d) => d, + (v, c, f) => c.Sql.GetAsyncSearch(v, f), + (v, c, f) => c.Sql.GetAsyncSearchAsync(v, f), + (_, c, r) => c.Sql.GetAsyncSearch(r), + (_, c, r) => c.Sql.GetAsyncSearchAsync(r), + uniqueValueSelector: values => values.ExtendedValue("id") + ) + }, + { + DeleteStep, u => + u.Calls( + v => new SqlDeleteAsyncRequest(v), + (_, d) => d, + (v, c, f) => c.Sql.DeleteAsyncSearch(v, f), + (v, c, f) => c.Sql.DeleteAsyncSearchAsync(v, f), + (_, c, r) => c.Sql.DeleteAsyncSearch(r), + (_, c, r) => c.Sql.DeleteAsyncSearchAsync(r), + uniqueValueSelector: values => values.ExtendedValue("id") + ) + } + }) { } + + [I] public async Task SqlSearchResponse() => await Assert(SubmitStep, r => + { + r.ShouldBeValid(); + r.Id.Should().NotBeNullOrEmpty(); + r.IsPartial.Should().BeTrue(); + r.IsRunning.Should().BeTrue(); + }); + + [I] public async Task SqlSearchStatusResponse() => await Assert(StatusStep, r => + { + r.ShouldBeValid(); + r.Id.Should().NotBeNullOrEmpty(); + + if (r.CompletionStatus.HasValue) + { + r.IsPartial.Should().BeFalse(); + r.IsRunning.Should().BeFalse(); + } + else + { + r.IsPartial.Should().BeTrue(); + r.IsRunning.Should().BeTrue(); + r.StartTimeInMillis.Should().BeGreaterThan(0); + } + + r.ExpirationTimeInMillis.Should().BeGreaterThan(0); + }); + + [I] public async Task SqlGetResponse() => await Assert(GetStep, r => + { + r.ShouldBeValid(); + r.IsPartial.Should().BeFalse(); + r.IsRunning.Should().BeFalse(); + + r.Cursor.Should().NotBeNullOrWhiteSpace("response cursor"); + r.Rows.Should().NotBeNullOrEmpty(); + r.Columns.Should().NotBeNullOrEmpty().And.HaveCount(4); + foreach (var c in r.Columns) + { + c.Name.Should().NotBeNullOrWhiteSpace("column name"); + c.Type.Should().NotBeNullOrWhiteSpace("column type"); + } + foreach (var row in r.Rows) + { + row.Should().NotBeNull().And.HaveCount(4); + + var type = row[0].As().Should().NotBeNullOrWhiteSpace("a type returned null"); + var name = row[1].As().Should().NotBeNullOrWhiteSpace("a name returned null"); + var date = row[2].As().Should().BeAfter(default); + var numberOfCommits = row[3].As().Should().BePositive(); + } + }); + + [I] public async Task SqlDeleteResponse() => await Assert(DeleteStep, r => + { + r.ShouldBeValid(); + r.Acknowledged.Should().BeTrue(); + }); +}