Skip to content
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

Fixing composite aggregations with correct parameters #967

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@
@JsonpDeserializable
public class CompositeAggregationSource implements JsonpSerializable {
@Nullable
private final TermsAggregation terms;
private final CompositeTermsAggregationSource terms;

@Nullable
private final HistogramAggregation histogram;
private final CompositeHistogramAggregationSource histogram;

@Nullable
private final DateHistogramAggregation dateHistogram;
private final CompositeDateHistogramAggregationSource dateHistogram;

@Nullable
private final GeoTileGridAggregation geotileGrid;

// ---------------------------------------------------------------------------------------------
private final CompositeGeoTileGridAggregationSource geotileGrid;

private CompositeAggregationSource(Builder builder) {

Expand All @@ -79,31 +77,31 @@ public static CompositeAggregationSource of(Function<Builder, ObjectBuilder<Comp
* API name: {@code terms}
*/
@Nullable
public final TermsAggregation terms() {
public final CompositeTermsAggregationSource terms() {
return this.terms;
}

/**
* API name: {@code histogram}
*/
@Nullable
public final HistogramAggregation histogram() {
public final CompositeHistogramAggregationSource histogram() {
return this.histogram;
}

/**
* API name: {@code date_histogram}
*/
@Nullable
public final DateHistogramAggregation dateHistogram() {
public final CompositeDateHistogramAggregationSource dateHistogram() {
return this.dateHistogram;
}

/**
* API name: {@code geotile_grid}
*/
@Nullable
public final GeoTileGridAggregation geotileGrid() {
public final CompositeGeoTileGridAggregationSource geotileGrid() {
return this.geotileGrid;
}

Expand Down Expand Up @@ -141,83 +139,87 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

}

// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link CompositeAggregationSource}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CompositeAggregationSource> {
@Nullable
private TermsAggregation terms;
private CompositeTermsAggregationSource terms;

@Nullable
private HistogramAggregation histogram;
private CompositeHistogramAggregationSource histogram;

@Nullable
private DateHistogramAggregation dateHistogram;
private CompositeDateHistogramAggregationSource dateHistogram;

@Nullable
private GeoTileGridAggregation geotileGrid;
private CompositeGeoTileGridAggregationSource geotileGrid;

/**
* API name: {@code terms}
*/
public final Builder terms(@Nullable TermsAggregation value) {
public final Builder terms(@Nullable CompositeTermsAggregationSource value) {
this.terms = value;
return this;
}

/**
* API name: {@code terms}
*/
public final Builder terms(Function<TermsAggregation.Builder, ObjectBuilder<TermsAggregation>> fn) {
return this.terms(fn.apply(new TermsAggregation.Builder()).build());
public final Builder terms(Function<CompositeTermsAggregationSource.Builder, ObjectBuilder<CompositeTermsAggregationSource>> fn) {
return this.terms(fn.apply(new CompositeTermsAggregationSource.Builder()).build());
}

/**
* API name: {@code histogram}
*/
public final Builder histogram(@Nullable HistogramAggregation value) {
public final Builder histogram(@Nullable CompositeHistogramAggregationSource value) {
this.histogram = value;
return this;
}

/**
* API name: {@code histogram}
*/
public final Builder histogram(Function<HistogramAggregation.Builder, ObjectBuilder<HistogramAggregation>> fn) {
return this.histogram(fn.apply(new HistogramAggregation.Builder()).build());
public final Builder histogram(
Function<CompositeHistogramAggregationSource.Builder, ObjectBuilder<CompositeHistogramAggregationSource>> fn
) {
return this.histogram(fn.apply(new CompositeHistogramAggregationSource.Builder()).build());
}

/**
* API name: {@code date_histogram}
*/
public final Builder dateHistogram(@Nullable DateHistogramAggregation value) {
public final Builder dateHistogram(@Nullable CompositeDateHistogramAggregationSource value) {
this.dateHistogram = value;
return this;
}

/**
* API name: {@code date_histogram}
*/
public final Builder dateHistogram(Function<DateHistogramAggregation.Builder, ObjectBuilder<DateHistogramAggregation>> fn) {
return this.dateHistogram(fn.apply(new DateHistogramAggregation.Builder()).build());
public final Builder dateHistogram(
Function<CompositeDateHistogramAggregationSource.Builder, ObjectBuilder<CompositeDateHistogramAggregationSource>> fn
) {
return this.dateHistogram(fn.apply(new CompositeDateHistogramAggregationSource.Builder()).build());
}

/**
* API name: {@code geotile_grid}
*/
public final Builder geotileGrid(@Nullable GeoTileGridAggregation value) {
public final Builder geotileGrid(@Nullable CompositeGeoTileGridAggregationSource value) {
this.geotileGrid = value;
return this;
}

/**
* API name: {@code geotile_grid}
*/
public final Builder geotileGrid(Function<GeoTileGridAggregation.Builder, ObjectBuilder<GeoTileGridAggregation>> fn) {
return this.geotileGrid(fn.apply(new GeoTileGridAggregation.Builder()).build());
public final Builder geotileGrid(
Function<CompositeGeoTileGridAggregationSource.Builder, ObjectBuilder<CompositeGeoTileGridAggregationSource>> fn
) {
return this.geotileGrid(fn.apply(new CompositeGeoTileGridAggregationSource.Builder()).build());
}

/**
Expand Down Expand Up @@ -245,11 +247,10 @@ public CompositeAggregationSource build() {

protected static void setupCompositeAggregationSourceDeserializer(ObjectDeserializer<CompositeAggregationSource.Builder> op) {

op.add(Builder::terms, TermsAggregation._DESERIALIZER, "terms");
op.add(Builder::histogram, HistogramAggregation._DESERIALIZER, "histogram");
op.add(Builder::dateHistogram, DateHistogramAggregation._DESERIALIZER, "date_histogram");
op.add(Builder::geotileGrid, GeoTileGridAggregation._DESERIALIZER, "geotile_grid");

op.add(Builder::terms, CompositeTermsAggregationSource._DESERIALIZER, "terms");
op.add(Builder::histogram, CompositeHistogramAggregationSource._DESERIALIZER, "histogram");
op.add(Builder::dateHistogram, CompositeDateHistogramAggregationSource._DESERIALIZER, "date_histogram");
op.add(Builder::geotileGrid, CompositeGeoTileGridAggregationSource._DESERIALIZER, "geotile_grid");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.client.opensearch._types.aggregations;

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.opensearch._types.Time;
import org.opensearch.client.util.ObjectBuilder;

public class CompositeDateHistogramAggregationSource extends CompositeValuesSource {

@Nullable
private final Time calendarInterval;

@Nullable
private final Time fixedInterval;

private final long offset;
VachaShah marked this conversation as resolved.
Show resolved Hide resolved

private final String zoneId;
VachaShah marked this conversation as resolved.
Show resolved Hide resolved

private CompositeDateHistogramAggregationSource(Builder builder) {
super(builder);
this.calendarInterval = builder.calendarInterval;
this.fixedInterval = builder.fixedInterval;
this.offset = builder.offset;
this.zoneId = builder.zoneId;
}

public static CompositeDateHistogramAggregationSource of(Function<Builder, ObjectBuilder<CompositeDateHistogramAggregationSource>> fn) {
return fn.apply(new Builder()).build();
}

/**
* API name: {@code calendar_interval}
*/
@Nullable
public final Time calendarInterval() {
return this.calendarInterval;
}

/**
* API name: {@code fixed_interval}
*/
@Nullable
public final Time fixedInterval() {
return this.fixedInterval;
}

/**
* Required - API name: {@code offset}
*/
public final long offset() {
return this.offset;

}

/**
* Required - API name: {@code zone_id}
*/
public final String zoneId() {
return this.zoneId;
}

/**
* Serialize this object to JSON.
*/
@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
super.serializeInternal(generator, mapper);
if (this.calendarInterval != null) {
generator.writeKey("calendar_interval");
this.calendarInterval.serialize(generator, mapper);

}
if (this.fixedInterval != null) {
generator.writeKey("fixed_interval");
this.fixedInterval.serialize(generator, mapper);

}
generator.writeKey("offset");
generator.write(this.offset);

generator.writeKey("zone_id");
generator.write(this.zoneId);
}

/**
* Builder for {@link CompositeDateHistogramAggregationSource}.
*/

public static class Builder extends CompositeValuesSource.AbstractBuilder<Builder>
implements
ObjectBuilder<CompositeDateHistogramAggregationSource> {

@Nullable
private Time calendarInterval;

@Nullable
private Time fixedInterval;

private long offset;
VachaShah marked this conversation as resolved.
Show resolved Hide resolved

private String zoneId;
VachaShah marked this conversation as resolved.
Show resolved Hide resolved

/**
* API name: {@code calendar_interval}
*/
public final Builder calendarInterval(@Nullable Time value) {
this.calendarInterval = value;
return this;
}

/**
* API name: {@code fixed_interval}
*/
public final Builder fixedInterval(@Nullable Time value) {
this.fixedInterval = value;
return this;
}

/**
* Required - API name: {@code offset}
*/
public final Builder offset(long value) {
this.offset = value;
return this;
}

/**
* Required - API name: {@code zone_id}
*/

public final Builder zoneId(String value) {
this.zoneId = value;
return this;
}

/**
* Builds a {@link CompositeDateHistogramAggregationSource}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public CompositeDateHistogramAggregationSource build() {
_checkSingleUse();

return new CompositeDateHistogramAggregationSource(this);
}

@Override
protected Builder self() {
return this;
}
}

/**
* Json deserializer for {@link CompositeDateHistogramAggregationSource}
*/
public static final JsonpDeserializer<CompositeDateHistogramAggregationSource> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
CompositeDateHistogramAggregationSource::setupCompositeDateHistogramAggregationSourceDeserializer
);

protected static void setupCompositeDateHistogramAggregationSourceDeserializer(
ObjectDeserializer<CompositeDateHistogramAggregationSource.Builder> op
) {
CompositeValuesSource.setupCompositeValuesSourceDeserializer(op);
op.add(Builder::calendarInterval, Time._DESERIALIZER, "calendar_interval");
op.add(Builder::fixedInterval, Time._DESERIALIZER, "fixed_interval");
op.add(Builder::offset, JsonpDeserializer.longDeserializer(), "offset");
op.add(Builder::zoneId, JsonpDeserializer.stringDeserializer(), "time_zone");
}

}
Loading
Loading