cgivre commented on a change in pull request #1635: DRILL-7021: HTTPD Throws
NPE and Doesn't Recognize Timeformat
URL: https://github.com/apache/drill/pull/1635#discussion_r262853359
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/store/httpd/HttpdLogRecord.java
##########
@@ -109,8 +117,36 @@ public void set(final String field, final Long value) {
if (w != null) {
LOG.trace("Parsed field: {}, as long: {}", field, value);
w.writeBigInt(value);
+ } else {
+ LOG.warn("No 'long' writer found for field: {}", field);
}
- else {
+ }
+ }
+
+ /**
+ * This method is referenced and called via reflection. This is added as a
parsing target for the parser. It will get
+ * called when the value of a log field is a timesstamp data type.
+ *
+ * @param field name of field
+ * @param value value of field
+ */
+ @SuppressWarnings("unused")
+ public void setTimestamp(final String field, final String value) {
+ if (value != null) {
+ //Convert the date string into a long
+ SimpleDateFormat dateFormatter = new SimpleDateFormat(this.timeFormat);
+ long ts = 0;
+ try {
+ Date d = dateFormatter.parse(value);
+ ts = d.getTime();
+ } catch (Exception e) {
Review comment:
If the date formatter is unable to parse a date, the timestamp falls back to
zero, which it was previous set, and you get a date of 1 Jan 1970. I included
a comment explaining that.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services