--- ImportTsv_orig.java 2014-01-20 14:20:28.000000000 -0500 +++ ImportTsv.java 2014-01-20 09:35:59.928103107 -0500 @@ -57,6 +57,14 @@ import com.google.common.base.Splitter; import com.google.common.collect.Lists; +//2013-08-19T04:39:07 +import java.text.DateFormat; +import java.util.*; +import java.text.SimpleDateFormat; +import java.text.ParseException; + + + /** * Tool to import data from a TSV file. * @@ -220,10 +228,12 @@ getColumnOffset(timestampKeyColumnIndex), getColumnLength(timestampKeyColumnIndex)); try { - return Long.parseLong(timeStampStr); + return Long.parseLong(timeStampStr); } catch (NumberFormatException nfe) { + // Try this record with string to date in mseconds long + return extractTimestampInput(timeStampStr); // treat this record as bad record - throw new BadTsvLineException("Invalid timestamp " + timeStampStr); + //throw new BadTsvLineException("Invalid timestamp " + timeStampStr); } } @@ -243,6 +253,22 @@ return lineBytes; } } + public static long extractTimestampInput(String strDate) throws BadTsvLineException{ + final List dateFormats = Arrays.asList("yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss"); + + for(String format: dateFormats){ + SimpleDateFormat sdf = new SimpleDateFormat(format); + try{ + Date d= sdf.parse(strDate); + long msecs = d.getTime(); + return msecs; + } catch (ParseException e) { + //intentionally empty + } + } + // If we come here we have a problem with converting timestamps for this row. + throw new BadTsvLineException("Invalid timestamp " + strDate); + } public static class BadTsvLineException extends Exception { public BadTsvLineException(String err) {