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

Run spotless and exclude checkstyle on modules module #1442

Merged
merged 1 commit into from
Oct 27, 2021
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<suppress files="plugins[/\\]examples" checks="." />
<!-- Excludes checkstyle run on libs module -->
<suppress files="libs" checks="." />
<!-- Excludes checkstyle run on modules module -->
<suppress files="modules" checks="." />

<!--
Truly temporary suppressions suppression of snippets included in
Expand Down
18 changes: 0 additions & 18 deletions gradle/formatting.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ import org.opensearch.gradle.BuildPlugin

// Do not add new sub-projects here!
def projectPathsToExclude = [
':modules:aggs-matrix-stats',
':modules:analysis-common',
':modules:ingest-common',
':modules:ingest-geoip',
':modules:ingest-user-agent',
':modules:lang-expression',
':modules:lang-mustache',
':modules:lang-painless',
':modules:lang-painless:spi',
':modules:mapper-extras',
':modules:parent-join',
':modules:percolator',
':modules:rank-eval',
':modules:reindex',
':modules:repository-url',
':modules:systemd',
':modules:tasks',
':modules:transport-netty4',
':plugins:analysis-icu',
':plugins:analysis-kuromoji',
':plugins:analysis-nori',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
public class MatrixAggregationPlugin extends Plugin implements SearchPlugin {
@Override
public List<AggregationSpec> getAggregations() {
return singletonList(new AggregationSpec(MatrixStatsAggregationBuilder.NAME, MatrixStatsAggregationBuilder::new,
new MatrixStatsParser()).addResultReader(InternalMatrixStats::new));
return singletonList(
new AggregationSpec(MatrixStatsAggregationBuilder.NAME, MatrixStatsAggregationBuilder::new, new MatrixStatsParser())
.addResultReader(InternalMatrixStats::new)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public class InternalMatrixStats extends InternalAggregation implements MatrixSt
private final MatrixStatsResults results;

/** per shard ctor */
InternalMatrixStats(String name, long count, RunningStats multiFieldStatsResults, MatrixStatsResults results,
Map<String, Object> metadata) {
InternalMatrixStats(
String name,
long count,
RunningStats multiFieldStatsResults,
MatrixStatsResults results,
Map<String, Object> metadata
) {
super(name, metadata);
assert count >= 0;
this.stats = multiFieldStatsResults;
Expand Down Expand Up @@ -248,7 +253,7 @@ public Object getProperty(List<String> path) {
public InternalAggregation reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
// merge stats across all shards
List<InternalAggregation> aggs = new ArrayList<>(aggregations);
aggs.removeIf(p -> ((InternalMatrixStats)p).stats == null);
aggs.removeIf(p -> ((InternalMatrixStats) p).stats == null);

// return empty result iff all stats are null
if (aggs.isEmpty()) {
Expand Down Expand Up @@ -284,7 +289,6 @@ public boolean equals(Object obj) {
if (super.equals(obj) == false) return false;

InternalMatrixStats other = (InternalMatrixStats) obj;
return Objects.equals(this.stats, other.stats) &&
Objects.equals(this.results, other.results);
return Objects.equals(this.stats, other.stats) && Objects.equals(this.results, other.results);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@
public interface MatrixStats extends Aggregation {
/** return the total document count */
long getDocCount();

/** return total field count (differs from docCount if there are missing values) */
long getFieldCount(String field);

/** return the field mean */
double getMean(String field);

/** return the field variance */
double getVariance(String field);

/** return the skewness of the distribution */
double getSkewness(String field);

/** return the kurtosis of the distribution */
double getKurtosis(String field);

/** return the covariance between field x and field y */
double getCovariance(String fieldX, String fieldY);

/** return the correlation coefficient of field x and field y */
double getCorrelation(String fieldX, String fieldY);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public MatrixStatsAggregationBuilder(String name) {
super(name);
}

protected MatrixStatsAggregationBuilder(MatrixStatsAggregationBuilder clone,
AggregatorFactories.Builder factoriesBuilder, Map<String, Object> metadata) {
protected MatrixStatsAggregationBuilder(
MatrixStatsAggregationBuilder clone,
AggregatorFactories.Builder factoriesBuilder,
Map<String, Object> metadata
) {
super(clone, factoriesBuilder, metadata);
this.multiValueMode = clone.multiValueMode;
}
Expand Down Expand Up @@ -88,10 +91,12 @@ public MultiValueMode multiValueMode() {
}

@Override
protected MatrixStatsAggregatorFactory innerBuild(QueryShardContext queryShardContext,
Map<String, ValuesSourceConfig> configs,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
protected MatrixStatsAggregatorFactory innerBuild(
QueryShardContext queryShardContext,
Map<String, ValuesSourceConfig> configs,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder
) throws IOException {
return new MatrixStatsAggregatorFactory(name, configs, multiValueMode, queryShardContext, parent, subFactoriesBuilder, metadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ final class MatrixStatsAggregator extends MetricsAggregator {
/** array of descriptive stats, per shard, needed to compute the correlation */
ObjectArray<RunningStats> stats;

MatrixStatsAggregator(String name, Map<String, ValuesSource.Numeric> valuesSources, SearchContext context,
Aggregator parent, MultiValueMode multiValueMode, Map<String,Object> metadata) throws IOException {
MatrixStatsAggregator(
String name,
Map<String, ValuesSource.Numeric> valuesSources,
SearchContext context,
Aggregator parent,
MultiValueMode multiValueMode,
Map<String, Object> metadata
) throws IOException {
super(name, context, parent, metadata);
if (valuesSources != null && !valuesSources.isEmpty()) {
this.valuesSources = new ArrayValuesSource.NumericArrayValuesSource(valuesSources, multiValueMode);
Expand All @@ -77,8 +83,7 @@ public ScoreMode scoreMode() {
}

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
final LeafBucketCollector sub) throws IOException {
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
if (valuesSources == null) {
return LeafBucketCollector.NO_OP_COLLECTOR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,38 @@ final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFact

private final MultiValueMode multiValueMode;

MatrixStatsAggregatorFactory(String name,
Map<String, ValuesSourceConfig> configs,
MultiValueMode multiValueMode,
QueryShardContext queryShardContext,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder,
Map<String, Object> metadata) throws IOException {
MatrixStatsAggregatorFactory(
String name,
Map<String, ValuesSourceConfig> configs,
MultiValueMode multiValueMode,
QueryShardContext queryShardContext,
AggregatorFactory parent,
AggregatorFactories.Builder subFactoriesBuilder,
Map<String, Object> metadata
) throws IOException {
super(name, configs, queryShardContext, parent, subFactoriesBuilder, metadata);
this.multiValueMode = multiValueMode;
}

@Override
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata)
throws IOException {
protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map<String, Object> metadata) throws IOException {
return new MatrixStatsAggregator(name, null, searchContext, parent, multiValueMode, metadata);
}

@Override
protected Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
SearchContext searchContext,
Aggregator parent,
CardinalityUpperBound cardinality,
Map<String, Object> metadata) throws IOException {
protected Aggregator doCreateInternal(
Map<String, ValuesSource> valuesSources,
SearchContext searchContext,
Aggregator parent,
CardinalityUpperBound cardinality,
Map<String, Object> metadata
) throws IOException {
Map<String, ValuesSource.Numeric> typedValuesSources = new HashMap<>(valuesSources.size());
for (Map.Entry<String, ValuesSource> entry : valuesSources.entrySet()) {
if (entry.getValue() instanceof ValuesSource.Numeric == false) {
throw new AggregationExecutionException("ValuesSource type " + entry.getValue().toString() +
"is not supported for aggregation " + this.name());
throw new AggregationExecutionException(
"ValuesSource type " + entry.getValue().toString() + "is not supported for aggregation " + this.name()
);
}
// TODO: There must be a better option than this.
typedValuesSources.put(entry.getKey(), (ValuesSource.Numeric) entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ public MatrixStatsParser() {
}

@Override
protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
Map<ParseField, Object> otherOptions) throws IOException {
protected boolean token(
String aggregationName,
String currentFieldName,
XContentParser.Token token,
XContentParser parser,
Map<ParseField, Object> otherOptions
) throws IOException {
if (ArrayValuesSourceAggregationBuilder.MULTIVALUE_MODE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
if (token == XContentParser.Token.VALUE_STRING) {
otherOptions.put(ArrayValuesSourceAggregationBuilder.MULTIVALUE_MODE_FIELD, parser.text());
Expand All @@ -61,10 +66,14 @@ protected boolean token(String aggregationName, String currentFieldName, XConten
}

@Override
protected MatrixStatsAggregationBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
protected MatrixStatsAggregationBuilder createFactory(
String aggregationName,
ValuesSourceType valuesSourceType,
ValueType targetValueType,
Map<ParseField, Object> otherOptions
) {
MatrixStatsAggregationBuilder builder = new MatrixStatsAggregationBuilder(aggregationName);
String mode = (String)otherOptions.get(ArrayValuesSourceAggregationBuilder.MULTIVALUE_MODE_FIELD);
String mode = (String) otherOptions.get(ArrayValuesSourceAggregationBuilder.MULTIVALUE_MODE_FIELD);
if (mode != null) {
builder.multiValueMode(MultiValueMode.fromString(mode));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void compute() {
// update skewness
results.skewness.put(fieldName, Math.sqrt(results.docCount) * results.skewness.get(fieldName) / Math.pow(var, 1.5D));
// update kurtosis
results.kurtosis.put(fieldName, (double)results.docCount * results.kurtosis.get(fieldName) / (var * var));
results.kurtosis.put(fieldName, (double) results.docCount * results.kurtosis.get(fieldName) / (var * var));
// update variances
results.variances.put(fieldName, results.variances.get(fieldName) / nM1);
}
Expand Down Expand Up @@ -248,8 +248,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MatrixStatsResults that = (MatrixStatsResults) o;
return Objects.equals(results, that.results) &&
Objects.equals(correlation, that.correlation);
return Objects.equals(results, that.results) && Objects.equals(correlation, that.correlation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ private static <T> T checkedGet(final Map<String, T> values, final String fieldN
return values.get(fieldName);
}

private static final ObjectParser<ParsedMatrixStats, Void> PARSER =
new ObjectParser<>(ParsedMatrixStats.class.getSimpleName(), true, ParsedMatrixStats::new);
private static final ObjectParser<ParsedMatrixStats, Void> PARSER = new ObjectParser<>(
ParsedMatrixStats.class.getSimpleName(),
true,
ParsedMatrixStats::new
);
static {
declareAggregationFields(PARSER);
PARSER.declareLong(ParsedMatrixStats::setDocCount, CommonFields.DOC_COUNT);
Expand Down Expand Up @@ -200,21 +203,27 @@ static class ParsedMatrixStatsResult {
Map<String, Double> covariances;
Map<String, Double> correlations;

private static final ObjectParser<ParsedMatrixStatsResult, Void> RESULT_PARSER =
new ObjectParser<>(ParsedMatrixStatsResult.class.getSimpleName(), true, ParsedMatrixStatsResult::new);
private static final ObjectParser<ParsedMatrixStatsResult, Void> RESULT_PARSER = new ObjectParser<>(
ParsedMatrixStatsResult.class.getSimpleName(),
true,
ParsedMatrixStatsResult::new
);
static {
RESULT_PARSER.declareString((result, name) -> result.name = name,
new ParseField(InternalMatrixStats.Fields.NAME));
RESULT_PARSER.declareLong((result, count) -> result.count = count,
new ParseField(InternalMatrixStats.Fields.COUNT));
RESULT_PARSER.declareDouble((result, mean) -> result.mean = mean,
new ParseField(InternalMatrixStats.Fields.MEAN));
RESULT_PARSER.declareDouble((result, variance) -> result.variance = variance,
new ParseField(InternalMatrixStats.Fields.VARIANCE));
RESULT_PARSER.declareDouble((result, skewness) -> result.skewness = skewness,
new ParseField(InternalMatrixStats.Fields.SKEWNESS));
RESULT_PARSER.declareDouble((result, kurtosis) -> result.kurtosis = kurtosis,
new ParseField(InternalMatrixStats.Fields.KURTOSIS));
RESULT_PARSER.declareString((result, name) -> result.name = name, new ParseField(InternalMatrixStats.Fields.NAME));
RESULT_PARSER.declareLong((result, count) -> result.count = count, new ParseField(InternalMatrixStats.Fields.COUNT));
RESULT_PARSER.declareDouble((result, mean) -> result.mean = mean, new ParseField(InternalMatrixStats.Fields.MEAN));
RESULT_PARSER.declareDouble(
(result, variance) -> result.variance = variance,
new ParseField(InternalMatrixStats.Fields.VARIANCE)
);
RESULT_PARSER.declareDouble(
(result, skewness) -> result.skewness = skewness,
new ParseField(InternalMatrixStats.Fields.SKEWNESS)
);
RESULT_PARSER.declareDouble(
(result, kurtosis) -> result.kurtosis = kurtosis,
new ParseField(InternalMatrixStats.Fields.KURTOSIS)
);

RESULT_PARSER.declareObject((ParsedMatrixStatsResult result, Map<String, Object> covars) -> {
result.covariances = new LinkedHashMap<>(covars.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ private void init() {
public RunningStats(StreamInput in) throws IOException {
this();
// read doc count
docCount = (Long)in.readGenericValue();
docCount = (Long) in.readGenericValue();
// read fieldSum
fieldSum = convertIfNeeded((Map<String, Double>)in.readGenericValue());
fieldSum = convertIfNeeded((Map<String, Double>) in.readGenericValue());
// counts
counts = convertIfNeeded((Map<String, Long>)in.readGenericValue());
counts = convertIfNeeded((Map<String, Long>) in.readGenericValue());
// means
means = convertIfNeeded((Map<String, Double>)in.readGenericValue());
means = convertIfNeeded((Map<String, Double>) in.readGenericValue());
// variances
variances = convertIfNeeded((Map<String, Double>)in.readGenericValue());
variances = convertIfNeeded((Map<String, Double>) in.readGenericValue());
// skewness
skewness = convertIfNeeded((Map<String, Double>)in.readGenericValue());
skewness = convertIfNeeded((Map<String, Double>) in.readGenericValue());
// kurtosis
kurtosis = convertIfNeeded((Map<String, Double>)in.readGenericValue());
kurtosis = convertIfNeeded((Map<String, Double>) in.readGenericValue());
// read covariances
covariances = convertIfNeeded((Map<String, HashMap<String, Double>>)in.readGenericValue());
covariances = convertIfNeeded((Map<String, HashMap<String, Double>>) in.readGenericValue());
}

// Convert Map to HashMap if it isn't
private static <K, V> HashMap<K, V> convertIfNeeded(Map<K,V> map) {
private static <K, V> HashMap<K, V> convertIfNeeded(Map<K, V> map) {
if (map instanceof HashMap) {
return (HashMap<K, V>) map;
} else {
Expand Down Expand Up @@ -235,7 +235,7 @@ public void merge(final RunningStats other) {
this.counts.put(fieldName, other.counts.get(fieldName).longValue());
this.fieldSum.put(fieldName, other.fieldSum.get(fieldName).doubleValue());
this.variances.put(fieldName, other.variances.get(fieldName).doubleValue());
this.skewness.put(fieldName , other.skewness.get(fieldName).doubleValue());
this.skewness.put(fieldName, other.skewness.get(fieldName).doubleValue());
this.kurtosis.put(fieldName, other.kurtosis.get(fieldName).doubleValue());
if (other.covariances.containsKey(fieldName)) {
this.covariances.put(fieldName, other.covariances.get(fieldName));
Expand Down Expand Up @@ -338,14 +338,14 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RunningStats that = (RunningStats) o;
return docCount == that.docCount &&
Objects.equals(fieldSum, that.fieldSum) &&
Objects.equals(counts, that.counts) &&
Objects.equals(means, that.means) &&
Objects.equals(variances, that.variances) &&
Objects.equals(skewness, that.skewness) &&
Objects.equals(kurtosis, that.kurtosis) &&
Objects.equals(covariances, that.covariances);
return docCount == that.docCount
&& Objects.equals(fieldSum, that.fieldSum)
&& Objects.equals(counts, that.counts)
&& Objects.equals(means, that.means)
&& Objects.equals(variances, that.variances)
&& Objects.equals(skewness, that.skewness)
&& Objects.equals(kurtosis, that.kurtosis)
&& Objects.equals(covariances, that.covariances);
}

@Override
Expand Down
Loading