|
@@ -34,6 +34,7 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
|
|
|
static final ParseField PROBABILITY = new ParseField("probability");
|
|
|
static final ParseField SEED = new ParseField("seed");
|
|
|
+ static final ParseField SHARD_SEED = new ParseField("shard_seed");
|
|
|
|
|
|
public static final ObjectParser<RandomSamplerAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(
|
|
|
RandomSamplerAggregationBuilder.NAME,
|
|
@@ -41,10 +42,12 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
);
|
|
|
static {
|
|
|
PARSER.declareInt(RandomSamplerAggregationBuilder::setSeed, SEED);
|
|
|
+ PARSER.declareInt(RandomSamplerAggregationBuilder::setShardSeed, SHARD_SEED);
|
|
|
PARSER.declareDouble(RandomSamplerAggregationBuilder::setProbability, PROBABILITY);
|
|
|
}
|
|
|
|
|
|
private int seed = Randomness.get().nextInt();
|
|
|
+ private Integer shardSeed;
|
|
|
private double p;
|
|
|
|
|
|
public RandomSamplerAggregationBuilder(String name) {
|
|
@@ -67,10 +70,18 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public RandomSamplerAggregationBuilder setShardSeed(int shardSeed) {
|
|
|
+ this.shardSeed = shardSeed;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public RandomSamplerAggregationBuilder(StreamInput in) throws IOException {
|
|
|
super(in);
|
|
|
this.p = in.readDouble();
|
|
|
this.seed = in.readInt();
|
|
|
+ if (in.getTransportVersion().onOrAfter(TransportVersions.RANDOM_AGG_SHARD_SEED)) {
|
|
|
+ this.shardSeed = in.readOptionalInt();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
protected RandomSamplerAggregationBuilder(
|
|
@@ -81,12 +92,16 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
super(clone, factoriesBuilder, metadata);
|
|
|
this.p = clone.p;
|
|
|
this.seed = clone.seed;
|
|
|
+ this.shardSeed = clone.shardSeed;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
|
|
out.writeDouble(p);
|
|
|
out.writeInt(seed);
|
|
|
+ if (out.getTransportVersion().onOrAfter(TransportVersions.RANDOM_AGG_SHARD_SEED)) {
|
|
|
+ out.writeOptionalInt(shardSeed);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void recursivelyCheckSubAggs(Collection<AggregationBuilder> builders, Consumer<AggregationBuilder> aggregationCheck) {
|
|
@@ -128,7 +143,7 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
);
|
|
|
}
|
|
|
});
|
|
|
- return new RandomSamplerAggregatorFactory(name, seed, p, context, parent, subfactoriesBuilder, metadata);
|
|
|
+ return new RandomSamplerAggregatorFactory(name, seed, shardSeed, p, context, parent, subfactoriesBuilder, metadata);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -136,6 +151,9 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
builder.startObject();
|
|
|
builder.field(PROBABILITY.getPreferredName(), p);
|
|
|
builder.field(SEED.getPreferredName(), seed);
|
|
|
+ if (shardSeed != null) {
|
|
|
+ builder.field(SHARD_SEED.getPreferredName(), shardSeed);
|
|
|
+ }
|
|
|
builder.endObject();
|
|
|
return null;
|
|
|
}
|
|
@@ -162,7 +180,7 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(super.hashCode(), p, seed);
|
|
|
+ return Objects.hash(super.hashCode(), p, seed, shardSeed);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -171,6 +189,6 @@ public class RandomSamplerAggregationBuilder extends AbstractAggregationBuilder<
|
|
|
if (obj == null || getClass() != obj.getClass()) return false;
|
|
|
if (super.equals(obj) == false) return false;
|
|
|
RandomSamplerAggregationBuilder other = (RandomSamplerAggregationBuilder) obj;
|
|
|
- return Objects.equals(p, other.p) && Objects.equals(seed, other.seed);
|
|
|
+ return Objects.equals(p, other.p) && Objects.equals(seed, other.seed) && Objects.equals(shardSeed, other.shardSeed);
|
|
|
}
|
|
|
}
|