2 * Copyright (c) 2007 Yahoo! Inc. All rights reserved.
3 * See accompanying LICENSE file.
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
) {
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
){
30 timestamp
= dateFormat
.parse(splitString
[i
]).getTime()/1000.0;
31 }catch(ParseException e
){
32 System
.err
.println("Could not parse timestamp " + splitString
[i
]);
35 fields
.add(new DataAtom(splitString
[i
]));