Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/master' into fix-search-remote-…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
jasontedor committed Sep 27, 2018
2 parents dd37252 + ea9b335 commit 63b694f
Show file tree
Hide file tree
Showing 44 changed files with 768 additions and 428 deletions.
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ buildRestTests.docs = fileTree(projectDir) {
exclude 'reference/rollup/apis/delete-job.asciidoc'
exclude 'reference/rollup/apis/get-job.asciidoc'
exclude 'reference/rollup/apis/rollup-caps.asciidoc'
exclude 'reference/graph/explore.asciidoc'
}

listSnippets.docs = buildRestTests.docs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[role="xpack"]
[testenv="platinum"]
[[graph-explore-api]]
== Explore API

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/rest-api/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ directly to configure and access {xpack} features.


include::info.asciidoc[]
include::{xes-repo-dir}/rest-api/graph/explore.asciidoc[]
include::{es-repo-dir}/graph/explore.asciidoc[]
include::{es-repo-dir}/licensing/index.asciidoc[]
include::{es-repo-dir}/migration/migration.asciidoc[]
include::{es-repo-dir}/ml/apis/ml-api.asciidoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.Arrays;
Expand Down Expand Up @@ -103,7 +105,8 @@ public static XContentBuilder builder(XContent xContent, Set<String> includes, S
writers.put(ZonedDateTime.class, (b, v) -> b.value(v.toString()));
writers.put(Calendar.class, XContentBuilder::timeValue);
writers.put(GregorianCalendar.class, XContentBuilder::timeValue);

writers.put(BigInteger.class, (b, v) -> b.value((BigInteger) v));
writers.put(BigDecimal.class, (b, v) -> b.value((BigDecimal) v));

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

////////////////////////////////////////////////////////////////////////////
// BigInteger
//////////////////////////////////

public XContentBuilder field(String name, BigInteger value) throws IOException {
if (value == null) {
return nullField(name);
}
ensureNameNotNull(name);
generator.writeNumberField(name, value);
return this;
}

public XContentBuilder array(String name, BigInteger[] values) throws IOException {
return field(name).values(values);
}

private XContentBuilder values(BigInteger[] values) throws IOException {
if (values == null) {
return nullValue();
}
startArray();
for (BigInteger b : values) {
value(b);
}
endArray();
return this;
}

public XContentBuilder value(BigInteger value) throws IOException {
if (value == null) {
return nullValue();
}
generator.writeNumber(value);
return this;
}


////////////////////////////////////////////////////////////////////////////
// BigDecimal
//////////////////////////////////

public XContentBuilder field(String name, BigDecimal value) throws IOException {
if (value == null) {
return nullField(name);
}
ensureNameNotNull(name);
generator.writeNumberField(name, value);
return this;
}

public XContentBuilder array(String name, BigDecimal[] values) throws IOException {
return field(name).values(values);
}

private XContentBuilder values(BigDecimal[] values) throws IOException {
if (values == null) {
return nullValue();
}
startArray();
for (BigDecimal b : values) {
value(b);
}
endArray();
return this;
}

public XContentBuilder value(BigDecimal value) throws IOException {
if (value == null) {
return nullValue();
}
generator.writeNumber(value);
return this;
}

////////////////////////////////////////////////////////////////////////////
// String
//////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;

public interface XContentGenerator extends Closeable, Flushable {

Expand Down Expand Up @@ -70,6 +72,14 @@ public interface XContentGenerator extends Closeable, Flushable {

void writeNumber(short value) throws IOException;

void writeNumber(BigInteger value) throws IOException;

void writeNumberField(String name, BigInteger value) throws IOException;

void writeNumber(BigDecimal value) throws IOException;

void writeNumberField(String name, BigDecimal value) throws IOException;

void writeStringField(String name, String value) throws IOException;

void writeString(String value) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;
import java.util.Set;

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

@Override
public void writeNumberField(String name, BigInteger value) throws IOException {
// as jackson's JsonGenerator doesn't have this method for BigInteger
// we have to implement it ourselves
generator.writeFieldName(name);
generator.writeNumber(value);
}

@Override
public void writeNumberField(String name, BigDecimal value) throws IOException {
generator.writeNumberField(name, value);
}

@Override
public void writeNumber(int value) throws IOException {
generator.writeNumber(value);
Expand All @@ -246,6 +261,16 @@ public void writeNumber(short value) throws IOException {
generator.writeNumber(value);
}

@Override
public void writeNumber(BigInteger value) throws IOException {
generator.writeNumber(value);
}

@Override
public void writeNumber(BigDecimal value) throws IOException {
generator.writeNumber(value);
}

@Override
public void writeStringField(String name, String value) throws IOException {
generator.writeStringField(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import org.objectweb.asm.util.Printer;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.SecureClassLoader;
import java.security.cert.Certificate;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -89,16 +92,11 @@ final class Loader extends SecureClassLoader {
*/
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
if (scriptClass.getName().equals(name)) {
return scriptClass;
Class<?> found = additionalClasses.get(name);
if (found != null) {
return found;
}
if (factoryClass != null && factoryClass.getName().equals(name)) {
return factoryClass;
}
if (statefulFactoryClass != null && statefulFactoryClass.getName().equals(name)) {
return statefulFactoryClass;
}
Class<?> found = painlessLookup.canonicalTypeNameToType(name.replace('$', '.'));
found = painlessLookup.canonicalTypeNameToType(name.replace('$', '.'));

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

/**
* The class/interface to create the {@code scriptClass} instance.
*/
private final Class<?> factoryClass;

/**
* An optional class/interface to create the {@code factoryClass} instance.
* The whitelist the script will use.
*/
private final Class<?> statefulFactoryClass;
private final PainlessLookup painlessLookup;

/**
* The whitelist the script will use.
* Classes that do not exist in the lookup, but are needed by the script factories.
*/
private final PainlessLookup painlessLookup;
private final Map<String, Class<?>> additionalClasses;

/**
* Standard constructor.
Expand All @@ -179,9 +172,36 @@ public Loader createLoader(ClassLoader parent) {
*/
Compiler(Class<?> scriptClass, Class<?> factoryClass, Class<?> statefulFactoryClass, PainlessLookup painlessLookup) {
this.scriptClass = scriptClass;
this.factoryClass = factoryClass;
this.statefulFactoryClass = statefulFactoryClass;
this.painlessLookup = painlessLookup;
Map<String, Class<?>> additionalClasses = new HashMap<>();
additionalClasses.put(scriptClass.getName(), scriptClass);
addFactoryMethod(additionalClasses, factoryClass, "newInstance");
addFactoryMethod(additionalClasses, statefulFactoryClass, "newFactory");
addFactoryMethod(additionalClasses, statefulFactoryClass, "newInstance");
this.additionalClasses = Collections.unmodifiableMap(additionalClasses);
}

private static void addFactoryMethod(Map<String, Class<?>> additionalClasses, Class<?> factoryClass, String methodName) {
if (factoryClass == null) {
return;
}

Method factoryMethod = null;
for (Method method : factoryClass.getMethods()) {
if (methodName.equals(method.getName())) {
factoryMethod = method;
break;
}
}
if (factoryMethod == null) {
return;
}

additionalClasses.put(factoryClass.getName(), factoryClass);
for (int i = 0; i < factoryMethod.getParameterTypes().length; ++i) {
Class<?> parameterClazz = factoryMethod.getParameterTypes()[i];
additionalClasses.put(parameterClazz.getName(), parameterClazz);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,59 @@

package org.elasticsearch.painless.lookup;

import java.util.Objects;

public class PainlessCast {

/** Create a standard cast with no boxing/unboxing. */
public static PainlessCast originalTypetoTargetType(Class<?> originalType, Class<?> targetType, boolean explicitCast) {
Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, null, null);
}

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

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(unboxOriginalType);

return new PainlessCast(originalType, targetType, explicitCast, unboxOriginalType, null, null, null);
}

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

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(unboxTargetType);

return new PainlessCast(originalType, targetType, explicitCast, null, unboxTargetType, null, null);
}

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

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(boxOriginalType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, boxOriginalType, null);
}

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

Objects.requireNonNull(originalType);
Objects.requireNonNull(targetType);
Objects.requireNonNull(boxTargetType);

return new PainlessCast(originalType, targetType, explicitCast, null, null, null, boxTargetType);
}

Expand All @@ -73,4 +94,30 @@ private PainlessCast(Class<?> originalType, Class<?> targetType, boolean explici
this.boxOriginalType = boxOriginalType;
this.boxTargetType = boxTargetType;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (object == null || getClass() != object.getClass()) {
return false;
}

PainlessCast that = (PainlessCast)object;

return explicitCast == that.explicitCast &&
Objects.equals(originalType, that.originalType) &&
Objects.equals(targetType, that.targetType) &&
Objects.equals(unboxOriginalType, that.unboxOriginalType) &&
Objects.equals(unboxTargetType, that.unboxTargetType) &&
Objects.equals(boxOriginalType, that.boxOriginalType) &&
Objects.equals(boxTargetType, that.boxTargetType);
}

@Override
public int hashCode() {
return Objects.hash(originalType, targetType, explicitCast, unboxOriginalType, unboxTargetType, boxOriginalType, boxTargetType);
}
}
Loading

0 comments on commit 63b694f

Please sign in to comment.