Skip to content

Commit

Permalink
Merge branch 'main' into functioninfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fang-xing-esql committed Mar 19, 2024
2 parents be168ba + d5565b6 commit f2530d9
Show file tree
Hide file tree
Showing 415 changed files with 3,522 additions and 774 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.benchmark.compute.operator;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.compute.data.Block;
Expand All @@ -26,11 +27,13 @@
import org.elasticsearch.xpack.esql.expression.function.scalar.date.DateTrunc;
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Abs;
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvMin;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Add;
import org.elasticsearch.xpack.esql.planner.Layout;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;
import org.elasticsearch.xpack.ql.expression.FieldAttribute;
import org.elasticsearch.xpack.ql.expression.Literal;
import org.elasticsearch.xpack.ql.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.ql.tree.Source;
import org.elasticsearch.xpack.ql.type.DataTypes;
import org.elasticsearch.xpack.ql.type.EsField;
Expand Down Expand Up @@ -58,7 +61,6 @@
@State(Scope.Thread)
@Fork(1)
public class EvalBenchmark {
private static final BigArrays BIG_ARRAYS = BigArrays.NON_RECYCLING_INSTANCE; // TODO real big arrays?
private static final BlockFactory blockFactory = BlockFactory.getInstance(
new NoopCircuitBreaker("noop"),
BigArrays.NON_RECYCLING_INSTANCE
Expand All @@ -82,7 +84,9 @@ public class EvalBenchmark {
}
}

@Param({ "abs", "add", "date_trunc", "equal_to_const", "long_equal_to_long", "long_equal_to_int", "mv_min", "mv_min_ascending" })
@Param(
{ "abs", "add", "date_trunc", "equal_to_const", "long_equal_to_long", "long_equal_to_int", "mv_min", "mv_min_ascending", "rlike" }
)
public String operation;

private static Operator operator(String operation) {
Expand Down Expand Up @@ -134,6 +138,11 @@ private static EvalOperator.ExpressionEvaluator evaluator(String operation) {
FieldAttribute longField = longField();
yield EvalMapper.toEvaluator(new MvMin(Source.EMPTY, longField), layout(longField)).get(driverContext);
}
case "rlike" -> {
FieldAttribute keywordField = keywordField();
RLike rlike = new RLike(Source.EMPTY, keywordField, new RLikePattern(".ar"));
yield EvalMapper.toEvaluator(rlike, layout(keywordField)).get(driverContext);
}
default -> throw new UnsupportedOperationException();
};
}
Expand All @@ -146,6 +155,10 @@ private static FieldAttribute intField() {
return new FieldAttribute(Source.EMPTY, "int", new EsField("int", DataTypes.INTEGER, Map.of(), true));
}

private static FieldAttribute keywordField() {
return new FieldAttribute(Source.EMPTY, "keyword", new EsField("keyword", DataTypes.KEYWORD, Map.of(), true));
}

private static Layout layout(FieldAttribute... fields) {
Layout.Builder layout = new Layout.Builder();
layout.append(Arrays.asList(fields));
Expand Down Expand Up @@ -205,6 +218,15 @@ private static void checkExpected(String operation, Page actual) {
}
}
}
case "rlike" -> {
BooleanVector v = actual.<BooleanBlock>getBlock(1).asVector();
for (int i = 0; i < BLOCK_LENGTH; i++) {
boolean expected = i % 2 == 1;
if (v.getBoolean(i) != expected) {
throw new AssertionError("[" + operation + "] expected [" + expected + "] but was [" + v.getBoolean(i) + "]");
}
}
}
default -> throw new UnsupportedOperationException();
}
}
Expand Down Expand Up @@ -250,6 +272,14 @@ private static Page page(String operation) {
}
yield new Page(builder.build());
}
case "rlike" -> {
var builder = blockFactory.newBytesRefVectorBuilder(BLOCK_LENGTH);
BytesRef[] values = new BytesRef[] { new BytesRef("foo"), new BytesRef("bar") };
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendBytesRef(values[i % 2]);
}
yield new Page(builder.build().asBlock());
}
default -> throw new UnsupportedOperationException();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.gradle.internal;

import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand Down Expand Up @@ -40,6 +41,7 @@

import javax.inject.Inject;

import static de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME;
import static org.objectweb.asm.Opcodes.V_PREVIEW;

public class MrjarPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -121,6 +123,15 @@ private void addMrjarSourceset(

compileTask.doLast(t -> { stripPreviewFromFiles(compileTask.getDestinationDirectory().getAsFile().get().toPath()); });
});

// Since we configure MRJAR sourcesets to allow preview apis, class signatures for those
// apis are not known by forbidden apis, so we must ignore all missing classes. We could, in theory,
// run forbidden apis in a separate jvm matching the sourceset jvm, but it's not worth
// the complexity (according to forbidden apis author!)
String forbiddenApisTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null);
project.getTasks().withType(CheckForbiddenApisTask.class).named(forbiddenApisTaskName).configure(forbiddenApisTask -> {
forbiddenApisTask.setIgnoreMissingClasses(true);
});
}

private static void stripPreviewFromFiles(Path compileDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.compress.utils.Lists;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainDownload;
import org.gradle.jvm.toolchain.JavaToolchainRequest;
Expand All @@ -21,25 +20,25 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.StreamSupport;

import static org.gradle.jvm.toolchain.JavaToolchainDownload.fromUri;

public abstract class AdoptiumJdkToolchainResolver extends AbstractCustomJavaToolchainResolver {

// package protected for better testing
final Map<AdoptiumVersionRequest, Optional<AdoptiumVersionInfo>> CACHED_SEMVERS = new ConcurrentHashMap<>();
final Map<AdoptiumVersionRequest, Optional<String>> CACHED_RELEASES = new ConcurrentHashMap<>();

@Override
public Optional<JavaToolchainDownload> resolve(JavaToolchainRequest request) {
if (requestIsSupported(request) == false) {
return Optional.empty();
}
AdoptiumVersionRequest versionRequestKey = toVersionRequest(request);
Optional<AdoptiumVersionInfo> versionInfo = CACHED_SEMVERS.computeIfAbsent(
Optional<String> versionInfo = CACHED_RELEASES.computeIfAbsent(
versionRequestKey,
(r) -> resolveAvailableVersion(versionRequestKey)
);
Expand All @@ -54,12 +53,12 @@ private AdoptiumVersionRequest toVersionRequest(JavaToolchainRequest request) {
return new AdoptiumVersionRequest(platform, arch, javaLanguageVersion);
}

private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionRequest requestKey) {
private Optional<String> resolveAvailableVersion(AdoptiumVersionRequest requestKey) {
ObjectMapper mapper = new ObjectMapper();
try {
int languageVersion = requestKey.languageVersion.asInt();
URL source = new URL(
"https://api.adoptium.net/v3/info/release_versions?architecture="
"https://api.adoptium.net/v3/info/release_names?architecture="
+ requestKey.arch
+ "&image_type=jdk&os="
+ requestKey.platform
Expand All @@ -71,14 +70,8 @@ private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionReq
+ ")"
);
JsonNode jsonNode = mapper.readTree(source);
JsonNode versionsNode = jsonNode.get("versions");
return Optional.of(
Lists.newArrayList(versionsNode.iterator())
.stream()
.map(this::toVersionInfo)
.max(Comparator.comparing(AdoptiumVersionInfo::semver))
.get()
);
JsonNode versionsNode = jsonNode.get("releases");
return StreamSupport.stream(versionsNode.spliterator(), false).map(JsonNode::textValue).findFirst();
} catch (FileNotFoundException e) {
// request combo not supported (e.g. aarch64 + windows
return Optional.empty();
Expand All @@ -87,21 +80,10 @@ private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionReq
}
}

private AdoptiumVersionInfo toVersionInfo(JsonNode node) {
return new AdoptiumVersionInfo(
node.get("build").asInt(),
node.get("major").asInt(),
node.get("minor").asInt(),
node.get("openjdk_version").asText(),
node.get("security").asInt(),
node.get("semver").asText()
);
}

private URI resolveDownloadURI(AdoptiumVersionRequest request, AdoptiumVersionInfo versionInfo) {
private URI resolveDownloadURI(AdoptiumVersionRequest request, String version) {
return URI.create(
"https://api.adoptium.net/v3/binary/version/jdk-"
+ versionInfo.semver
"https://api.adoptium.net/v3/binary/version/"
+ version
+ "/"
+ request.platform
+ "/"
Expand All @@ -118,7 +100,5 @@ private boolean requestIsSupported(JavaToolchainRequest request) {
return anyVendorOr(request.getJavaToolchainSpec().getVendor().get(), JvmVendorSpec.ADOPTIUM);
}

record AdoptiumVersionInfo(int build, int major, int minor, String openjdkVersion, int security, String semver) {}

record AdoptiumVersionRequest(String platform, String arch, JavaLanguageVersion languageVersion) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ record JdkBuild(JavaLanguageVersion languageVersion, String version, String buil
);

// package private so it can be replaced by tests
List<JdkBuild> builds = List.of(
getBundledJdkBuild(),
// 22 release candidate
new JdkBuild(JavaLanguageVersion.of(22), "22", "36", "830ec9fcccef480bb3e73fb7ecafe059")
);
List<JdkBuild> builds = List.of(getBundledJdkBuild());

private JdkBuild getBundledJdkBuild() {
String bundledJdkVersion = VersionProperties.getBundledJdkVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package org.elasticsearch.gradle.internal.toolchain
import org.gradle.api.services.BuildServiceParameters
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainResolver
import org.gradle.platform.OperatingSystem

import static org.elasticsearch.gradle.internal.toolchain.AbstractCustomJavaToolchainResolver.toArchString
import static org.elasticsearch.gradle.internal.toolchain.AbstractCustomJavaToolchainResolver.toOsString
Expand All @@ -38,12 +37,7 @@ class AdoptiumJdkToolchainResolverSpec extends AbstractToolchainResolverSpec {
toOsString(it[2], it[1]),
toArchString(it[3]),
languageVersion);
resolver.CACHED_SEMVERS.put(request, Optional.of(new AdoptiumJdkToolchainResolver.AdoptiumVersionInfo(languageVersion.asInt(),
1,
1,
"" + languageVersion.asInt() + ".1.1.1+37",
0, "" + languageVersion.asInt() + ".1.1.1+37.1"
)))
resolver.CACHED_RELEASES.put(request, Optional.of('jdk-' + languageVersion.asInt() + '.1.1.1+37.1'))

}
return resolver
Expand Down
2 changes: 1 addition & 1 deletion build-tools-internal/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ elasticsearch = 8.14.0
lucene = 9.10.0

bundled_jdk_vendor = openjdk
bundled_jdk = 21.0.2+13@f2283984656d49d69e91c558476027ac
bundled_jdk = 22+36@830ec9fcccef480bb3e73fb7ecafe059
# optional dependencies
spatial4j = 0.7
jts = 1.15.0
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/106429.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 106429
summary: "ESQL: Regex improvements"
area: ES|QL
type: enhancement
issues: []
6 changes: 6 additions & 0 deletions docs/changelog/106435.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 106435
summary: "ENRICH support for TEXT fields"
area: ES|QL
type: enhancement
issues:
- 105384
4 changes: 1 addition & 3 deletions docs/reference/esql/functions/abs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Numeric expression. If `null`, the function returns `null`.

Returns the absolute value.

*Supported types*

include::types/abs.asciidoc[]

*Examples*
Expand All @@ -38,4 +36,4 @@ include::{esql-specs}/math.csv-spec[tag=docsAbsEmployees]
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/math.csv-spec[tag=docsAbsEmployees-result]
|===
|===
2 changes: 0 additions & 2 deletions docs/reference/esql/functions/acos.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Numeric expression. If `null`, the function returns `null`.
Returns the {wikipedia}/Inverse_trigonometric_functions[arccosine] of `n` as an
angle, expressed in radians.

*Supported types*

include::types/acos.asciidoc[]

*Example*
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/esql/functions/asin.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Numeric expression. If `null`, the function returns `null`.
Returns the {wikipedia}/Inverse_trigonometric_functions[arcsine] of the input
numeric expression as an angle, expressed in radians.

*Supported types*

include::types/asin.asciidoc[]

*Example*
Expand Down
4 changes: 1 addition & 3 deletions docs/reference/esql/functions/atan.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Numeric expression. If `null`, the function returns `null`.
Returns the {wikipedia}/Inverse_trigonometric_functions[arctangent] of the input
numeric expression as an angle, expressed in radians.

*Supported types*

include::types/atan.asciidoc[]

*Example*
Expand All @@ -30,4 +28,4 @@ include::{esql-specs}/floats.csv-spec[tag=atan]
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/floats.csv-spec[tag=atan-result]
|===
|===
2 changes: 0 additions & 2 deletions docs/reference/esql/functions/atan2.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Numeric expression. If `null`, the function returns `null`.
The {wikipedia}/Atan2[angle] between the positive x-axis and the ray from the
origin to the point (x , y) in the Cartesian plane, expressed in radians.

*Supported types*

include::types/atan2.asciidoc[]

*Example*
Expand Down
Loading

0 comments on commit f2530d9

Please sign in to comment.