Skip to content

Commit

Permalink
ESQL: TOP aggregation IP support (elastic#111105)
Browse files Browse the repository at this point in the history
Added IP support to TOP() aggregation.

Adapted a bit the stringtemplates organization for esql/compute to
(also?) work with specific datatypes. Right now it may be a bit messy,
but we need the specific support for cases like this.
  • Loading branch information
ivancea committed Jul 22, 2024
1 parent 86544aa commit 195b916
Show file tree
Hide file tree
Showing 32 changed files with 1,520 additions and 207 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/111105.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 111105
summary: "ESQL: TOP aggregation IP support"
area: ES|QL
type: feature
issues: []
24 changes: 24 additions & 0 deletions docs/reference/esql/functions/kibana/definition/top.json

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

1 change: 1 addition & 0 deletions docs/reference/esql/functions/types/top.asciidoc

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

44 changes: 31 additions & 13 deletions x-pack/plugin/esql/compute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,40 @@ spotless {
}
}

def prop(Type, type, Wrapper, TYPE, BYTES, Array, Hash) {
def prop(Name, Type, type, Wrapper, TYPE, BYTES, Array, Hash) {
return [
// Name of the DataType. Use in DataType names
"Name" : Name,
// PascalCased type. Use in ElementType names
"Type" : Type,
// Variable type. May be a primitive
"type" : type,
// Wrapper type. Only for primitive types
"Wrapper": Wrapper,
// SCREAMING_SNAKE_CASE type. Use in ElementType names
"TYPE" : TYPE,
"BYTES" : BYTES,
"Array" : Array,
"Hash" : Hash,

"int" : type == "int" ? "true" : "",
"float" : type == "float" ? "true" : "",
"long" : type == "long" ? "true" : "",
"double" : type == "double" ? "true" : "",
"BytesRef" : type == "BytesRef" ? "true" : "",
"boolean" : type == "boolean" ? "true" : "",
"int" : Name == "Int" ? "true" : "",
"float" : Name == "Float" ? "true" : "",
"long" : Name == "Long" ? "true" : "",
"double" : Name == "Double" ? "true" : "",
"boolean" : Name == "Boolean" ? "true" : "",
"BytesRef" : Name == "BytesRef" ? "true" : "",
"Ip" : Name == "Ip" ? "true" : "",
]
}

tasks.named('stringTemplates').configure {
var intProperties = prop("Int", "int", "Integer", "INT", "Integer.BYTES", "IntArray", "LongHash")
var floatProperties = prop("Float", "float", "Float", "FLOAT", "Float.BYTES", "FloatArray", "LongHash")
var longProperties = prop("Long", "long", "Long", "LONG", "Long.BYTES", "LongArray", "LongHash")
var doubleProperties = prop("Double", "double", "Double", "DOUBLE", "Double.BYTES", "DoubleArray", "LongHash")
var bytesRefProperties = prop("BytesRef", "BytesRef", "", "BYTES_REF", "org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF", "", "BytesRefHash")
var booleanProperties = prop("Boolean", "boolean", "Boolean", "BOOLEAN", "Byte.BYTES", "BitArray", "")
var intProperties = prop("Int", "Int", "int", "Integer", "INT", "Integer.BYTES", "IntArray", "LongHash")
var floatProperties = prop("Float", "Float", "float", "Float", "FLOAT", "Float.BYTES", "FloatArray", "LongHash")
var longProperties = prop("Long", "Long", "long", "Long", "LONG", "Long.BYTES", "LongArray", "LongHash")
var doubleProperties = prop("Double", "Double", "double", "Double", "DOUBLE", "Double.BYTES", "DoubleArray", "LongHash")
var booleanProperties = prop("Boolean", "Boolean", "boolean", "Boolean", "BOOLEAN", "Byte.BYTES", "BitArray", "")
var bytesRefProperties = prop("BytesRef", "BytesRef", "BytesRef", "", "BYTES_REF", "org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF", "", "BytesRefHash")
var ipProperties = prop("Ip", "BytesRef", "BytesRef", "", "BYTES_REF", "16", "", "")

// primitive vectors
File vectorInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/data/X-Vector.java.st")
Expand Down Expand Up @@ -554,6 +562,16 @@ tasks.named('stringTemplates').configure {
it.inputFile = topAggregatorInputFile
it.outputFile = "org/elasticsearch/compute/aggregation/TopDoubleAggregator.java"
}
template {
it.properties = booleanProperties
it.inputFile = topAggregatorInputFile
it.outputFile = "org/elasticsearch/compute/aggregation/TopBooleanAggregator.java"
}
template {
it.properties = ipProperties
it.inputFile = topAggregatorInputFile
it.outputFile = "org/elasticsearch/compute/aggregation/TopIpAggregator.java"
}

File multivalueDedupeInputFile = file("src/main/java/org/elasticsearch/compute/operator/mvdedupe/X-MultivalueDedupe.java.st")
template {
Expand Down

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

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

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

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

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

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

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

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

Loading

0 comments on commit 195b916

Please sign in to comment.