Skip to content

Commit 63b694f

Browse files
committed
Merge remote-tracking branch 'elastic/master' into fix-search-remote-fallback
* elastic/master: TEST: Add engine is closed as expected failure msg Adjust bwc version for max_seq_no_of_updates Build DocStats from SegmentInfos in ReadOnlyEngine (elastic#34079) When creating wildcard queries, use MatchNoDocsQuery when the field type doesn't exist. (elastic#34093) [DOCS] Moves graph to docs folder (elastic#33472) Mute MovAvgIT#testHoltWintersNotEnoughData Security: use default scroll keepalive (elastic#33639) Calculate changed roles on roles.yml reload (elastic#33525) Scripting: Reflect factory signatures in painless classloader (elastic#34088) XContentBuilder to handle BigInteger and BigDecimal (elastic#32888) Delegate wildcard query creation to MappedFieldType. (elastic#34062) Painless: Cleanup Cache (elastic#33963)
2 parents dd37252 + ea9b335 commit 63b694f

File tree

44 files changed

+768
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+768
-428
lines changed

docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ buildRestTests.docs = fileTree(projectDir) {
100100
exclude 'reference/rollup/apis/delete-job.asciidoc'
101101
exclude 'reference/rollup/apis/get-job.asciidoc'
102102
exclude 'reference/rollup/apis/rollup-caps.asciidoc'
103+
exclude 'reference/graph/explore.asciidoc'
103104
}
104105

105106
listSnippets.docs = buildRestTests.docs

x-pack/docs/en/rest-api/graph/explore.asciidoc renamed to docs/reference/graph/explore.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[role="xpack"]
2+
[testenv="platinum"]
23
[[graph-explore-api]]
34
== Explore API
45

docs/reference/rest-api/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ directly to configure and access {xpack} features.
1919

2020

2121
include::info.asciidoc[]
22-
include::{xes-repo-dir}/rest-api/graph/explore.asciidoc[]
22+
include::{es-repo-dir}/graph/explore.asciidoc[]
2323
include::{es-repo-dir}/licensing/index.asciidoc[]
2424
include::{es-repo-dir}/migration/migration.asciidoc[]
2525
include::{es-repo-dir}/ml/apis/ml-api.asciidoc[]

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.io.IOException;
2626
import java.io.InputStream;
2727
import java.io.OutputStream;
28+
import java.math.BigDecimal;
29+
import java.math.BigInteger;
2830
import java.nio.file.Path;
2931
import java.time.ZonedDateTime;
3032
import java.util.Arrays;
@@ -103,7 +105,8 @@ public static XContentBuilder builder(XContent xContent, Set<String> includes, S
103105
writers.put(ZonedDateTime.class, (b, v) -> b.value(v.toString()));
104106
writers.put(Calendar.class, XContentBuilder::timeValue);
105107
writers.put(GregorianCalendar.class, XContentBuilder::timeValue);
106-
108+
writers.put(BigInteger.class, (b, v) -> b.value((BigInteger) v));
109+
writers.put(BigDecimal.class, (b, v) -> b.value((BigDecimal) v));
107110

108111
Map<Class<?>, HumanReadableTransformer> humanReadableTransformer = new HashMap<>();
109112
Map<Class<?>, Function<Object, Object>> dateTransformers = new HashMap<>();
@@ -546,6 +549,81 @@ public XContentBuilder value(short value) throws IOException {
546549
return this;
547550
}
548551

552+
////////////////////////////////////////////////////////////////////////////
553+
// BigInteger
554+
//////////////////////////////////
555+
556+
public XContentBuilder field(String name, BigInteger value) throws IOException {
557+
if (value == null) {
558+
return nullField(name);
559+
}
560+
ensureNameNotNull(name);
561+
generator.writeNumberField(name, value);
562+
return this;
563+
}
564+
565+
public XContentBuilder array(String name, BigInteger[] values) throws IOException {
566+
return field(name).values(values);
567+
}
568+
569+
private XContentBuilder values(BigInteger[] values) throws IOException {
570+
if (values == null) {
571+
return nullValue();
572+
}
573+
startArray();
574+
for (BigInteger b : values) {
575+
value(b);
576+
}
577+
endArray();
578+
return this;
579+
}
580+
581+
public XContentBuilder value(BigInteger value) throws IOException {
582+
if (value == null) {
583+
return nullValue();
584+
}
585+
generator.writeNumber(value);
586+
return this;
587+
}
588+
589+
590+
////////////////////////////////////////////////////////////////////////////
591+
// BigDecimal
592+
//////////////////////////////////
593+
594+
public XContentBuilder field(String name, BigDecimal value) throws IOException {
595+
if (value == null) {
596+
return nullField(name);
597+
}
598+
ensureNameNotNull(name);
599+
generator.writeNumberField(name, value);
600+
return this;
601+
}
602+
603+
public XContentBuilder array(String name, BigDecimal[] values) throws IOException {
604+
return field(name).values(values);
605+
}
606+
607+
private XContentBuilder values(BigDecimal[] values) throws IOException {
608+
if (values == null) {
609+
return nullValue();
610+
}
611+
startArray();
612+
for (BigDecimal b : values) {
613+
value(b);
614+
}
615+
endArray();
616+
return this;
617+
}
618+
619+
public XContentBuilder value(BigDecimal value) throws IOException {
620+
if (value == null) {
621+
return nullValue();
622+
}
623+
generator.writeNumber(value);
624+
return this;
625+
}
626+
549627
////////////////////////////////////////////////////////////////////////////
550628
// String
551629
//////////////////////////////////

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.io.Flushable;
2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.math.BigDecimal;
27+
import java.math.BigInteger;
2628

2729
public interface XContentGenerator extends Closeable, Flushable {
2830

@@ -70,6 +72,14 @@ public interface XContentGenerator extends Closeable, Flushable {
7072

7173
void writeNumber(short value) throws IOException;
7274

75+
void writeNumber(BigInteger value) throws IOException;
76+
77+
void writeNumberField(String name, BigInteger value) throws IOException;
78+
79+
void writeNumber(BigDecimal value) throws IOException;
80+
81+
void writeNumberField(String name, BigDecimal value) throws IOException;
82+
7383
void writeStringField(String name, String value) throws IOException;
7484

7585
void writeString(String value) throws IOException;

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import java.io.IOException;
4343
import java.io.InputStream;
4444
import java.io.OutputStream;
45+
import java.math.BigDecimal;
46+
import java.math.BigInteger;
4547
import java.util.Objects;
4648
import java.util.Set;
4749

@@ -226,6 +228,19 @@ public void writeNumberField(String name, int value) throws IOException {
226228
generator.writeNumberField(name, value);
227229
}
228230

231+
@Override
232+
public void writeNumberField(String name, BigInteger value) throws IOException {
233+
// as jackson's JsonGenerator doesn't have this method for BigInteger
234+
// we have to implement it ourselves
235+
generator.writeFieldName(name);
236+
generator.writeNumber(value);
237+
}
238+
239+
@Override
240+
public void writeNumberField(String name, BigDecimal value) throws IOException {
241+
generator.writeNumberField(name, value);
242+
}
243+
229244
@Override
230245
public void writeNumber(int value) throws IOException {
231246
generator.writeNumber(value);
@@ -246,6 +261,16 @@ public void writeNumber(short value) throws IOException {
246261
generator.writeNumber(value);
247262
}
248263

264+
@Override
265+
public void writeNumber(BigInteger value) throws IOException {
266+
generator.writeNumber(value);
267+
}
268+
269+
@Override
270+
public void writeNumber(BigDecimal value) throws IOException {
271+
generator.writeNumber(value);
272+
}
273+
249274
@Override
250275
public void writeStringField(String name, String value) throws IOException {
251276
generator.writeStringField(name, value);

modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import org.objectweb.asm.util.Printer;
2929

3030
import java.lang.reflect.Constructor;
31+
import java.lang.reflect.Method;
3132
import java.net.MalformedURLException;
3233
import java.net.URL;
3334
import java.security.CodeSource;
3435
import java.security.SecureClassLoader;
3536
import java.security.cert.Certificate;
37+
import java.util.Collections;
38+
import java.util.HashMap;
3639
import java.util.Map;
3740
import java.util.concurrent.atomic.AtomicInteger;
3841

@@ -89,16 +92,11 @@ final class Loader extends SecureClassLoader {
8992
*/
9093
@Override
9194
public Class<?> findClass(String name) throws ClassNotFoundException {
92-
if (scriptClass.getName().equals(name)) {
93-
return scriptClass;
95+
Class<?> found = additionalClasses.get(name);
96+
if (found != null) {
97+
return found;
9498
}
95-
if (factoryClass != null && factoryClass.getName().equals(name)) {
96-
return factoryClass;
97-
}
98-
if (statefulFactoryClass != null && statefulFactoryClass.getName().equals(name)) {
99-
return statefulFactoryClass;
100-
}
101-
Class<?> found = painlessLookup.canonicalTypeNameToType(name.replace('$', '.'));
99+
found = painlessLookup.canonicalTypeNameToType(name.replace('$', '.'));
102100

103101
return found != null ? found : super.findClass(name);
104102
}
@@ -156,19 +154,14 @@ public Loader createLoader(ClassLoader parent) {
156154
private final Class<?> scriptClass;
157155

158156
/**
159-
* The class/interface to create the {@code scriptClass} instance.
160-
*/
161-
private final Class<?> factoryClass;
162-
163-
/**
164-
* An optional class/interface to create the {@code factoryClass} instance.
157+
* The whitelist the script will use.
165158
*/
166-
private final Class<?> statefulFactoryClass;
159+
private final PainlessLookup painlessLookup;
167160

168161
/**
169-
* The whitelist the script will use.
162+
* Classes that do not exist in the lookup, but are needed by the script factories.
170163
*/
171-
private final PainlessLookup painlessLookup;
164+
private final Map<String, Class<?>> additionalClasses;
172165

173166
/**
174167
* Standard constructor.
@@ -179,9 +172,36 @@ public Loader createLoader(ClassLoader parent) {
179172
*/
180173
Compiler(Class<?> scriptClass, Class<?> factoryClass, Class<?> statefulFactoryClass, PainlessLookup painlessLookup) {
181174
this.scriptClass = scriptClass;
182-
this.factoryClass = factoryClass;
183-
this.statefulFactoryClass = statefulFactoryClass;
184175
this.painlessLookup = painlessLookup;
176+
Map<String, Class<?>> additionalClasses = new HashMap<>();
177+
additionalClasses.put(scriptClass.getName(), scriptClass);
178+
addFactoryMethod(additionalClasses, factoryClass, "newInstance");
179+
addFactoryMethod(additionalClasses, statefulFactoryClass, "newFactory");
180+
addFactoryMethod(additionalClasses, statefulFactoryClass, "newInstance");
181+
this.additionalClasses = Collections.unmodifiableMap(additionalClasses);
182+
}
183+
184+
private static void addFactoryMethod(Map<String, Class<?>> additionalClasses, Class<?> factoryClass, String methodName) {
185+
if (factoryClass == null) {
186+
return;
187+
}
188+
189+
Method factoryMethod = null;
190+
for (Method method : factoryClass.getMethods()) {
191+
if (methodName.equals(method.getName())) {
192+
factoryMethod = method;
193+
break;
194+
}
195+
}
196+
if (factoryMethod == null) {
197+
return;
198+
}
199+
200+
additionalClasses.put(factoryClass.getName(), factoryClass);
201+
for (int i = 0; i < factoryMethod.getParameterTypes().length; ++i) {
202+
Class<?> parameterClazz = factoryMethod.getParameterTypes()[i];
203+
additionalClasses.put(parameterClazz.getName(), parameterClazz);
204+
}
185205
}
186206

187207
/**

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessCast.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,59 @@
1919

2020
package org.elasticsearch.painless.lookup;
2121

22+
import java.util.Objects;
23+
2224
public class PainlessCast {
2325

2426
/** Create a standard cast with no boxing/unboxing. */
2527
public static PainlessCast originalTypetoTargetType(Class<?> originalType, Class<?> targetType, boolean explicitCast) {
28+
Objects.requireNonNull(originalType);
29+
Objects.requireNonNull(targetType);
30+
2631
return new PainlessCast(originalType, targetType, explicitCast, null, null, null, null);
2732
}
2833

2934
/** Create a cast where the original type will be unboxed, and then the cast will be performed. */
3035
public static PainlessCast unboxOriginalType(
3136
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxOriginalType) {
3237

38+
Objects.requireNonNull(originalType);
39+
Objects.requireNonNull(targetType);
40+
Objects.requireNonNull(unboxOriginalType);
41+
3342
return new PainlessCast(originalType, targetType, explicitCast, unboxOriginalType, null, null, null);
3443
}
3544

3645
/** Create a cast where the target type will be unboxed, and then the cast will be performed. */
3746
public static PainlessCast unboxTargetType(
3847
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxTargetType) {
3948

49+
Objects.requireNonNull(originalType);
50+
Objects.requireNonNull(targetType);
51+
Objects.requireNonNull(unboxTargetType);
52+
4053
return new PainlessCast(originalType, targetType, explicitCast, null, unboxTargetType, null, null);
4154
}
4255

4356
/** Create a cast where the original type will be boxed, and then the cast will be performed. */
4457
public static PainlessCast boxOriginalType(
4558
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxOriginalType) {
4659

60+
Objects.requireNonNull(originalType);
61+
Objects.requireNonNull(targetType);
62+
Objects.requireNonNull(boxOriginalType);
63+
4764
return new PainlessCast(originalType, targetType, explicitCast, null, null, boxOriginalType, null);
4865
}
4966

5067
/** Create a cast where the target type will be boxed, and then the cast will be performed. */
5168
public static PainlessCast boxTargetType(
5269
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxTargetType) {
5370

71+
Objects.requireNonNull(originalType);
72+
Objects.requireNonNull(targetType);
73+
Objects.requireNonNull(boxTargetType);
74+
5475
return new PainlessCast(originalType, targetType, explicitCast, null, null, null, boxTargetType);
5576
}
5677

@@ -73,4 +94,30 @@ private PainlessCast(Class<?> originalType, Class<?> targetType, boolean explici
7394
this.boxOriginalType = boxOriginalType;
7495
this.boxTargetType = boxTargetType;
7596
}
97+
98+
@Override
99+
public boolean equals(Object object) {
100+
if (this == object) {
101+
return true;
102+
}
103+
104+
if (object == null || getClass() != object.getClass()) {
105+
return false;
106+
}
107+
108+
PainlessCast that = (PainlessCast)object;
109+
110+
return explicitCast == that.explicitCast &&
111+
Objects.equals(originalType, that.originalType) &&
112+
Objects.equals(targetType, that.targetType) &&
113+
Objects.equals(unboxOriginalType, that.unboxOriginalType) &&
114+
Objects.equals(unboxTargetType, that.unboxTargetType) &&
115+
Objects.equals(boxOriginalType, that.boxOriginalType) &&
116+
Objects.equals(boxTargetType, that.boxTargetType);
117+
}
118+
119+
@Override
120+
public int hashCode() {
121+
return Objects.hash(originalType, targetType, explicitCast, unboxOriginalType, unboxTargetType, boxOriginalType, boxTargetType);
122+
}
76123
}

0 commit comments

Comments
 (0)