I would like to converter a Parquet TIMESTAMP_MICROS_STRINGIFIER in Java date format. My code below return a wrong date:
private static void writeGroup(BufferedWriter w, Group g, MessageType schema, String csvDelimiter)
throws IOException {
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
for (int j = 0; j < schema.getFieldCount(); j++) {
if (j > 0) {
w.write(csvDelimiter);
}
String valueToString;
try {
if (String.valueOf(g.getType().getType(schema.getFieldName(j)).asPrimitiveType().stringifier()).equals("TIMESTAMP_MICROS_STRINGIFIER")) {
Instant instant = Instant.ofEpochMilli(g.getLong(j, 0));
Date date = Date.from(instant);
valueToString = dt.format(date);
} else {
valueToString = g.getValueToString(j, 0);
}
} catch (RuntimeException e) {
valueToString = "";
}
w.write(valueToString);
}
w.write('\n');
}
Output Date: 53971-26-19 03:26:40
Expected Date: 2022-01-01 00:35:40
TIMESTAMP String Value: 1640997340000000
Schema: optional int64 tpep_pickup_datetime (TIMESTAMP(MICROS,false));
Thanks