Initial import into git.
[galago.git] / java / pig-galago / src / com / yahoo / pig / data / TimestampedTuple.java
blob1fe5299dedca42076a80fbb8cac300cc0fb985e8
1 /*
2 * Copyright (c) 2007 Yahoo! Inc. All rights reserved.
3 * See accompanying LICENSE file.
4 */
5 package com.yahoo.pig.data;
7 import java.text.ParseException;
8 import java.text.SimpleDateFormat;
9 import java.util.ArrayList;
11 public class TimestampedTuple extends Tuple {
13 public double timestamp = 0; // timestamp of this tuple
14 public boolean isHeartbeat = false; // true iff this is a heartbeat (i.e. purpose is just to convey new timestamp; carries no data)
16 public TimestampedTuple(int numFields) {
17 super(numFields);
20 public TimestampedTuple(String textLine, String delimiter, int timestampColumn,
21 SimpleDateFormat dateFormat){
22 if (delimiter == null) {
23 delimiter = defaultDelimiter;
25 String[] splitString = textLine.split(delimiter, -1);
26 fields = new ArrayList<Datum>(splitString.length-1);
27 for (int i = 0; i < splitString.length; i++) {
28 if (i==timestampColumn){
29 try{
30 timestamp = dateFormat.parse(splitString[i]).getTime()/1000.0;
31 }catch(ParseException e){
32 System.err.println("Could not parse timestamp " + splitString[i]);
34 }else{
35 fields.add(new DataAtom(splitString[i]));