-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ES|QL Add serialization to fulltext predicate types (#109819)
This commit adds serialization to fulltext predicate types, so that queries build atop these types can be sent to data nodes.
- Loading branch information
1 parent
55431dd
commit 3a41d8c
Showing
9 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...xpack/esql/expression/predicate/operator/fulltext/AbstractFulltextSerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.predicate.operator.fulltext; | ||
|
||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.xpack.esql.core.expression.predicate.fulltext.FullTextPredicate; | ||
import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class AbstractFulltextSerializationTests<T extends FullTextPredicate> extends AbstractExpressionSerializationTests<T> { | ||
|
||
static final String OPTION_DELIMITER = ";"; | ||
|
||
@Override | ||
protected List<NamedWriteableRegistry.Entry> getNamedWriteables() { | ||
return FullTextPredicate.getNamedWriteables(); | ||
} | ||
|
||
String randomOptionOrNull() { | ||
if (randomBoolean()) { | ||
return null; | ||
} | ||
HashMap<String, String> options = new HashMap<>(); | ||
int maxOptions = randomInt(8); | ||
for (int i = 0; i < maxOptions; i++) { | ||
var opt = randomIndividualOption(); | ||
options.computeIfAbsent(opt.getKey(), k -> opt.getValue()); // no duplicate options | ||
} | ||
return options.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(OPTION_DELIMITER)); | ||
} | ||
|
||
Map.Entry<String, String> randomIndividualOption() { | ||
return Map.entry(randomAlphaOfLength(randomIntBetween(1, 4)), randomAlphaOfLength(randomIntBetween(1, 4))); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...earch/xpack/esql/expression/predicate/operator/fulltext/MatchQuerySerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.predicate.operator.fulltext; | ||
|
||
import org.elasticsearch.xpack.esql.core.expression.predicate.fulltext.MatchQueryPredicate; | ||
import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; | ||
|
||
import java.io.IOException; | ||
|
||
public class MatchQuerySerializationTests extends AbstractFulltextSerializationTests<MatchQueryPredicate> { | ||
|
||
@Override | ||
protected final MatchQueryPredicate createTestInstance() { | ||
return new MatchQueryPredicate(randomSource(), randomChild(), randomAlphaOfLength(randomIntBetween(1, 16)), randomOptionOrNull()); | ||
} | ||
|
||
@Override | ||
protected MatchQueryPredicate mutateInstance(MatchQueryPredicate instance) throws IOException { | ||
var field = instance.field(); | ||
var query = instance.query(); | ||
var options = instance.options(); | ||
switch (between(0, 2)) { | ||
case 0 -> field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild); | ||
case 1 -> query = randomValueOtherThan(query, () -> randomAlphaOfLength(randomIntBetween(1, 16))); | ||
case 2 -> options = randomValueOtherThan(options, this::randomOptionOrNull); | ||
} | ||
return new MatchQueryPredicate(instance.source(), field, query, options); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../xpack/esql/expression/predicate/operator/fulltext/MultiMatchQuerySerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.predicate.operator.fulltext; | ||
|
||
import org.elasticsearch.xpack.esql.core.expression.predicate.fulltext.MultiMatchQueryPredicate; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class MultiMatchQuerySerializationTests extends AbstractFulltextSerializationTests<MultiMatchQueryPredicate> { | ||
|
||
@Override | ||
protected final MultiMatchQueryPredicate createTestInstance() { | ||
return new MultiMatchQueryPredicate( | ||
randomSource(), | ||
randomFieldString(), | ||
randomAlphaOfLength(randomIntBetween(1, 16)), | ||
randomOptionOrNull() | ||
); | ||
} | ||
|
||
@Override | ||
protected MultiMatchQueryPredicate mutateInstance(MultiMatchQueryPredicate instance) throws IOException { | ||
var fieldString = instance.fieldString(); | ||
var query = instance.query(); | ||
var options = instance.options(); | ||
switch (between(0, 2)) { | ||
case 0 -> fieldString = randomValueOtherThan(fieldString, this::randomFieldString); | ||
case 1 -> query = randomValueOtherThan(query, () -> randomAlphaOfLength(randomIntBetween(1, 16))); | ||
case 2 -> options = randomValueOtherThan(options, this::randomOptionOrNull); | ||
} | ||
return new MultiMatchQueryPredicate(instance.source(), fieldString, query, options); | ||
} | ||
|
||
String randomFieldString() { | ||
if (randomBoolean()) { | ||
return ""; // empty, no fields | ||
} | ||
HashMap<String, Float> fields = new HashMap<>(); | ||
int maxOptions = randomInt(4); | ||
for (int i = 0; i < maxOptions; i++) { | ||
var opt = randomIndividualField(); | ||
fields.computeIfAbsent(opt.getKey(), k -> opt.getValue()); // no duplicate fields | ||
} | ||
return fields.entrySet().stream().map(e -> e.getKey() + "^" + e.getValue()).collect(Collectors.joining(",")); | ||
} | ||
|
||
Map.Entry<String, Float> randomIndividualField() { | ||
return Map.entry(randomAlphaOfLength(randomIntBetween(1, 4)), randomFloat()); | ||
} | ||
} |
Oops, something went wrong.