Dates accessed from scripts should use UTC timezone
this was broken in the field data refactoring we did in 0.90, fixes #3091
This commit is contained in:
parent
24fccc91d8
commit
b4d75a50bf
|
@ -39,9 +39,9 @@ public abstract class AtomicNumericFieldData implements AtomicFieldData<ScriptDo
|
||||||
@Override
|
@Override
|
||||||
public ScriptDocValues getScriptValues() {
|
public ScriptDocValues getScriptValues() {
|
||||||
if (isFloat) {
|
if (isFloat) {
|
||||||
return new ScriptDocValues.NumericDouble(getDoubleValues());
|
return new ScriptDocValues.Doubles(getDoubleValues());
|
||||||
} else {
|
} else {
|
||||||
return new ScriptDocValues.NumericLong(getLongValues());
|
return new ScriptDocValues.Longs(getLongValues());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.fielddata;
|
package org.elasticsearch.index.fielddata;
|
||||||
|
|
||||||
import java.util.Collections;
|
import org.apache.lucene.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.lucene.util.ArrayUtil;
|
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.apache.lucene.util.CharsRef;
|
|
||||||
import org.apache.lucene.util.RamUsageEstimator;
|
|
||||||
import org.apache.lucene.util.UnicodeUtil;
|
|
||||||
import org.elasticsearch.common.geo.GeoDistance;
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.geo.GeoPoint;
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
|
@ -34,8 +27,12 @@ import org.elasticsearch.common.util.SlicedDoubleList;
|
||||||
import org.elasticsearch.common.util.SlicedLongList;
|
import org.elasticsearch.common.util.SlicedLongList;
|
||||||
import org.elasticsearch.common.util.SlicedObjectList;
|
import org.elasticsearch.common.util.SlicedObjectList;
|
||||||
import org.elasticsearch.index.fielddata.BytesValues.Iter;
|
import org.elasticsearch.index.fielddata.BytesValues.Iter;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.MutableDateTime;
|
import org.joda.time.MutableDateTime;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Script level doc values, the assumption is that any implementation will implement a <code>getValue</code>
|
* Script level doc values, the assumption is that any implementation will implement a <code>getValue</code>
|
||||||
* and a <code>getValues</code> that return the relevant type that then can be used in scripts.
|
* and a <code>getValues</code> that return the relevant type that then can be used in scripts.
|
||||||
|
@ -115,9 +112,9 @@ public abstract class ScriptDocValues {
|
||||||
list.offset = 0;
|
list.offset = 0;
|
||||||
list.length = 0;
|
list.length = 0;
|
||||||
Iter iter = values.getIter(docId);
|
Iter iter = values.getIter(docId);
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
BytesRef next = iter.next();
|
BytesRef next = iter.next();
|
||||||
list.grow(list.length+1);
|
list.grow(list.length + 1);
|
||||||
UnicodeUtil.UTF8toUTF16(next, spare);
|
UnicodeUtil.UTF8toUTF16(next, spare);
|
||||||
list.values[list.length++] = spare.toString();
|
list.values[list.length++] = spare.toString();
|
||||||
}
|
}
|
||||||
|
@ -129,14 +126,13 @@ public abstract class ScriptDocValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Longs extends ScriptDocValues {
|
||||||
public static class NumericLong extends ScriptDocValues {
|
|
||||||
|
|
||||||
private final LongValues values;
|
private final LongValues values;
|
||||||
private final MutableDateTime date = new MutableDateTime(0);
|
private final MutableDateTime date = new MutableDateTime(0, DateTimeZone.UTC);
|
||||||
private final SlicedLongList list;
|
private final SlicedLongList list;
|
||||||
|
|
||||||
public NumericLong(LongValues values) {
|
public Longs(LongValues values) {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.list = new SlicedLongList(values.isMultiValued() ? 10 : 1);
|
this.list = new SlicedLongList(values.isMultiValued() ? 10 : 1);
|
||||||
}
|
}
|
||||||
|
@ -155,8 +151,8 @@ public abstract class ScriptDocValues {
|
||||||
final LongValues.Iter iter = values.getIter(docId);
|
final LongValues.Iter iter = values.getIter(docId);
|
||||||
list.offset = 0;
|
list.offset = 0;
|
||||||
list.length = 0;
|
list.length = 0;
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
list.grow(list.length+1);
|
list.grow(list.length + 1);
|
||||||
list.values[list.length++] = iter.next();
|
list.values[list.length++] = iter.next();
|
||||||
}
|
}
|
||||||
listLoaded = true;
|
listLoaded = true;
|
||||||
|
@ -170,12 +166,13 @@ public abstract class ScriptDocValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static class NumericDouble extends ScriptDocValues {
|
|
||||||
|
public static class Doubles extends ScriptDocValues {
|
||||||
|
|
||||||
private final DoubleValues values;
|
private final DoubleValues values;
|
||||||
private final SlicedDoubleList list;
|
private final SlicedDoubleList list;
|
||||||
|
|
||||||
public NumericDouble(DoubleValues values) {
|
public Doubles(DoubleValues values) {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.list = new SlicedDoubleList(values.isMultiValued() ? 10 : 1);
|
this.list = new SlicedDoubleList(values.isMultiValued() ? 10 : 1);
|
||||||
|
|
||||||
|
@ -195,8 +192,8 @@ public abstract class ScriptDocValues {
|
||||||
final DoubleValues.Iter iter = values.getIter(docId);
|
final DoubleValues.Iter iter = values.getIter(docId);
|
||||||
list.offset = 0;
|
list.offset = 0;
|
||||||
list.length = 0;
|
list.length = 0;
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
list.grow(list.length+1);
|
list.grow(list.length + 1);
|
||||||
list.values[list.length++] = iter.next();
|
list.values[list.length++] = iter.next();
|
||||||
}
|
}
|
||||||
listLoaded = true;
|
listLoaded = true;
|
||||||
|
@ -250,7 +247,7 @@ public abstract class ScriptDocValues {
|
||||||
return lats;
|
return lats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double [] getLons() {
|
public double[] getLons() {
|
||||||
List<GeoPoint> points = getValues();
|
List<GeoPoint> points = getValues();
|
||||||
double[] lons = new double[points.size()];
|
double[] lons = new double[points.size()];
|
||||||
for (int i = 0; i < points.size(); i++) {
|
for (int i = 0; i < points.size(); i++) {
|
||||||
|
@ -269,9 +266,9 @@ public abstract class ScriptDocValues {
|
||||||
GeoPointValues.Iter iter = values.getIter(docId);
|
GeoPointValues.Iter iter = values.getIter(docId);
|
||||||
list.offset = 0;
|
list.offset = 0;
|
||||||
list.length = 0;
|
list.length = 0;
|
||||||
while(iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
int index = list.length;
|
int index = list.length;
|
||||||
list.grow(index+1);
|
list.grow(index + 1);
|
||||||
GeoPoint next = iter.next();
|
GeoPoint next = iter.next();
|
||||||
GeoPoint point = list.values[index];
|
GeoPoint point = list.values[index];
|
||||||
if (point == null) {
|
if (point == null) {
|
||||||
|
|
|
@ -27,11 +27,13 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
|
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
|
||||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
||||||
import org.elasticsearch.index.fielddata.plain.ByteArrayAtomicFieldData;
|
import org.elasticsearch.index.fielddata.plain.ByteArrayAtomicFieldData;
|
||||||
import org.elasticsearch.index.fielddata.plain.IntArrayAtomicFieldData;
|
import org.elasticsearch.index.fielddata.plain.IntArrayAtomicFieldData;
|
||||||
import org.elasticsearch.index.fielddata.plain.LongArrayAtomicFieldData;
|
import org.elasticsearch.index.fielddata.plain.LongArrayAtomicFieldData;
|
||||||
import org.elasticsearch.index.fielddata.plain.ShortArrayAtomicFieldData;
|
import org.elasticsearch.index.fielddata.plain.ShortArrayAtomicFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -124,6 +126,19 @@ public class LongFieldDataTests extends NumericFieldDataTests {
|
||||||
assertThat(fieldData.getLongValues().getValue(1), equalTo((long) Integer.MIN_VALUE - 1l));
|
assertThat(fieldData.getLongValues().getValue(1), equalTo((long) Integer.MIN_VALUE - 1l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDateScripts() throws Exception {
|
||||||
|
fillSingleValueAllSet();
|
||||||
|
IndexNumericFieldData indexFieldData = getForField("value");
|
||||||
|
AtomicNumericFieldData fieldData = indexFieldData.load(refreshReader());
|
||||||
|
|
||||||
|
ScriptDocValues.Longs scriptValues = (ScriptDocValues.Longs) fieldData.getScriptValues();
|
||||||
|
scriptValues.setNextDocId(0);
|
||||||
|
assertThat(scriptValues.getValue(), equalTo(2l));
|
||||||
|
assertThat(scriptValues.getDate().getMillis(), equalTo(2l));
|
||||||
|
assertThat(scriptValues.getDate().getZone(), equalTo(DateTimeZone.UTC));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillSingleValueAllSet() throws Exception {
|
protected void fillSingleValueAllSet() throws Exception {
|
||||||
Document d = new Document();
|
Document d = new Document();
|
||||||
|
|
Loading…
Reference in New Issue