use of org.joda.time.format.DateTimeFormatter in project druid by druid-io.
the class GranularityPathSpec method addInputPaths.
@Override
public Job addInputPaths(HadoopDruidIndexerConfig config, Job job) throws IOException {
final Set<Interval> intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd());
for (Interval inputInterval : config.getInputIntervals()) {
for (Interval interval : dataGranularity.getIterable(inputInterval)) {
intervals.add(trim(inputInterval, interval));
}
}
Path betaInput = new Path(inputPath);
FileSystem fs = betaInput.getFileSystem(job.getConfiguration());
Set<String> paths = Sets.newTreeSet();
Pattern fileMatcher = Pattern.compile(filePattern);
DateTimeFormatter customFormatter = null;
if (pathFormat != null) {
customFormatter = DateTimeFormat.forPattern(pathFormat);
}
for (Interval interval : intervals) {
DateTime t = interval.getStart();
String intervalPath = null;
if (customFormatter != null) {
intervalPath = customFormatter.print(t);
} else {
intervalPath = dataGranularity.toPath(t);
}
Path granularPath = new Path(betaInput, intervalPath);
log.info("Checking path[%s]", granularPath);
for (FileStatus status : FSSpideringIterator.spiderIterable(fs, granularPath)) {
final Path filePath = status.getPath();
if (fileMatcher.matcher(filePath.toString()).matches()) {
paths.add(filePath.toString());
}
}
}
log.info("Appending path %s", paths);
StaticPathSpec.addToMultipleInputs(config, job, paths, inputFormat);
return job;
}
use of org.joda.time.format.DateTimeFormatter in project elasticsearch by elastic.
the class BaseXContentTestCase method testReadableInstant.
public void testReadableInstant() throws Exception {
assertResult("{'instant':null}", () -> builder().startObject().field("instant", (ReadableInstant) null).endObject());
assertResult("{'instant':null}", () -> builder().startObject().field("instant").value((ReadableInstant) null).endObject());
final DateTime t1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
String expected = "{'t1':'2016-01-01T00:00:00.000Z'}";
assertResult(expected, () -> builder().startObject().field("t1", t1).endObject());
assertResult(expected, () -> builder().startObject().field("t1").value(t1).endObject());
final DateTime t2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC);
expected = "{'t2':'2016-12-25T07:59:42.213Z'}";
assertResult(expected, () -> builder().startObject().field("t2", t2).endObject());
assertResult(expected, () -> builder().startObject().field("t2").value(t2).endObject());
final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(), ISODateTimeFormat.dateTimeNoMillis());
final DateTime t3 = DateTime.now();
expected = "{'t3':'" + formatter.print(t3) + "'}";
assertResult(expected, () -> builder().startObject().field("t3", t3, formatter).endObject());
assertResult(expected, () -> builder().startObject().field("t3").value(t3, formatter).endObject());
final DateTime t4 = new DateTime(randomDateTimeZone());
expected = "{'t4':'" + formatter.print(t4) + "'}";
assertResult(expected, () -> builder().startObject().field("t4", t4, formatter).endObject());
assertResult(expected, () -> builder().startObject().field("t4").value(t4, formatter).endObject());
// 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
long date = Math.abs(randomLong() % (2 * (long) 10e11));
final DateTime t5 = new DateTime(date, randomDateTimeZone());
expected = "{'t5':'" + XContentBuilder.DEFAULT_DATE_PRINTER.print(t5) + "'}";
assertResult(expected, () -> builder().startObject().field("t5", t5).endObject());
assertResult(expected, () -> builder().startObject().field("t5").value(t5).endObject());
expected = "{'t5':'" + formatter.print(t5) + "'}";
assertResult(expected, () -> builder().startObject().field("t5", t5, formatter).endObject());
assertResult(expected, () -> builder().startObject().field("t5").value(t5, formatter).endObject());
// 2016-01-01T00:00:00.000Z
Instant i1 = new Instant(1451606400000L);
expected = "{'i1':'2016-01-01T00:00:00.000Z'}";
assertResult(expected, () -> builder().startObject().field("i1", i1).endObject());
assertResult(expected, () -> builder().startObject().field("i1").value(i1).endObject());
// 2016-12-25T07:59:42.213Z
Instant i2 = new Instant(1482652782213L);
expected = "{'i2':'" + formatter.print(i2) + "'}";
assertResult(expected, () -> builder().startObject().field("i2", i2, formatter).endObject());
assertResult(expected, () -> builder().startObject().field("i2").value(i2, formatter).endObject());
expectNonNullFormatterException(() -> builder().startObject().field("t3", t3, null).endObject());
expectNonNullFormatterException(() -> builder().startObject().field("t3").value(t3, null).endObject());
}
use of org.joda.time.format.DateTimeFormatter in project elasticsearch by elastic.
the class BaseXContentTestCase method testObject.
public void testObject() throws Exception {
Map<String, Object> object = new HashMap<>();
object.put("{'object':false}", Boolean.FALSE);
object.put("{'object':13}", (byte) 13);
object.put("{'object':5.0}", 5.0d);
object.put("{'object':8.0}", 8.0f);
object.put("{'object':{'lat':45.759429931640625,'lon':4.8394775390625}}", GeoPoint.fromGeohash("u05kq4k"));
object.put("{'object':3}", 3);
object.put("{'object':2}", 2L);
object.put("{'object':1}", (short) 1);
object.put("{'object':'string'}", "string");
object.put("{'object':'a'}", new Text("a"));
object.put("{'object':'b'}", new Text(new BytesArray("b")));
object.put("{'object':null}", null);
object.put("{'object':'OPEN'}", IndexMetaData.State.OPEN);
object.put("{'object':'NM'}", DistanceUnit.NAUTICALMILES);
object.put("{'object':{'f1':'v1'}}", singletonMap("f1", "v1"));
object.put("{'object':{'f1':{'f2':'v2'}}}", singletonMap("f1", singletonMap("f2", "v2")));
object.put("{'object':[1,2,3]}", Arrays.asList(1, 2, 3));
final String path = Constants.WINDOWS ? "{'object':'a\\\\b\\\\c'}" : "{'object':'a/b/c'}";
object.put(path, PathUtils.get("a", "b", "c"));
final DateTimeFormatter formatter = XContentBuilder.DEFAULT_DATE_PRINTER;
final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
object.put("{'object':'" + formatter.print(d1.getTime()) + "'}", d1);
final DateTime d2 = DateTime.now();
object.put("{'object':'" + formatter.print(d2) + "'}", d2);
final Calendar c1 = new DateTime(2010, 1, 1, 0, 0, DateTimeZone.UTC).toCalendar(Locale.ROOT);
object.put("{'object':'2010-01-01T00:00:00.000Z'}", c1);
final ToXContent x1 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", 2).array("f3", 3, 4, 5).endObject();
final ToXContent x2 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", x1).endObject();
object.put("{'object':{'f1':'v1','f2':{'f1':'v1','f2':2,'f3':[3,4,5]}}}", x2);
for (Map.Entry<String, Object> o : object.entrySet()) {
final String expected = o.getKey();
assertResult(expected, () -> builder().humanReadable(true).startObject().field("object", o.getValue()).endObject());
assertResult(expected, () -> builder().humanReadable(true).startObject().field("object").value(o.getValue()).endObject());
}
assertResult("{'objects':[null,null,null]}", () -> builder().startObject().array("objects", null, null, null).endObject());
}
use of org.joda.time.format.DateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method assertDateFormatParsingThrowingException.
private void assertDateFormatParsingThrowingException(String pattern, String invalidDate) {
try {
FormatDateTimeFormatter formatter = Joda.forPattern(pattern);
DateTimeFormatter parser = formatter.parser();
parser.parseMillis(invalidDate);
fail(String.format(Locale.ROOT, "Expected parsing exception for pattern [%s] with date [%s], but did not happen", pattern, invalidDate));
} catch (IllegalArgumentException e) {
}
}
use of org.joda.time.format.DateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method testIsoVsCustom.
public void testIsoVsCustom() {
DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
long millis = formatter.parseMillis("1970-01-01T00:00:00");
assertThat(millis, equalTo(0L));
formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZone(DateTimeZone.UTC);
millis = formatter.parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
FormatDateTimeFormatter formatter2 = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
millis = formatter2.parser().parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
}
Aggregations