Skip to content

[Backport 8.0] Container variant improvements #6461

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
Jun 21, 2022
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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,16 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;


namespace Elastic.Clients.Elasticsearch.QueryDsl
{
// TODO - Generate more of these?
// TODO - Generate these
public partial class TermQuery
{
public static implicit operator QueryContainer(TermQuery termQuery) => new(termQuery);
public static implicit operator QueryContainer(TermQuery termQuery) => QueryContainer.Term(termQuery);
}

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 static implicit operator QueryContainer(MatchAllQuery matchAllQuery) => QueryContainer.MatchAll(matchAllQuery);
}
}

namespace Elastic.Clients.Elasticsearch
{
// Stubs until we generate these - Allows the code to compile so we can identify real errors.

public partial class HttpHeaders : Dictionary<string, Union<string, IReadOnlyCollection<string>>>
{
}

public partial class Metadata : Dictionary<string, object>
{
}

//public partial class RuntimeFields : Dictionary<Field, RuntimeField>
//{
//}

public partial class ApplicationsPrivileges : Dictionary<Name, ResourcePrivileges>
{
}

public partial class Privileges : Dictionary<string, bool>
{
}

public partial class ResourcePrivileges : Dictionary<Name, Privileges>
{
}

// TODO: Implement properly
[JsonConverter(typeof(PercentageConverter))]
public partial class Percentage
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace Elastic.Clients.Elasticsearch.Aggregations
{
[JsonConverter(typeof(AggregationContainerConverter))]
public partial class AggregationContainer : IContainer
public partial class AggregationContainer
{
public AggregationContainer(AggregationBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant));
internal AggregationBase Variant { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,12 @@ public override void Write(Utf8JsonWriter writer, DateHistogramAggregation value
}

[JsonConverter(typeof(DateHistogramAggregationConverter))]
public partial class DateHistogramAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByContainerVariant
public partial class DateHistogramAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByVariant
{
public DateHistogramAggregation(string name) : base(name)
{
}

[JsonIgnore]
string TransformManagement.IPivotGroupByContainerVariant.PivotGroupByContainerVariantName => "date_histogram";
[JsonInclude]
[JsonPropertyName("calendar_interval")]
public Elastic.Clients.Elasticsearch.Aggregations.CalendarInterval? CalendarInterval { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ public override void Write(Utf8JsonWriter writer, HistogramAggregation value, Js
}

[JsonConverter(typeof(HistogramAggregationConverter))]
public partial class HistogramAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByContainerVariant
public partial class HistogramAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByVariant
{
public HistogramAggregation(string name) : base(name)
{
}

[JsonIgnore]
string TransformManagement.IPivotGroupByContainerVariant.PivotGroupByContainerVariantName => "histogram";
[JsonInclude]
[JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Field? Field { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,31 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Aggregations
{
public interface IInferenceConfigContainerVariant
public interface IInferenceConfigVariant
{
string InferenceConfigContainerVariantName { get; }
}

[JsonConverter(typeof(InferenceConfigContainerConverter))]
public partial class InferenceConfigContainer : IContainer
public partial class InferenceConfigContainer
{
public InferenceConfigContainer(IInferenceConfigContainerVariant variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant));
internal IInferenceConfigContainerVariant Variant { get; }
public InferenceConfigContainer(string variantName, IInferenceConfigVariant variant)
{
if (variantName is null)
throw new ArgumentNullException(nameof(variantName));
if (variant is null)
throw new ArgumentNullException(nameof(variant));
if (string.IsNullOrWhiteSpace(variantName))
throw new ArgumentException("Variant name must not be empty or whitespace.");
VariantName = variantName;
Variant = variant;
}

internal IInferenceConfigVariant Variant { get; }

internal string VariantName { get; }

public static InferenceConfigContainer Classification(Elastic.Clients.Elasticsearch.Ml.ClassificationInferenceOptions variant) => new InferenceConfigContainer("classification", variant);
public static InferenceConfigContainer Regression(Elastic.Clients.Elasticsearch.Ml.RegressionInferenceOptions variant) => new InferenceConfigContainer("regression", variant);
}

internal sealed class InferenceConfigContainerConverter : JsonConverter<InferenceConfigContainer>
Expand All @@ -51,13 +66,13 @@ public override InferenceConfigContainer Read(ref Utf8JsonReader reader, Type ty
if (propertyName == "classification")
{
var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Ml.ClassificationInferenceOptions?>(ref reader, options);
return new InferenceConfigContainer(variant);
return new InferenceConfigContainer(propertyName, variant);
}

if (propertyName == "regression")
{
var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Ml.RegressionInferenceOptions?>(ref reader, options);
return new InferenceConfigContainer(variant);
return new InferenceConfigContainer(propertyName, variant);
}

throw new JsonException();
Expand All @@ -66,14 +81,14 @@ public override InferenceConfigContainer Read(ref Utf8JsonReader reader, Type ty
public override void Write(Utf8JsonWriter writer, InferenceConfigContainer value, JsonSerializerOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName(value.Variant.InferenceConfigContainerVariantName);
switch (value.Variant)
writer.WritePropertyName(value.VariantName);
switch (value.VariantName)
{
case Elastic.Clients.Elasticsearch.Ml.ClassificationInferenceOptions variant:
JsonSerializer.Serialize(writer, variant, options);
case "classification":
JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.Ml.ClassificationInferenceOptions>(writer, (Elastic.Clients.Elasticsearch.Ml.ClassificationInferenceOptions)value.Variant, options);
break;
case Elastic.Clients.Elasticsearch.Ml.RegressionInferenceOptions variant:
JsonSerializer.Serialize(writer, variant, options);
case "regression":
JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.Ml.RegressionInferenceOptions>(writer, (Elastic.Clients.Elasticsearch.Ml.RegressionInferenceOptions)value.Variant, options);
break;
}

Expand Down Expand Up @@ -111,11 +126,11 @@ private void Set<T>(Action<T> descriptorAction, string variantName)
Descriptor = descriptor;
}

private void Set(IInferenceConfigContainerVariant variant, string variantName)
private void Set(IInferenceConfigVariant variant, string variantName)
{
if (ContainsVariant)
throw new Exception("TODO");
Container = new InferenceConfigContainer(variant);
Container = new InferenceConfigContainer(variantName, variant);
ContainedVariantName = variantName;
ContainsVariant = true;
}
Expand Down Expand Up @@ -176,11 +191,11 @@ private void Set<T>(Action<T> descriptorAction, string variantName)
Descriptor = descriptor;
}

private void Set(IInferenceConfigContainerVariant variant, string variantName)
private void Set(IInferenceConfigVariant variant, string variantName)
{
if (ContainsVariant)
throw new Exception("TODO");
Container = new InferenceConfigContainer(variant);
Container = new InferenceConfigContainer(variantName, variant);
ContainedVariantName = variantName;
ContainsVariant = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,12 @@ public override void Write(Utf8JsonWriter writer, TermsAggregation value, JsonSe
}

[JsonConverter(typeof(TermsAggregationConverter))]
public partial class TermsAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByContainerVariant
public partial class TermsAggregation : BucketAggregationBase, TransformManagement.IPivotGroupByVariant
{
public TermsAggregation(string name) : base(name)
{
}

[JsonIgnore]
string TransformManagement.IPivotGroupByContainerVariant.PivotGroupByContainerVariantName => "terms";
[JsonInclude]
[JsonPropertyName("collect_mode")]
public Elastic.Clients.Elasticsearch.Aggregations.TermsAggregationCollectMode? CollectMode { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class AppendProcessor : ProcessorBase, IProcessorContainerVariant
public partial class AppendProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "append";
[JsonInclude]
[JsonPropertyName("allow_duplicates")]
public bool? AllowDuplicates { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class AttachmentProcessor : ProcessorBase, IProcessorContainerVariant
public partial class AttachmentProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "attachment";
[JsonInclude]
[JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Field Field { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class BytesProcessor : ProcessorBase, IProcessorContainerVariant
public partial class BytesProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "bytes";
[JsonInclude]
[JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Field Field { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class CircleProcessor : ProcessorBase, IProcessorContainerVariant
public partial class CircleProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "circle";
[JsonInclude]
[JsonPropertyName("error_distance")]
public double ErrorDistance { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class ConvertProcessor : ProcessorBase, IProcessorContainerVariant
public partial class ConvertProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "convert";
[JsonInclude]
[JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Field Field { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class CsvProcessor : ProcessorBase, IProcessorContainerVariant
public partial class CsvProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "csv";
[JsonInclude]
[JsonPropertyName("description")]
public string? Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
public partial class DateIndexNameProcessor : ProcessorBase, IProcessorContainerVariant
public partial class DateIndexNameProcessor : ProcessorBase, IProcessorVariant
{
[JsonIgnore]
string IProcessorContainerVariant.ProcessorContainerVariantName => "date_index_name";
[JsonInclude]
[JsonPropertyName("date_formats")]
public IEnumerable<string> DateFormats { get; set; }
Expand Down
Loading