use of org.joda.time.ReadableDateTime in project elasticsearch by elastic.
the class ScriptDocValuesDatesTests method test.
public void test() {
long[][] values = new long[between(3, 10)][];
ReadableDateTime[][] expectedDates = new ReadableDateTime[values.length][];
for (int d = 0; d < values.length; d++) {
values[d] = new long[randomBoolean() ? randomBoolean() ? 0 : 1 : between(2, 100)];
expectedDates[d] = new ReadableDateTime[values[d].length];
for (int i = 0; i < values[d].length; i++) {
expectedDates[d][i] = new DateTime(randomNonNegativeLong(), DateTimeZone.UTC);
values[d][i] = expectedDates[d][i].getMillis();
}
}
Dates dates = wrap(values);
for (int round = 0; round < 10; round++) {
int d = between(0, values.length - 1);
dates.setNextDocId(d);
assertEquals(expectedDates[d].length > 0 ? expectedDates[d][0] : new DateTime(0, DateTimeZone.UTC), dates.getValue());
assertEquals(values[d].length, dates.size());
for (int i = 0; i < values[d].length; i++) {
assertEquals(expectedDates[d][i], dates.get(i));
}
Exception e = expectThrows(UnsupportedOperationException.class, () -> dates.add(new DateTime()));
assertEquals("doc values are unmodifiable", e.getMessage());
}
}
use of org.joda.time.ReadableDateTime in project joda-time by JodaOrg.
the class TestConverterManager method testGetPartialConverterOKMultipleMatches.
public void testGetPartialConverterOKMultipleMatches() {
PartialConverter c = new PartialConverter() {
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
return null;
}
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
return null;
}
public Chronology getChronology(Object object, DateTimeZone zone) {
return null;
}
public Chronology getChronology(Object object, Chronology chrono) {
return null;
}
public Class getSupportedType() {
return ReadableDateTime.class;
}
};
try {
ConverterManager.getInstance().addPartialConverter(c);
PartialConverter ok = ConverterManager.getInstance().getPartialConverter(new DateTime());
// ReadableDateTime and ReadablePartial both match, but RI discarded as less specific
assertEquals(ReadableDateTime.class, ok.getSupportedType());
} finally {
ConverterManager.getInstance().removePartialConverter(c);
}
assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
use of org.joda.time.ReadableDateTime in project elasticsearch by elastic.
the class ScriptDocValuesLongsTests method testDates.
public void testDates() {
long[][] values = new long[between(3, 10)][];
ReadableDateTime[][] dates = new ReadableDateTime[values.length][];
for (int d = 0; d < values.length; d++) {
values[d] = new long[randomBoolean() ? randomBoolean() ? 0 : 1 : between(2, 100)];
dates[d] = new ReadableDateTime[values[d].length];
for (int i = 0; i < values[d].length; i++) {
dates[d][i] = new DateTime(randomNonNegativeLong(), DateTimeZone.UTC);
values[d][i] = dates[d][i].getMillis();
}
}
Longs longs = wrap(values);
for (int round = 0; round < 10; round++) {
int d = between(0, values.length - 1);
longs.setNextDocId(d);
assertEquals(dates[d].length > 0 ? dates[d][0] : new DateTime(0, DateTimeZone.UTC), longs.getDate());
assertEquals(values[d].length, longs.getDates().size());
for (int i = 0; i < values[d].length; i++) {
assertEquals(dates[d][i], longs.getDates().get(i));
}
Exception e = expectThrows(UnsupportedOperationException.class, () -> longs.getDates().add(new DateTime()));
assertEquals("doc values are unmodifiable", e.getMessage());
}
assertWarnings("getDate on numeric fields is deprecated. Use a date field to get dates.", "getDates on numeric fields is deprecated. Use a date field to get dates.");
}
use of org.joda.time.ReadableDateTime in project elasticsearch by elastic.
the class SearchFieldsIT method testFieldsPulledFromFieldData.
public void testFieldsPulledFromFieldData() throws Exception {
createIndex("test");
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", false).endObject().startObject("properties").startObject("text_field").field("type", "text").field("fielddata", true).endObject().startObject("keyword_field").field("type", "keyword").endObject().startObject("byte_field").field("type", "byte").endObject().startObject("short_field").field("type", "short").endObject().startObject("integer_field").field("type", "integer").endObject().startObject("long_field").field("type", "long").endObject().startObject("float_field").field("type", "float").endObject().startObject("double_field").field("type", "double").endObject().startObject("date_field").field("type", "date").endObject().startObject("boolean_field").field("type", "boolean").endObject().startObject("binary_field").field("type", "binary").endObject().startObject("ip_field").field("type", "ip").endObject().endObject().endObject().endObject().string();
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).execute().actionGet();
ReadableDateTime date = new DateTime(2012, 3, 22, 0, 0, DateTimeZone.UTC);
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("text_field", "foo").field("keyword_field", "foo").field("byte_field", (byte) 1).field("short_field", (short) 2).field("integer_field", 3).field("long_field", 4L).field("float_field", 5.0f).field("double_field", 6.0d).field("date_field", Joda.forPattern("dateOptionalTime").printer().print(date)).field("boolean_field", true).field("ip_field", "::1").endObject()).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
SearchRequestBuilder builder = client().prepareSearch().setQuery(matchAllQuery()).addDocValueField("text_field").addDocValueField("keyword_field").addDocValueField("byte_field").addDocValueField("short_field").addDocValueField("integer_field").addDocValueField("long_field").addDocValueField("float_field").addDocValueField("double_field").addDocValueField("date_field").addDocValueField("boolean_field").addDocValueField("ip_field");
SearchResponse searchResponse = builder.execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
Set<String> fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet());
assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field", "float_field", "double_field", "date_field", "boolean_field", "text_field", "keyword_field", "ip_field")));
assertThat(searchResponse.getHits().getAt(0).getFields().get("byte_field").getValue().toString(), equalTo("1"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("short_field").getValue().toString(), equalTo("2"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("integer_field").getValue(), equalTo((Object) 3L));
assertThat(searchResponse.getHits().getAt(0).getFields().get("long_field").getValue(), equalTo((Object) 4L));
assertThat(searchResponse.getHits().getAt(0).getFields().get("float_field").getValue(), equalTo((Object) 5.0));
assertThat(searchResponse.getHits().getAt(0).getFields().get("double_field").getValue(), equalTo((Object) 6.0d));
assertThat(searchResponse.getHits().getAt(0).getFields().get("date_field").getValue(), equalTo(date));
assertThat(searchResponse.getHits().getAt(0).getFields().get("boolean_field").getValue(), equalTo((Object) true));
assertThat(searchResponse.getHits().getAt(0).getFields().get("text_field").getValue(), equalTo("foo"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("keyword_field").getValue(), equalTo("foo"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("ip_field").getValue(), equalTo("::1"));
}
use of org.joda.time.ReadableDateTime in project joda-time by JodaOrg.
the class TestConverterManager method testGetInstantConverterOKMultipleMatches.
public void testGetInstantConverterOKMultipleMatches() {
InstantConverter c = new InstantConverter() {
public long getInstantMillis(Object object, Chronology chrono) {
return 0;
}
public Chronology getChronology(Object object, DateTimeZone zone) {
return null;
}
public Chronology getChronology(Object object, Chronology chrono) {
return null;
}
public Class getSupportedType() {
return ReadableDateTime.class;
}
};
try {
ConverterManager.getInstance().addInstantConverter(c);
InstantConverter ok = ConverterManager.getInstance().getInstantConverter(new DateTime());
// ReadableDateTime and ReadableInstant both match, but RI discarded as less specific
assertEquals(ReadableDateTime.class, ok.getSupportedType());
} finally {
ConverterManager.getInstance().removeInstantConverter(c);
}
assertEquals(6, ConverterManager.getInstance().getInstantConverters().length);
}
Aggregations