Skip to content

Commit

Permalink
Merge remote-tracking branch 'es/6.x' into ccr-6.x
Browse files Browse the repository at this point in the history
* es/6.x:
  Scripting: Remove dead code from painless module (#32064) (#32104)
  Painless: Move and Rename Several Methods in the lookup package (#32105)
  Bypass highlight query terms extraction on empty fields (#32090)
  Core: Backport java time date formatters (#31997)
  Switch non-x-pack to new style requests (#32106)
  SQL: allow LEFT and RIGHT as function names (#32066)
  Painless: Separate PainlessLookup into PainlessLookup and PainlessLookupBuilder (#32054)
  [test] turn on host io cache for opensuse (#32053)
  DOCS: put LIMIT 10 to the SQL query (#32065)
  • Loading branch information
martijnvg committed Jul 17, 2018
2 parents 3cccc98 + f555426 commit 38f8cdb
Show file tree
Hide file tree
Showing 87 changed files with 3,972 additions and 2,017 deletions.
5 changes: 5 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Vagrant.configure(2) do |config|
'opensuse-42'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = 'elastic/opensuse-42-x86_64'

# https://github.com/elastic/elasticsearch/issues/30295
config.vm.provider 'virtualbox' do |vbox|
vbox.customize ['storagectl', :id, '--name', 'SATA Controller', '--hostiocache', 'on']
end
suse_common config, box
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ In SQL, the above aggregation is similar in concept to:

[source,sh]
--------------------------------------------------
SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC
SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC LIMIT 10;
--------------------------------------------------

And the response (partially shown):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import org.elasticsearch.ingest.TestTemplateService;
import org.elasticsearch.script.TemplateScript;
import org.elasticsearch.test.ESTestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -36,19 +37,21 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.joda.time.DateTimeZone.UTC;

public class DateProcessorTests extends ESTestCase {

private TemplateScript.Factory templatize(Locale locale) {
return new TestTemplateService.MockTemplateScript.Factory(locale.getLanguage());
}

private TemplateScript.Factory templatize(DateTimeZone timezone) {
return new TestTemplateService.MockTemplateScript.Factory(timezone.getID());
private TemplateScript.Factory templatize(ZoneId timezone) {
// prevent writing "UTC" as string, as joda time does not parse it
String id = timezone.equals(ZoneOffset.UTC) ? "UTC" : timezone.getId();
return new TestTemplateService.MockTemplateScript.Factory(id);
}
public void testJodaPattern() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10),
templatize(DateTimeZone.forID("Europe/Amsterdam")), templatize(Locale.ENGLISH),
templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH),
"date_as_string", Collections.singletonList("yyyy dd MM hh:mm:ss"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 06 11:05:15");
Expand All @@ -63,7 +66,7 @@ public void testJodaPatternMultipleFormats() {
matchFormats.add("dd/MM/yyyy");
matchFormats.add("dd-MM-yyyy");
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10),
templatize(DateTimeZone.forID("Europe/Amsterdam")), templatize(Locale.ENGLISH),
templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH),
"date_as_string", matchFormats, "date_as_date");

Map<String, Object> document = new HashMap<>();
Expand Down Expand Up @@ -98,7 +101,7 @@ public void testJodaPatternMultipleFormats() {
public void testInvalidJodaPattern() {
try {
DateProcessor processor = new DateProcessor(randomAlphaOfLength(10),
templatize(UTC), templatize(randomLocale(random())),
templatize(ZoneOffset.UTC), templatize(randomLocale(random())),
"date_as_string", Collections.singletonList("invalid pattern"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010");
Expand All @@ -112,7 +115,7 @@ public void testInvalidJodaPattern() {

public void testJodaPatternLocale() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10),
templatize(DateTimeZone.forID("Europe/Amsterdam")), templatize(Locale.ITALIAN),
templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ITALIAN),
"date_as_string", Collections.singletonList("yyyy dd MMM"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 giugno");
Expand All @@ -123,18 +126,18 @@ public void testJodaPatternLocale() {

public void testJodaPatternDefaultYear() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10),
templatize(DateTimeZone.forID("Europe/Amsterdam")), templatize(Locale.ENGLISH),
templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH),
"date_as_string", Collections.singletonList("dd/MM"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "12/06");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class),
equalTo(DateTime.now().getYear() + "-06-12T00:00:00.000+02:00"));
equalTo(ZonedDateTime.now().getYear() + "-06-12T00:00:00.000+02:00"));
}

public void testTAI64N() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(DateTimeZone.forOffsetHours(2)),
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(ZoneOffset.ofHours(2)),
templatize(randomLocale(random())),
"date_as_string", Collections.singletonList("TAI64N"), "date_as_date");
Map<String, Object> document = new HashMap<>();
Expand All @@ -146,8 +149,8 @@ public void testTAI64N() {
}

public void testUnixMs() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(UTC), templatize(randomLocale(random())),
"date_as_string", Collections.singletonList("UNIX_MS"), "date_as_date");
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(ZoneOffset.UTC),
templatize(randomLocale(random())), "date_as_string", Collections.singletonList("UNIX_MS"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "1000500");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
Expand All @@ -162,7 +165,7 @@ public void testUnixMs() {
}

public void testUnix() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(UTC),
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), templatize(ZoneOffset.UTC),
templatize(randomLocale(random())),
"date_as_string", Collections.singletonList("UNIX"), "date_as_date");
Map<String, Object> document = new HashMap<>();
Expand All @@ -186,7 +189,7 @@ public void testInvalidTimezone() {

public void testInvalidLocale() {
DateProcessor processor = new DateProcessor(randomAlphaOfLength(10),
templatize(UTC), new TestTemplateService.MockTemplateScript.Factory("invalid_locale"),
templatize(ZoneOffset.UTC), new TestTemplateService.MockTemplateScript.Factory("invalid_locale"),
"date_as_string", Collections.singletonList("yyyy"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.painless;

import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessCast;
import org.elasticsearch.painless.lookup.PainlessLookup.def;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
import org.elasticsearch.painless.lookup.def;

import java.util.Objects;

Expand Down Expand Up @@ -465,8 +465,9 @@ public static PainlessCast getLegalCast(Location location, Class<?> actual, Clas
(actual.isAssignableFrom(expected) && explicit)) {
return PainlessCast.standard(actual, expected, explicit);
} else {
throw location.createError(new ClassCastException(
"Cannot cast from [" + PainlessLookup.ClassToName(actual) + "] to [" + PainlessLookup.ClassToName(expected) + "]."));
throw location.createError(new ClassCastException("Cannot cast from " +
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(actual) + "] to " +
"[" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "]."));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

package org.elasticsearch.painless;

import org.elasticsearch.painless.lookup.PainlessClass;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
import org.elasticsearch.painless.lookup.PainlessMethod;
import org.elasticsearch.painless.lookup.PainlessClass;
import org.elasticsearch.painless.lookup.PainlessMethodKey;

import java.lang.invoke.CallSite;
Expand Down Expand Up @@ -302,7 +303,7 @@ static MethodHandle lookupMethod(PainlessLookup painlessLookup, MethodHandles.Lo
nestedType,
0,
DefBootstrap.REFERENCE,
PainlessLookup.ClassToName(interfaceType));
PainlessLookupUtility.anyTypeToPainlessTypeName(interfaceType));
filter = nested.dynamicInvoker();
} else {
throw new AssertionError();
Expand Down Expand Up @@ -347,7 +348,7 @@ private static MethodHandle lookupReferenceInternal(PainlessLookup painlessLooku
PainlessMethod interfaceMethod = painlessLookup.getPainlessStructFromJavaClass(clazz).functionalMethod;
if (interfaceMethod == null) {
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
"to [" + PainlessLookup.ClassToName(clazz) + "], not a functional interface");
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(clazz) + "], not a functional interface");
}
int arity = interfaceMethod.arguments.size() + captures.length;
final MethodHandle handle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.painless.lookup.PainlessClass;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
import org.elasticsearch.painless.lookup.PainlessMethod;
import org.elasticsearch.painless.lookup.PainlessMethodKey;
import org.objectweb.asm.Type;
Expand Down Expand Up @@ -168,7 +169,7 @@ private static PainlessMethod lookup(PainlessLookup painlessLookup, Class<?> exp
PainlessMethod method = painlessLookup.getPainlessStructFromJavaClass(expected).functionalMethod;
if (method == null) {
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
"to [" + PainlessLookup.ClassToName(expected) + "], not a functional interface");
"to [" + PainlessLookupUtility.anyTypeToPainlessTypeName(expected) + "], not a functional interface");
}

// lookup requested method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

package org.elasticsearch.painless;

import org.elasticsearch.painless.ScriptClassInfo.MethodArgument;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;
import org.elasticsearch.painless.lookup.PainlessMethod;
import org.elasticsearch.painless.lookup.PainlessMethodKey;
import org.elasticsearch.painless.ScriptClassInfo.MethodArgument;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -292,7 +293,7 @@ public int getSlot() {
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Variable[type=").append(PainlessLookup.ClassToName(clazz));
b.append("Variable[type=").append(PainlessLookupUtility.anyTypeToPainlessTypeName(clazz));
b.append(",name=").append(name);
b.append(",slot=").append(slot);
if (readonly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.painless;

import org.elasticsearch.painless.lookup.PainlessCast;
import org.elasticsearch.painless.lookup.PainlessLookup.def;
import org.elasticsearch.painless.lookup.def;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -227,14 +227,6 @@ public static Type getType(Class<?> clazz) {
return Type.getType(clazz);
}

public void writeBranch(final Label tru, final Label fals) {
if (tru != null) {
visitJumpInsn(Opcodes.IFNE, tru);
} else if (fals != null) {
visitJumpInsn(Opcodes.IFEQ, fals);
}
}

/** Starts a new string concat.
* @return the size of arguments pushed to stack (the object that does string concats, e.g. a StringBuilder)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.painless.Compiler.Loader;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupBuilder;
import org.elasticsearch.painless.spi.Whitelist;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.ScriptContext;
Expand Down Expand Up @@ -102,9 +102,11 @@ public PainlessScriptEngine(Settings settings, Map<ScriptContext<?>, List<Whitel
for (Map.Entry<ScriptContext<?>, List<Whitelist>> entry : contexts.entrySet()) {
ScriptContext<?> context = entry.getKey();
if (context.instanceClazz.equals(SearchScript.class) || context.instanceClazz.equals(ExecutableScript.class)) {
contextsToCompilers.put(context, new Compiler(GenericElasticsearchScript.class, new PainlessLookup(entry.getValue())));
contextsToCompilers.put(context, new Compiler(GenericElasticsearchScript.class,
new PainlessLookupBuilder(entry.getValue()).build()));
} else {
contextsToCompilers.put(context, new Compiler(context.instanceClazz, new PainlessLookup(entry.getValue())));
contextsToCompilers.put(context, new Compiler(context.instanceClazz,
new PainlessLookupBuilder(entry.getValue()).build()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.painless;

import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupUtility;

import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -182,7 +183,7 @@ private MethodArgument methodArgument(PainlessLookup painlessLookup, Class<?> cl

private static Class<?> definitionTypeForClass(PainlessLookup painlessLookup, Class<?> type,
Function<Class<?>, String> unknownErrorMessageSource) {
type = PainlessLookup.ObjectClassTodefClass(type);
type = PainlessLookupUtility.javaObjectTypeToPainlessDefType(type);
Class<?> componentType = type;

while (componentType.isArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.antlr.v4.runtime.LexerNoViableAltException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.Interval;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.lookup.PainlessLookup;

/**
* A lexer that is customized for painless. It:
Expand Down

This file was deleted.

Loading

0 comments on commit 38f8cdb

Please sign in to comment.