Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
772b87b
Create MV_RIEMANN_ZETA scalar multivalue function
machadoum May 24, 2024
91de8fe
[WIP] Create RIEMANN_ZETA aggregate function
machadoum May 24, 2024
8bfd903
Fix bug
machadoum May 27, 2024
3326dd0
Merge remote-tracking branch 'elastic/main' into siem-ea-9521
machadoum Jul 17, 2024
9199562
wip
machadoum Jul 19, 2024
85679b2
Merge remote-tracking branch 'origin/main' into siem-ea-9521
machadoum Jul 19, 2024
eb924c3
wip2
machadoum Jul 25, 2024
5a17239
Merge remote-tracking branch 'origin/main' into siem-ea-9521
machadoum Jul 25, 2024
6c5bc3e
fix
machadoum Jul 25, 2024
5020e7a
Fix style
machadoum Jul 25, 2024
5c9988e
fxup
nik9000 Jul 25, 2024
15d4ab6
Rename p_series to pseries
machadoum Jul 26, 2024
dc75416
Update docs
machadoum Jul 26, 2024
29467ed
Update docs/changelog/109017.yaml
machadoum Jul 26, 2024
6993133
Skip older
nik9000 Jul 26, 2024
261739f
Alphabetize
nik9000 Jul 26, 2024
a44a6b8
Fix changelog
machadoum Jul 26, 2024
b93902b
Improve docs
machadoum Jul 26, 2024
d34970b
Merge remote-tracking branch 'origin/main' into siem-ea-9521
machadoum Jul 26, 2024
9e90d27
Fix
nik9000 Jul 26, 2024
b65b9a8
Merge branch 'main' into siem-ea-9521
nik9000 Jul 26, 2024
a4f7588
Fix @fixed
nik9000 Jul 26, 2024
865d0c7
Implement Code review comments
machadoum Jul 29, 2024
e8d5b30
Fix style
machadoum Jul 29, 2024
fab2782
Improve TODO
machadoum Jul 29, 2024
60f38a5
Update package info docs as requested in the code review
machadoum Jul 30, 2024
2666bba
Update test to generate random values
machadoum Jul 31, 2024
98f5811
Merge remote-tracking branch 'origin/main' into siem-ea-9521
machadoum Jul 31, 2024
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 @@ -54,6 +54,7 @@ public class CsvTestsDataLoader {
private static final TestsDataset HOSTS = new TestsDataset("hosts", "mapping-hosts.json", "hosts.csv");
private static final TestsDataset APPS = new TestsDataset("apps", "mapping-apps.json", "apps.csv");
private static final TestsDataset LANGUAGES = new TestsDataset("languages", "mapping-languages.json", "languages.csv");
private static final TestsDataset ALERTS = new TestsDataset("alerts", "mapping-alerts.json", "alerts.csv");
private static final TestsDataset UL_LOGS = new TestsDataset("ul_logs", "mapping-ul_logs.json", "ul_logs.csv");
private static final TestsDataset SAMPLE_DATA = new TestsDataset("sample_data", "mapping-sample_data.json", "sample_data.csv");
private static final TestsDataset CLIENT_IPS = new TestsDataset("clientips", "mapping-clientips.json", "clientips.csv");
Expand Down Expand Up @@ -94,6 +95,7 @@ public class CsvTestsDataLoader {
Map.entry(LANGUAGES.indexName, LANGUAGES),
Map.entry(UL_LOGS.indexName, UL_LOGS),
Map.entry(SAMPLE_DATA.indexName, SAMPLE_DATA),
Map.entry(ALERTS.indexName, ALERTS),
Map.entry(CLIENT_IPS.indexName, CLIENT_IPS),
Map.entry(CLIENT_CIDR.indexName, CLIENT_CIDR),
Map.entry(AGES.indexName, AGES),
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugin/esql/qa/testFixtures/src/main/resources/alerts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
host.name:keyword,kibana.alert.risk_score:double
test-host-1,21.0
test-host-2,17.0
test-host-2,23.0
test-host-1,45.0
test-host-2,12.0
test-host-2,16.0
test-host-1,21.0
test-host-1,70.0
test-host-1,21.0
test-host-2,5.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"properties": {
"host.name": {
"type": "keyword"
},
"kibana.alert.risk_score": {
"type": "double"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
multivalue
ROW data = [21.0, 45.0, 21.0, 70.0, 21.0]
| EVAL sorted = MV_SORT(data, "desc")
| EVAL score = MV_RIEMANN_ZETA(sorted, 1.5)
| EVAL normalized_score = ROUND(100 * score / 261.2, 2)
| KEEP normalized_score, score;

normalized_score:double|score:double
36.16 |94.45465156212452
;


aggregation
from alerts
| where host.name is not null
| SORT host.name, kibana.alert.risk_score
| stats score = RIEMANN_ZETA(kibana.alert.risk_score, 1.5) by host.name
| EVAL normalized_score = ROUND(100 * score / 261.2, 2)
| keep host.name, normalized_score, score;

host.name:keyword|normalized_score:double|score:double
test-host-1 |36.16 |94.45465156212452
test-host-2 |36.16 |94.45465156212452
;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.xpack.esql.expression.function.aggregate.MedianAbsoluteDeviation;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Min;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Percentile;
import org.elasticsearch.xpack.esql.expression.function.aggregate.RiemannZeta;
import org.elasticsearch.xpack.esql.expression.function.aggregate.SpatialCentroid;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Sum;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Values;
Expand Down Expand Up @@ -87,6 +88,7 @@
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSlice;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSort;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSum;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvRiemannZeta;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvZip;
import org.elasticsearch.xpack.esql.expression.function.scalar.nulls.Coalesce;
import org.elasticsearch.xpack.esql.expression.function.scalar.spatial.SpatialContains;
Expand Down Expand Up @@ -189,6 +191,7 @@ private FunctionDefinition[][] functions() {
def(MedianAbsoluteDeviation.class, MedianAbsoluteDeviation::new, "median_absolute_deviation"),
def(Min.class, Min::new, "min"),
def(Percentile.class, Percentile::new, "percentile"),
def(RiemannZeta.class, RiemannZeta::new, "riemann_zeta"),
def(Sum.class, Sum::new, "sum"),
def(Values.class, Values::new, "values") },
// math
Expand Down Expand Up @@ -291,7 +294,8 @@ private FunctionDefinition[][] functions() {
def(MvSlice.class, MvSlice::new, "mv_slice"),
def(MvZip.class, MvZip::new, "mv_zip"),
def(MvSum.class, MvSum::new, "mv_sum"),
def(Split.class, Split::new, "split") } };
def(Split.class, Split::new, "split"),
def(MvRiemannZeta.class, MvRiemannZeta::new, "mv_riemann_zeta") } };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.expression.function.aggregate;

import org.elasticsearch.compute.aggregation.AggregatorFunctionSupplier;
import org.elasticsearch.compute.aggregation.SumDoubleAggregatorFunctionSupplier;
import org.elasticsearch.compute.aggregation.SumIntAggregatorFunctionSupplier;
import org.elasticsearch.compute.aggregation.SumLongAggregatorFunctionSupplier;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.expression.Literal;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.core.type.DataTypes;
import org.elasticsearch.xpack.esql.core.util.StringUtils;
import org.elasticsearch.xpack.esql.expression.SurrogateExpression;
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSum;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Mul;

import java.util.List;

import static org.elasticsearch.xpack.esql.core.type.DataTypes.*;

/**
* Sum all values of a field in matching documents.
*/
public class RiemannZeta extends NumericAggregate implements SurrogateExpression {
private final Expression p;

@FunctionInfo(returnType = "double", description = "todo", isAggregation = true)
public RiemannZeta(
Source source,
@Param(name = "number", type = { "double" }) Expression field,
@Param(name = "p", type = { "double" }) Expression p
) {
super(source, field, List.of(p));
this.p = p;
}

@Override
protected NodeInfo<RiemannZeta> info() {
return NodeInfo.create(this, RiemannZeta::new, field(), p);
}

@Override
public RiemannZeta replaceChildren(List<Expression> newChildren) {
return new RiemannZeta(source(), newChildren.get(0), newChildren.get(1));
}

@Override
public DataType dataType() {
return field().dataType();
}

@Override
protected AggregatorFunctionSupplier longSupplier(List<Integer> inputChannels) {
return new SumLongAggregatorFunctionSupplier(inputChannels);
}

@Override
protected AggregatorFunctionSupplier intSupplier(List<Integer> inputChannels) {
return new SumIntAggregatorFunctionSupplier(inputChannels);
}

@Override
protected AggregatorFunctionSupplier doubleSupplier(List<Integer> inputChannels) {
return new SumDoubleAggregatorFunctionSupplier(inputChannels);
}

@Override
public Expression surrogate() {
var s = source();
var field = field();

// SUM(const) is equivalent to MV_SUM(const)*COUNT(*).
return field.foldable()
? new Mul(s, new MvSum(s, field), new Count(s, new Literal(s, StringUtils.WILDCARD, DataTypes.KEYWORD)))
: null;
}
}
Loading