Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/142974.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
area: ES|QL
issues:
- 139928
pr: 142974
summary: Add support for `dense_vector` in `COALESCE`
type: enhancement

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.

7 changes: 7 additions & 0 deletions x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def prop(Name, Type, type, TYPE, BYTES, Array) {
"int" : type == "int" ? "true" : "",
"long" : type == "long" ? "true" : "",
"double" : type == "double" ? "true" : "",
"float" : type == "float" ? "true" : "",
"BytesRef" : type == "BytesRef" ? "true" : "",
"boolean" : type == "boolean" ? "true" : "",
"nanosMillis": Name == "NanosMillis" ? "true" : "",
Expand All @@ -544,6 +545,7 @@ tasks.named('stringTemplates').configure {
var nanosMillisProperties = prop("NanosMillis", "Long", "long", "LONG", "Long.BYTES", "LongArray")
var millisNanosProperties = prop("MillisNanos", "Long", "long", "LONG", "Long.BYTES", "LongArray")
var doubleProperties = prop("Double", "Double", "double", "DOUBLE", "Double.BYTES", "DoubleArray")
var floatProperties = prop("Float", "Float", "float", "FLOAT", "Float.BYTES", "FloatArray")
var bytesRefProperties = prop("BytesRef", "BytesRef", "BytesRef", "BYTES_REF", "org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF", "")
var booleanProperties = prop("Boolean", "Boolean", "boolean", "BOOLEAN", "Byte.BYTES", "BitArray")
var expHistoProperties = prop("ExponentialHistogram", "ExponentialHistogram", "ExponentialHistogram", "EXPONENTIAL_HISTOGRAM", "", "")
Expand Down Expand Up @@ -607,6 +609,11 @@ tasks.named('stringTemplates').configure {
it.inputFile = coalesceInputFile
it.outputFile = "org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceDoubleEvaluator.java"
}
template {
it.properties = floatProperties
it.inputFile = coalesceInputFile
it.outputFile = "org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceFloatEvaluator.java"
}
template {
it.properties = bytesRefProperties
it.inputFile = coalesceInputFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public class CsvTestsDataLoader {
new TestDataset("dense_vector_text"),
new TestDataset("mv_text"),
new TestDataset("dense_vector"),
new TestDataset("dense_vector_coalesce").withRequiredCapabilities(EsqlCapabilities.Cap.COALESCE_DENSE_VECTOR),
new TestDataset("dense_vector_bfloat16").withRequiredCapabilities(EsqlCapabilities.Cap.GENERIC_VECTOR_FORMAT),
new TestDataset("dense_vector_arithmetic"),
new TestDataset("web_logs"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id:l, float_vector:dense_vector, byte_vector:dense_vector, bit_vector:dense_vect
1, [4.0, 5.0, 6.0], [40, 50, 60], [45, 9]
2, [9.0, 8.0, 7.0], [90, 80, 70], [127, 0]
3, [0.054, 0.032, 0.012], [100, 110, 120], [88, 53]
4, , ,
4, , ,
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id:l, float_vector:dense_vector, float_vector_2:dense_vector, byte_vector:dense_vector, byte_vector_2:dense_vector, bit_vector:dense_vector, bit_vector_2:dense_vector, bfloat16_vector:dense_vector, bfloat16_vector_2:dense_vector
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check: https://github.com/elastic/elasticsearch/pull/142974/changes#r2848341088
A question about whether we want coalesce tests in the dense_vector*.csv-spec tests.

0, [1.0, 2.0, 3.0], [0.0, 0.0, 0.0], [10, 20, 30], [0, 0, 0], [13, 112], [0, 1], [1.0, 2.0, 3.0], [0.0, 0.0, 0.0]
1, [4.0, 5.0, 6.0], [0.0, 0.0, 0.0], [40, 50, 60], [0, 0, 0], [45, 9], [2, 3], [4.0, 5.0, 6.0], [0.0, 0.0, 0.0]
2, [9.0, 8.0, 7.0], [0.0, 0.0, 0.0], [90, 80, 70], [0, 0, 0], [127, 0], [4, 5], [9.0, 8.0, 7.0], [0.0, 0.0, 0.0]
3, [0.054, 0.032, 0.012], [0.0, 0.0, 0.0], [100, 110, 120], [0, 0, 0], [88, 53], [6, 7], [1.0, 5.0, 7.0], [0.0, 0.0, 0.0]
4, , [0.5, 0.5, 0.5], , [1, 2, 3], , [99, 100], , [1.0, 2.0, 3.0]
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ id:l | new_vector:dense_vector
4 | null
;

coalesceBfloat16VectorWithFallback
Copy link
Copy Markdown
Contributor Author

@mromaios mromaios Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ 💭 Do we need coalesce tests in the individual .csv-spec files, or is that an overkill? (same comment for the other types (default, bit, byte))

required_capability: coalesce_dense_vector

FROM dense_vector_coalesce
| EVAL v = COALESCE(bfloat16_vector, to_dense_vector([0, 0, 0]))
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [1.0, 2.0, 3.0]
1 | [4.0, 5.0, 6.0]
2 | [9.0, 8.0, 7.0]
3 | [1.0, 5.0, 7.0]
4 | [0.0, 0.0, 0.0]
;

coalesceBfloat16VectorTwoColumns
required_capability: coalesce_dense_vector

FROM dense_vector_coalesce
| EVAL v = COALESCE(bfloat16_vector, bfloat16_vector_2)
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [1.0, 2.0, 3.0]
1 | [4.0, 5.0, 6.0]
2 | [9.0, 8.0, 7.0]
3 | [1.0, 5.0, 7.0]
4 | [1.0, 2.0, 3.0]
;

denseVectorAggregationFunctions
required_capability: dense_vector_agg_functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@ id:l | new_vector:dense_vector
4 | null
;

coalesceBitVectorWithFallback
required_capability: coalesce_dense_vector

FROM dense_vector
| EVAL v = COALESCE(bit_vector, to_dense_vector([0, 0]))
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [13, 112]
1 | [45, 9]
2 | [127, 0]
3 | [88, 53]
4 | [0, 0]
;

coalesceBitVectorTwoColumns
required_capability: coalesce_dense_vector

FROM dense_vector_coalesce
| EVAL v = COALESCE(bit_vector, bit_vector_2)
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [13, 112]
1 | [45, 9]
2 | [127, 0]
3 | [88, 53]
4 | [99, 100]
;

denseVectorAggregationFunctions
required_capability: dense_vector_agg_functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@ id:l | new_vector:dense_vector
4 | null
;

coalesceByteVectorWithFallback
required_capability: coalesce_dense_vector

FROM dense_vector
| EVAL v = COALESCE(byte_vector, to_dense_vector([0, 0, 0]))
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [10, 20, 30]
1 | [40, 50, 60]
2 | [90, 80, 70]
3 | [100, 110, 120]
4 | [0, 0, 0]
;

coalesceByteVectorTwoColumns
required_capability: coalesce_dense_vector

FROM dense_vector_coalesce
| EVAL v = COALESCE(byte_vector, byte_vector_2)
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [10, 20, 30]
1 | [40, 50, 60]
2 | [90, 80, 70]
3 | [100, 110, 120]
4 | [1, 2, 3]
;

denseVectorAggregationFunctions
required_capability: dense_vector_agg_functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,37 @@ count_vectors:long
1
;

coalesceDenseVectorWithFallback
required_capability: coalesce_dense_vector

FROM dense_vector
| EVAL v = COALESCE(float_vector, to_dense_vector([0, 0, 0]))
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [1.0, 2.0, 3.0]
1 | [4.0, 5.0, 6.0]
2 | [9.0, 8.0, 7.0]
3 | [0.054, 0.032, 0.012]
4 | [0.0, 0.0, 0.0]
;

coalesceDenseVectorTwoColumns
required_capability: coalesce_dense_vector

FROM dense_vector_coalesce
| EVAL v = COALESCE(float_vector, float_vector_2)
| KEEP id, v
| SORT id
;

id:l | v:dense_vector
0 | [1.0, 2.0, 3.0]
1 | [4.0, 5.0, 6.0]
2 | [9.0, 8.0, 7.0]
3 | [0.054, 0.032, 0.012]
4 | [0.5, 0.5, 0.5]
;

Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"properties": {
"id": {
"type": "long"
},
"float_vector": {
"type": "dense_vector",
"similarity": "l2_norm",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"float_vector_2": {
"type": "dense_vector",
"similarity": "l2_norm",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"byte_vector": {
"type": "dense_vector",
"similarity": "l2_norm",
"element_type": "byte",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"byte_vector_2": {
"type": "dense_vector",
"similarity": "l2_norm",
"element_type": "byte",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"bit_vector": {
"type": "dense_vector",
"dims": 16,
"similarity": "l2_norm",
"element_type": "bit",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"bit_vector_2": {
"type": "dense_vector",
"dims": 16,
"similarity": "l2_norm",
"element_type": "bit",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"bfloat16_vector": {
"type": "dense_vector",
"similarity": "l2_norm",
"element_type": "bfloat16",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
},
"bfloat16_vector_2": {
"type": "dense_vector",
"similarity": "l2_norm",
"element_type": "bfloat16",
"index_options": {
"type": "hnsw",
"m": 16,
"ef_construction": 100
}
}
}
}
Loading
Loading