Skip to content

Commit 656502f

Browse files
committed
Rebased and update after PR #454 merge
1 parent 9d52f37 commit 656502f

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/main/java/com/teragrep/pth10/ast/DefaultTimeFormat.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import java.text.ParseException;
4949
import java.text.SimpleDateFormat;
50+
import java.util.Arrays;
5051
import java.util.Date;
5152

5253
/**
@@ -97,7 +98,10 @@ public Date parse(String time) {
9798
catch (ParseException ignored) {
9899
}
99100
}
100-
throw new RuntimeException("Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats <>)");
101+
throw new RuntimeException(
102+
"Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats: "
103+
+ Arrays.toString(formats) + ")"
104+
);
101105
}
102106

103107
private Date parseDate(String time, String timeFormat) throws ParseException {

src/main/java/com/teragrep/pth10/ast/time/InstantTimestamp.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
public final class InstantTimestamp implements DPLTimestamp {
6161

62-
private static final Logger LOGGER = LoggerFactory.getLogger(EpochTimestamp.class);
62+
private static final Logger LOGGER = LoggerFactory.getLogger(InstantTimestamp.class);
6363
private final String value;
6464
private final String timeformat;
6565

@@ -76,15 +76,19 @@ public Instant instant() {
7676
}
7777
catch (NumberFormatException ne) {
7878
LOGGER.debug("Could not parse relative timestamp, trying default formats");
79-
rv = instantFromString(value, timeformat);
79+
rv = instantFromString(value, timeformat, ne);
8080
}
8181

8282
return rv;
8383
}
8484

8585
// Uses defaultTimeFormat if timeformat is null and DPLTimeFormat if timeformat isn't null (which means that the
8686
// timeformat= option was used).
87-
private Instant instantFromString(final String value, final String timeFormatString, final NumberFormatException cause) {
87+
private Instant instantFromString(
88+
final String value,
89+
final String timeFormatString,
90+
final NumberFormatException cause
91+
) {
8892
final String unquotedValue = new UnquotedText(new TextString(value)).read(); // erase the possible outer quotes
8993
final Instant timevalue;
9094
if (timeFormatString == null || timeFormatString.isEmpty()) {

src/test/java/com/teragrep/pth10/DefaultTimeFormatTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ void invalidTimeformat() {
123123
.assertThrows(RuntimeException.class, () -> new DefaultTimeFormat().getEpoch(time));
124124

125125
Assertions
126-
.assertEquals("TimeQualifier conversion error: <12/34/2020:10:25:40> can't be parsed.", rte.getMessage());
126+
.assertEquals(
127+
"Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats: [MM/dd/yyyy:HH:mm:ss, yyyy-MM-dd'T'HH:mm:ss.SSSXXX, yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ssXXX, yyyy-MM-dd'T'HH:mm:ss])",
128+
rte.getMessage()
129+
);
127130
}
128131
}

src/test/java/com/teragrep/pth10/EarliestLatestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public void defaultFormatInvalidInputTest() { // MM/dd/yyyy:HH:mm:ss 2013-07-15
359359
});
360360
Assertions
361361
.assertEquals(
362-
"Error parsing <31/31/2014:00:00:00>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats <MM/dd/yyyy:HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ssXXX>). Unknown relative time modifier string [31/31/2014:00:00:00].",
362+
"Error parsing <31/31/2014:00:00:00>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats: [MM/dd/yyyy:HH:mm:ss, yyyy-MM-dd'T'HH:mm:ss.SSSXXX, yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ssXXX, yyyy-MM-dd'T'HH:mm:ss]). Unknown relative time modifier string [31/31/2014:00:00:00].",
363363
sqe.getMessage()
364364
);
365365
}

src/test/java/com/teragrep/pth10/relativeTimeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public void parseTimestampLatestRelativeTestWithPlus() {
336336
)
337337
public void parseTimestampLatestRelativeTestWithoutSign() {
338338
String q = "index=cinnamon latest=3h ";
339-
String expected = "Error parsing <3h>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats <MM/dd/yyyy:HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ssXXX>). Unknown relative time modifier string [3h].";
339+
String expected = "Error parsing <3h>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats: [MM/dd/yyyy:HH:mm:ss, yyyy-MM-dd'T'HH:mm:ss.SSSXXX, yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ssXXX, yyyy-MM-dd'T'HH:mm:ss]). Unknown relative time modifier string [3h].";
340340

341341
RuntimeException exception = this.streamingTestUtil
342342
.performThrowingDPLTest(RuntimeException.class, q, this.testFile, res -> {
@@ -437,7 +437,7 @@ public void parseTimestampEarliestRelativeSnapToDayLatestNow() {
437437
public void parseTimestampRelativeInvalidSnapToTimeUnitTest() {
438438
// pth10 ticket #66 query: 'index=... sourcetype=... earliest=@-5h latest=@-3h'
439439
String query = "index=cinnamon earliest=\"@-5h\" latest=\"@-3h\"";
440-
String expected = "Error parsing <@-5h>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats <MM/dd/yyyy:HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ss>, <yyyy-MM-dd'T'HH:mm:ssXXX>). Unknown relative time modifier string [@-5h].";
440+
String expected = "Error parsing <@-5h>. Check that the timestamp or the relative time value is in the correct format (Supported timestamp formats: [MM/dd/yyyy:HH:mm:ss, yyyy-MM-dd'T'HH:mm:ss.SSSXXX, yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ssXXX, yyyy-MM-dd'T'HH:mm:ss]). Unknown relative time modifier string [@-5h].";
441441

442442
RuntimeException exception = this.streamingTestUtil
443443
.performThrowingDPLTest(RuntimeException.class, query, this.testFile, res -> {

0 commit comments

Comments
 (0)