pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From the...@apache.org
Subject svn commit: r1376800 [5/6] - in /pig/trunk: ./ .eclipse.templates/ conf/ contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/ contrib/zebra/src/java/org/apache/hadoop/zebra/pig/ contrib/zebra/src/java/org/apache/hadoop/zebra/pig/compa...
Date Fri, 24 Aug 2012 00:18:09 GMT
Modified: pig/trunk/test/org/apache/pig/data/TestSchemaTuple.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/data/TestSchemaTuple.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/data/TestSchemaTuple.java (original)
+++ pig/trunk/test/org/apache/pig/data/TestSchemaTuple.java Fri Aug 24 00:18:05 2012
@@ -41,6 +41,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.InputSplit;
@@ -106,9 +108,9 @@ public class TestSchemaTuple {
         udfSchema = Utils.getSchemaFromString("((a:int,b:int),(a:int,b:int),(a:int,b:int)),((a:int,b:int),(a:int,b:int),(a:int,b:int))");
         SchemaTupleFrontend.registerToGenerateIfPossible(udfSchema, isAppendable, context);
 
-        udfSchema = Utils.getSchemaFromString("a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double,"
-                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double,"
-                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double))");
+        udfSchema = Utils.getSchemaFromString("a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt:datetime"
+                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt:datetime"
+                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt:datetime))");
         SchemaTupleFrontend.registerToGenerateIfPossible(udfSchema, isAppendable, context);
 
         udfSchema = Utils.getSchemaFromString("boolean, boolean, boolean, boolean, boolean, boolean"
@@ -126,45 +128,45 @@ public class TestSchemaTuple {
                 + "boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean");
         SchemaTupleFrontend.registerToGenerateIfPossible(udfSchema, isAppendable, context);
 
-        udfSchema = Utils.getSchemaFromString("int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))");
+        udfSchema = Utils.getSchemaFromString("int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))");
         SchemaTupleFrontend.registerToGenerateIfPossible(udfSchema, isAppendable, context);
 
         isAppendable = true;
@@ -223,9 +225,9 @@ public class TestSchemaTuple {
         tf = SchemaTupleFactory.getInstance(udfSchema, isAppendable, context);
         putThroughPaces(tf, udfSchema, isAppendable);
 
-        udfSchema = Utils.getSchemaFromString("a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double,"
-                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double,"
-                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double))");
+        udfSchema = Utils.getSchemaFromString("a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt: datetime"
+                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt: datetime,"
+                +"(a:int, b:long, c:chararray, d:boolean, e:bytearray, f:float, g:double, dt: datetime))");
         tf = SchemaTupleFactory.getInstance(udfSchema, isAppendable, context);
         putThroughPaces(tf, udfSchema, isAppendable);
 
@@ -245,45 +247,45 @@ public class TestSchemaTuple {
         tf = SchemaTupleFactory.getInstance(udfSchema, isAppendable, context);
         putThroughPaces(tf, udfSchema, isAppendable);
 
-        udfSchema = Utils.getSchemaFromString("int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))"
-                +"int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double,"
-                +"(int, long, chararray, boolean, bytearray, float, double))");
+        udfSchema = Utils.getSchemaFromString("int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))"
+                +"int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime,"
+                +"(int, long, chararray, boolean, bytearray, float, double, datetime))");
         tf = SchemaTupleFactory.getInstance(udfSchema, isAppendable, context);
         putThroughPaces(tf, udfSchema, isAppendable);
 
@@ -399,6 +401,7 @@ public class TestSchemaTuple {
         case DataType.LONG: return r.nextLong();
         case DataType.FLOAT: return r.nextFloat();
         case DataType.DOUBLE: return r.nextDouble();
+        case DataType.DATETIME: return new DateTime(r.nextLong());
         case DataType.BAG:
             DataBag db = BagFactory.getInstance().newDefaultBag();
             int sz = r.nextInt(100);
@@ -450,6 +453,7 @@ public class TestSchemaTuple {
                 case DataType.LONG: st.getLong(i); break;
                 case DataType.FLOAT: st.getFloat(i); break;
                 case DataType.DOUBLE: st.getDouble(i); break;
+                case DataType.DATETIME: st.getDateTime(i); break;
                 case DataType.TUPLE: st.getTuple(i); break;
                 case DataType.BAG: st.getDataBag(i); break;
                 case DataType.MAP: st.getMap(i); break;

Modified: pig/trunk/test/org/apache/pig/test/TestAdd.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestAdd.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestAdd.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestAdd.java Fri Aug 24 00:18:05 2012
@@ -23,6 +23,8 @@ import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -54,7 +56,7 @@ public class TestAdd extends TestCase{
     public void testOperator() throws ExecException{
         //int TRIALS = 10;
         byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY, 
-                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.MAP, DataType.TUPLE};
+                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.DATETIME, DataType.MAP, DataType.TUPLE};
         //Map<Byte,String> map = GenRandomData.genTypeToNameMap();
         System.out.println("Testing Add operator");
         for(byte type : types) {
@@ -230,6 +232,25 @@ public class TestAdd extends TestCase{
                 assertEquals(null, (Long)resl.result);
                 break;
             }
+            case DataType.DATETIME:
+                DateTime inpdt1 = new DateTime(r.nextLong());
+                DateTime inpdt2 = new DateTime(r.nextLong());
+                lt.setValue(inpdt1);
+                rt.setValue(inpdt2);
+                Result resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                
+                // test with null in lhs
+                lt.setValue(null);
+                rt.setValue(inpdt2);
+                resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                // test with null in rhs
+                lt.setValue(inpdt1);
+                rt.setValue(null);
+                resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                break;
             case DataType.MAP: {
                 Map<String,Object> inpm1 = GenRandomData.genRandMap(r, 10);
                 Map<String,Object> inpm2 = GenRandomData.genRandMap(r, 10);

Modified: pig/trunk/test/org/apache/pig/test/TestBuiltin.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestBuiltin.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBuiltin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBuiltin.java Fri Aug 24 00:18:05 2012
@@ -32,7 +32,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Random;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -45,14 +44,27 @@ import org.apache.pig.PigServer;
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;
 import org.apache.pig.builtin.ARITY;
+import org.apache.pig.builtin.AddDuration;
 import org.apache.pig.builtin.BagSize;
 import org.apache.pig.builtin.CONCAT;
 import org.apache.pig.builtin.COR;
 import org.apache.pig.builtin.COUNT;
 import org.apache.pig.builtin.COUNT_STAR;
 import org.apache.pig.builtin.COV;
+import org.apache.pig.builtin.CurrentTime;
 import org.apache.pig.builtin.DIFF;
+import org.apache.pig.builtin.DaysBetween;
 import org.apache.pig.builtin.Distinct;
+import org.apache.pig.builtin.GetDay;
+import org.apache.pig.builtin.GetHour;
+import org.apache.pig.builtin.GetMilliSecond;
+import org.apache.pig.builtin.GetMinute;
+import org.apache.pig.builtin.GetMonth;
+import org.apache.pig.builtin.GetSecond;
+import org.apache.pig.builtin.GetWeek;
+import org.apache.pig.builtin.GetWeekYear;
+import org.apache.pig.builtin.GetYear;
+import org.apache.pig.builtin.HoursBetween;
 import org.apache.pig.builtin.INDEXOF;
 import org.apache.pig.builtin.INVERSEMAP;
 import org.apache.pig.builtin.KEYSET;
@@ -60,6 +72,9 @@ import org.apache.pig.builtin.LAST_INDEX
 import org.apache.pig.builtin.LCFIRST;
 import org.apache.pig.builtin.LOWER;
 import org.apache.pig.builtin.MapSize;
+import org.apache.pig.builtin.MilliSecondsBetween;
+import org.apache.pig.builtin.MinutesBetween;
+import org.apache.pig.builtin.MonthsBetween;
 import org.apache.pig.builtin.PigStorage;
 import org.apache.pig.builtin.REGEX_EXTRACT;
 import org.apache.pig.builtin.REGEX_EXTRACT_ALL;
@@ -67,8 +82,10 @@ import org.apache.pig.builtin.REPLACE;
 import org.apache.pig.builtin.SIZE;
 import org.apache.pig.builtin.STRSPLIT;
 import org.apache.pig.builtin.SUBSTRING;
+import org.apache.pig.builtin.SecondsBetween;
 import org.apache.pig.builtin.StringConcat;
 import org.apache.pig.builtin.StringSize;
+import org.apache.pig.builtin.SubtractDuration;
 import org.apache.pig.builtin.TOBAG;
 import org.apache.pig.builtin.TOKENIZE;
 import org.apache.pig.builtin.TOMAP;
@@ -76,11 +93,20 @@ import org.apache.pig.builtin.TOP;
 import org.apache.pig.builtin.TOTUPLE;
 import org.apache.pig.builtin.TRIM;
 import org.apache.pig.builtin.TextLoader;
+import org.apache.pig.builtin.ToDate;
+import org.apache.pig.builtin.ToDate2ARGS;
+import org.apache.pig.builtin.ToDate3ARGS;
+import org.apache.pig.builtin.ToDateISO;
+import org.apache.pig.builtin.ToMilliSeconds;
+import org.apache.pig.builtin.ToString;
+import org.apache.pig.builtin.ToUnixTime;
 import org.apache.pig.builtin.TupleSize;
 import org.apache.pig.builtin.UCFIRST;
 import org.apache.pig.builtin.UPPER;
 import org.apache.pig.builtin.VALUELIST;
 import org.apache.pig.builtin.VALUESET;
+import org.apache.pig.builtin.WeeksBetween;
+import org.apache.pig.builtin.YearsBetween;
 import org.apache.pig.data.BagFactory;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -94,6 +120,8 @@ import org.apache.pig.impl.logicalLayer.
 import org.apache.pig.impl.logicalLayer.schema.Schema;
 import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
 import org.apache.pig.impl.logicalLayer.validators.TypeCheckerException;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
@@ -290,6 +318,9 @@ public class TestBuiltin {
         }catch(ExecException e) {
             e.printStackTrace();
         }
+
+
+        DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.UTC.getOffset(null)));
     }
 
     @AfterClass
@@ -315,6 +346,117 @@ public class TestBuiltin {
         }
     }
 
+    @Test
+    public void testAddSubtractDuration() throws Exception {
+        AddDuration func1 = new AddDuration();
+        SubtractDuration func2 = new SubtractDuration();
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, new DateTime("2009-01-07T01:07:01.000Z"));
+        t1.set(1, "PT1S");
+        Tuple t2 = TupleFactory.getInstance().newTuple(2);
+        t2.set(0, new DateTime("2008-02-06T02:06:02.000Z"));
+        t2.set(1, "PT1M");
+        Tuple t3 = TupleFactory.getInstance().newTuple(2);
+        t3.set(0, new DateTime("2007-03-05T03:05:03.000Z"));
+        t3.set(1, "P1D");
+        
+        assertEquals(func1.exec(t1), new DateTime("2009-01-07T01:07:02.000Z"));
+        assertEquals(func1.exec(t2), new DateTime("2008-02-06T02:07:02.000Z"));
+        assertEquals(func1.exec(t3), new DateTime("2007-03-06T03:05:03.000Z"));
+        assertEquals(func2.exec(t1), new DateTime("2009-01-07T01:07:00.000Z"));
+        assertEquals(func2.exec(t2), new DateTime("2008-02-06T02:05:02.000Z"));
+        assertEquals(func2.exec(t3), new DateTime("2007-03-04T03:05:03.000Z"));
+    }
+
+    @Test
+    public void testConversionBetweenDateTimeAndString() throws Exception {
+        ToDate func1 = new ToDate();
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, 1231290421000L);
+        DateTime dt1 = func1.exec(t1);
+        assertEquals(dt1, new DateTime("2009-01-07T01:07:01.000Z"));
+
+        ToDateISO func2 = new ToDateISO();
+        Tuple t2 = TupleFactory.getInstance().newTuple(1);
+        t2.set(0, "2009-01-07T01:07:01.000Z");
+        DateTime dt2 = func2.exec(t2);
+        assertEquals(dt2, new DateTime("2009-01-07T01:07:01.000Z"));
+
+        Tuple t3 = TupleFactory.getInstance().newTuple(1);
+        t3.set(0, "2009-01-07T01:07:01.000+08:00");
+        DateTime dt3 = func2.exec(t3);
+        assertEquals(dt3, new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00")));
+
+        ToDate2ARGS func3 = new ToDate2ARGS();        
+        Tuple t4 = TupleFactory.getInstance().newTuple(2);
+        t4.set(0, "2009.01.07 AD at 01:07:01");
+        t4.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
+        DateTime dt4 = func3.exec(t4);
+        assertEquals(dt4, new DateTime("2009-01-07T01:07:01.000Z"));
+
+        Tuple t5 = TupleFactory.getInstance().newTuple(2);
+        t5.set(0, "2009.01.07 AD at 01:07:01 +0800");
+        t5.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
+        DateTime dt5 = func3.exec(t5);
+        assertEquals(dt5, new DateTime("2009-01-07T01:07:01.000+08:00"));
+        
+        ToDate3ARGS func4 = new ToDate3ARGS();        
+        Tuple t6 = TupleFactory.getInstance().newTuple(3);
+        t6.set(0, "2009.01.07 AD at 01:07:01");
+        t6.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
+        t6.set(2, "+00:00");
+        DateTime dt6 = func4.exec(t6);
+        assertEquals(dt6, new DateTime("2009-01-07T01:07:01.000Z", DateTimeZone.forID("+00:00")));
+
+        Tuple t7 = TupleFactory.getInstance().newTuple(3);
+        t7.set(0, "2009.01.07 AD at 01:07:01 +0800");
+        t7.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
+        t7.set(2, "asia/singapore");
+        DateTime dt7 = func4.exec(t7);
+        assertEquals(dt7, new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00")));
+
+        ToUnixTime func5 = new ToUnixTime();
+        Tuple t8 = TupleFactory.getInstance().newTuple(1);
+        t8.set(0, new DateTime(1231290421000L));
+        Long ut1 = func5.exec(t8);
+        assertEquals(ut1.longValue(), 1231290421L);
+
+        ToString func6 = new ToString();
+
+        Tuple t9 = TupleFactory.getInstance().newTuple(1);
+        t9.set(0, new DateTime("2009-01-07T01:07:01.000Z"));
+        String dtStr1 = func6.exec(t9);
+        assertEquals(dtStr1, "2009-01-07T01:07:01.000Z");
+
+        Tuple t10 = TupleFactory.getInstance().newTuple(1);
+        t10.set(0, new DateTime("2009-01-07T09:07:01.000+08:00"));
+        String dtStr2 = func6.exec(t10);
+        assertEquals(dtStr2, "2009-01-07T01:07:01.000Z");
+
+        Tuple t11 = TupleFactory.getInstance().newTuple(2);
+        t11.set(0, new DateTime("2009-01-07T01:07:01.000Z"));
+        t11.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
+        String dtStr3 = func6.exec(t11);
+        assertEquals(dtStr3, "2009.01.07 AD at 01:07:01");
+
+        Tuple t12 = TupleFactory.getInstance().newTuple(2);
+        t12.set(0, new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00")));
+        t12.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
+        String dtStr4 = func6.exec(t12);
+        assertEquals(dtStr4, "2009.01.07 AD at 01:07:01 +0800");
+        
+        ToMilliSeconds func7 = new ToMilliSeconds();
+        Tuple t13 = TupleFactory.getInstance().newTuple(1);
+        t13.set(0, new DateTime(1231290421000L));
+        Long ut2 = func7.exec(t11);
+        assertEquals(ut2.longValue(), 1231290421000L);
+        
+        CurrentTime func8 = new CurrentTime();
+        DateTime dt11 = func8.exec(null);
+        Assert.assertNotNull(dt11);
+    }
+
     /**
      * Test the case where the combiner is not called - so initial is called
      * and then final is called
@@ -2538,4 +2680,113 @@ public class TestBuiltin {
         assertEquals((String)resultList.get(1), "source");
     }
 
+    @Test
+    public void testDiffDateTime() throws Exception {
+        Tuple t = TupleFactory.getInstance().newTuple(2);
+        t.set(0, new DateTime("2009-01-07T00:00:00.000Z"));
+        t.set(1, new DateTime("2002-01-01T00:00:00.000Z"));
+
+        YearsBetween func1 = new YearsBetween();
+        Long years = func1.exec(t);
+        System.out.println("Years: " + years.toString());
+        Assert.assertEquals(years.longValue(), 7L);
+        
+        MonthsBetween func2 = new MonthsBetween();
+        Long months = func2.exec(t);
+        System.out.println("Months: " + months.toString());
+        Assert.assertEquals(months.longValue(),84L);
+        
+        WeeksBetween func3 = new WeeksBetween();
+        Long weeks = func3.exec(t);
+        System.out.println("Weeks: " + weeks.toString());
+        Assert.assertEquals(weeks.longValue(), 366L);
+
+        DaysBetween func4 = new DaysBetween();
+        Long days = func4.exec(t);
+        System.out.println("Days: " + days.toString());
+        Assert.assertEquals(days.longValue(), 2563L);
+
+        HoursBetween func5 = new HoursBetween();
+        Long hours = func5.exec(t);
+        System.out.println("Hours: " + hours.toString());
+        Assert.assertEquals(hours.longValue(), 61512L);
+
+        MinutesBetween func6 = new MinutesBetween();
+        Long mins = func6.exec(t);
+        System.out.println("Minutes: " + mins.toString());
+        Assert.assertEquals(mins.longValue(), 3690720L);
+
+        SecondsBetween func7 = new SecondsBetween();
+        Long secs = func7.exec(t);
+        System.out.println("Seconds: " + secs.toString());
+        Assert.assertEquals(secs.longValue(), 221443200L);
+
+        MilliSecondsBetween func8 = new MilliSecondsBetween();
+        Long millis = func8.exec(t);
+        System.out.println("MilliSeconds: " + millis.toString());
+        Assert.assertEquals(millis.longValue(), 221443200000L);
+    }
+
+    @Test
+    public void testGetDateTimeField() throws Exception {
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, new DateTime("2010-04-15T08:11:33.020Z"));
+        Tuple t2 = TupleFactory.getInstance().newTuple(1);
+        t2.set(0, new DateTime("2010-04-15T08:11:33.020+08:00"));
+        
+        GetYear func1 = new GetYear();
+        Integer year = func1.exec(t1);
+        assertEquals(year.intValue(), 2010);
+        year = func1.exec(t2);
+        assertEquals(year.intValue(), 2010);
+
+        GetMonth func2 = new GetMonth();
+        Integer month = func2.exec(t1);
+        assertEquals(month.intValue(), 4);
+        month = func2.exec(t2);
+        assertEquals(month.intValue(), 4);
+        
+        GetDay func3 = new GetDay();
+        Integer day = func3.exec(t1);
+        assertEquals(day.intValue(), 15);
+        day = func3.exec(t2);
+        assertEquals(day.intValue(), 15);
+        
+        GetHour func4 = new GetHour();
+        Integer hour = func4.exec(t1);
+        assertEquals(hour.intValue(), 8);
+        hour = func4.exec(t2);
+        assertEquals(hour.intValue(), 0);
+        
+        GetMinute func5 = new GetMinute();
+        Integer minute = func5.exec(t1);
+        assertEquals(minute.intValue(), 11);
+        minute = func5.exec(t2);
+        assertEquals(minute.intValue(), 11);
+        
+        GetSecond func6 = new GetSecond();
+        Integer second = func6.exec(t1);
+        assertEquals(second.intValue(), 33);
+        second = func6.exec(t2);
+        assertEquals(second.intValue(), 33);
+        
+        GetMilliSecond func7 = new GetMilliSecond();
+        Integer milli = func7.exec(t1);
+        assertEquals(milli.intValue(), 20);
+        milli = func7.exec(t2);
+        assertEquals(milli.intValue(), 20);
+
+        GetWeekYear func8 = new GetWeekYear();
+        Integer weekyear = func8.exec(t1);
+        assertEquals(weekyear.intValue(), 2010);
+        weekyear = func8.exec(t2);
+        assertEquals(weekyear.intValue(), 2010);
+        
+        GetWeek func9 = new GetWeek();
+        Integer week = func9.exec(t1);
+        assertEquals(week.intValue(), 15);
+        week = func9.exec(t2);
+        assertEquals(week.intValue(), 15);
+    }
+
 }

Modified: pig/trunk/test/org/apache/pig/test/TestConversions.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestConversions.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestConversions.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestConversions.java Fri Aug 24 00:18:05 2012
@@ -22,6 +22,9 @@ import java.util.Random;
 import java.util.Map;
 import java.io.IOException;
 
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
 import org.apache.pig.ResourceSchema;
 import org.apache.pig.ResourceSchema.ResourceFieldSchema;
 import org.apache.pig.builtin.PigStorage;
@@ -52,6 +55,11 @@ public class TestConversions extends Tes
 	Random r = new Random();
 	final int MAX = 10;
 
+	@Override
+	public void setUp() {
+	    DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.UTC.getOffset(null)));
+	}
+
     @Test
     public void testBytesToBoolean() throws IOException {
         // valid booleans
@@ -245,6 +253,12 @@ public class TestConversions extends Tes
         Double d = r.nextDouble();
         assertTrue(DataType.equalByteArrays(d.toString().getBytes(), ((Utf8StorageConverter)ps.getLoadCaster()).toBytes(d)));
     }
+
+    @Test
+    public void testDateTimeToBytes() throws IOException {
+        DateTime dt = new DateTime(r.nextLong());
+        assertTrue(DataType.equalByteArrays(dt.toString().getBytes(), ((Utf8StorageConverter)ps.getLoadCaster()).toBytes(dt)));
+    }
         
     @Test
     public void testCharArrayToBytes() throws IOException {

Modified: pig/trunk/test/org/apache/pig/test/TestDivide.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestDivide.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestDivide.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestDivide.java Fri Aug 24 00:18:05 2012
@@ -23,6 +23,8 @@ import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -54,7 +56,7 @@ public class TestDivide extends TestCase
     public void testOperator() throws ExecException{
         //int TRIALS = 10;
         byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY, 
-                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.MAP, DataType.TUPLE};
+                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.DATETIME, DataType.MAP, DataType.TUPLE};
         //Map<Byte,String> map = GenRandomData.genTypeToNameMap();
         System.out.println("Testing DIVIDE operator");
         for(byte type : types) {
@@ -250,6 +252,25 @@ public class TestDivide extends TestCase
                 assertEquals(null, (Long)resl.result);
                 break;
             }
+            case DataType.DATETIME:
+                DateTime inpdt1 = new DateTime(r.nextLong());
+                DateTime inpdt2 = new DateTime(r.nextLong());
+                lt.setValue(inpdt1);
+                rt.setValue(inpdt2);
+                Result resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                
+                // test with null in lhs
+                lt.setValue(null);
+                rt.setValue(inpdt2);
+                resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                // test with null in rhs
+                lt.setValue(inpdt1);
+                rt.setValue(null);
+                resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                break;
             case DataType.MAP: {
                 Map<String,Object> inpm1 = GenRandomData.genRandMap(r, 10);
                 Map<String,Object> inpm2 = GenRandomData.genRandMap(r, 10);

Modified: pig/trunk/test/org/apache/pig/test/TestEqualTo.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestEqualTo.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestEqualTo.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestEqualTo.java Fri Aug 24 00:18:05 2012
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -240,6 +242,44 @@ public class TestEqualTo extends junit.f
 	}
 
     @Test
+    public void testDateTimeNe() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        EqualToExpr g = GenPhyOp.compEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        EqualToExpr g = GenPhyOp.compEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        
+        checkNullValues(  DataType.DATETIME,  new DateTime(1L) );
+
+    }
+
+    @Test
     public void testStringNe() throws Exception {
         ConstantExpression lt = GenPhyOp.exprConst();
         lt.setValue(new String("a"));

Modified: pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java Fri Aug 24 00:18:05 2012
@@ -20,6 +20,8 @@ package org.apache.pig.test;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -253,6 +255,56 @@ public class TestGTOrEqual extends junit
     	checkNullValues( DataType.DOUBLE,  new Double(1.0) );
     }
 
+    @Test
+    public void testDateTimeGt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        GTOrEqualToExpr g = GenPhyOp.compGTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeLt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(0L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        GTOrEqualToExpr g = GenPhyOp.compGTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        GTOrEqualToExpr g = GenPhyOp.compGTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        
+        checkNullValues( DataType.DATETIME,  new DateTime(1L) );
+    }
 
     @Test
     public void testStringGt() throws Exception {

Modified: pig/trunk/test/org/apache/pig/test/TestGreaterThan.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestGreaterThan.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestGreaterThan.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestGreaterThan.java Fri Aug 24 00:18:05 2012
@@ -20,6 +20,8 @@ package org.apache.pig.test;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -264,7 +266,63 @@ public class TestGreaterThan extends jun
 	    checkNullValues(   DataType.DOUBLE,  new Double(1.0) );
 	    
 	}
+
+    @Test
+    public void testDateTimeGt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        GreaterThanExpr g = GenPhyOp.compGreaterThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+
+    @Test
+    public void testDateTimeLt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(0L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        GreaterThanExpr g = GenPhyOp.compGreaterThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+  
     
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        GreaterThanExpr g = GenPhyOp.compGreaterThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        
+        checkNullValues(  DataType.DATETIME,  new DateTime(1L) );
+
+    }
+
 	@Test
     public void testStringGt() throws Exception {
         ConstantExpression lt = GenPhyOp.exprConst();

Modified: pig/trunk/test/org/apache/pig/test/TestLTOrEqual.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLTOrEqual.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLTOrEqual.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLTOrEqual.java Fri Aug 24 00:18:05 2012
@@ -20,6 +20,8 @@ package org.apache.pig.test;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -251,6 +253,56 @@ public class TestLTOrEqual extends junit
 	}
 
     @Test
+    public void testDateTimeGt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        LTOrEqualToExpr g = GenPhyOp.compLTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeLt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(0L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        LTOrEqualToExpr g = GenPhyOp.compLTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        LTOrEqualToExpr g = GenPhyOp.compLTOrEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        checkNullValues(  DataType.DATETIME, new DateTime(1L) );            
+    }
+
+    @Test
     public void testStringGt() throws Exception {
         ConstantExpression lt = GenPhyOp.exprConst();
         lt.setValue(new String("b"));

Modified: pig/trunk/test/org/apache/pig/test/TestLessThan.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLessThan.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLessThan.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLessThan.java Fri Aug 24 00:18:05 2012
@@ -20,6 +20,8 @@ package org.apache.pig.test;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -255,6 +257,58 @@ public class TestLessThan extends junit.
     }  
 
     @Test
+    public void testDateTimeGt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        LessThanExpr g = GenPhyOp.compLessThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeLt() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(0L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        LessThanExpr g = GenPhyOp.compLessThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        LessThanExpr g = GenPhyOp.compLessThanExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+    
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        
+        checkNullValues( DataType.DATETIME,  new DateTime(1L) );
+    }  
+
+    @Test
     public void testStringGt() throws Exception {
         ConstantExpression lt = GenPhyOp.exprConst();
         lt.setValue(new String("b"));

Modified: pig/trunk/test/org/apache/pig/test/TestMod.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestMod.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestMod.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestMod.java Fri Aug 24 00:18:05 2012
@@ -23,6 +23,8 @@ import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -54,7 +56,7 @@ public class TestMod extends TestCase{
     public void testOperator() throws ExecException{
         //int TRIALS = 10;
         byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY, 
-                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.MAP, DataType.TUPLE};
+                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.DATETIME, DataType.MAP, DataType.TUPLE};
         //Map<Byte,String> map = GenRandomData.genTypeToNameMap();
         System.out.println("Testing Mod operator");
         for(byte type : types) {
@@ -228,6 +230,25 @@ public class TestMod extends TestCase{
                 assertEquals(null, (Long)resl.result);
                 break;
             }
+            case DataType.DATETIME:
+                DateTime inpdt1 = new DateTime(r.nextLong());
+                DateTime inpdt2 = new DateTime(r.nextLong());
+                lt.setValue(inpdt1);
+                rt.setValue(inpdt2);
+                Result resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                
+                // test with null in lhs
+                lt.setValue(null);
+                rt.setValue(inpdt2);
+                resb = op.getNext(inpdt1);
+                assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+                // test with null in rhs
+                lt.setValue(inpdt1);
+                rt.setValue(null);
+                resb = op.getNext(inpdt1);
+                assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+                break;
             case DataType.MAP: {
                 Map<String,Object> inpm1 = GenRandomData.genRandMap(r, 10);
                 Map<String,Object> inpm2 = GenRandomData.genRandMap(r, 10);

Modified: pig/trunk/test/org/apache/pig/test/TestMultiply.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestMultiply.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestMultiply.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestMultiply.java Fri Aug 24 00:18:05 2012
@@ -23,6 +23,8 @@ import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -54,7 +56,7 @@ public class TestMultiply extends TestCa
     public void testOperator() throws ExecException{
         //int TRIALS = 10;
         byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY, 
-                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.MAP, DataType.TUPLE};
+                DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.DATETIME, DataType.MAP, DataType.TUPLE};
         //Map<Byte,String> map = GenRandomData.genTypeToNameMap();
         System.out.println("Testing Multiply operator");
         for(byte type : types) {
@@ -230,6 +232,26 @@ public class TestMultiply extends TestCa
                 assertEquals(null, (Long)resl.result);
                 break;
             }
+            case DataType.DATETIME: {
+                DateTime inpdt1 = new DateTime(r.nextLong());
+                DateTime inpdt2 = new DateTime(r.nextLong());
+                lt.setValue(inpdt1);
+                rt.setValue(inpdt2);
+                Result resdt = op.getNext(inpdt1);
+                assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+                
+                // test with null in lhs
+                lt.setValue(null);
+                rt.setValue(inpdt2);
+                resb = op.getNext(inpdt1);
+                assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+                // test with null in rhs
+                lt.setValue(inpdt1);
+                rt.setValue(null);
+                resb = op.getNext(inpdt1);
+                assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+                break;
+            }
             case DataType.MAP: {
                 Map<String,Object> inpm1 = GenRandomData.genRandMap(r, 10);
                 Map<String,Object> inpm2 = GenRandomData.genRandMap(r, 10);

Modified: pig/trunk/test/org/apache/pig/test/TestNotEqualTo.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestNotEqualTo.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestNotEqualTo.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestNotEqualTo.java Fri Aug 24 00:18:05 2012
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -234,6 +236,43 @@ public class TestNotEqualTo extends juni
     }
 
     @Test
+    public void testDateTimeNe() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(0L));
+        NotEqualToExpr g = GenPhyOp.compNotEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertTrue((Boolean)r.result);
+    }
+
+    @Test
+    public void testDateTimeEq() throws Exception {
+        ConstantExpression lt = GenPhyOp.exprConst();
+        lt.setValue(new DateTime(1L));
+        ConstantExpression rt = GenPhyOp.exprConst();
+        rt.setValue(new DateTime(1L));
+        NotEqualToExpr g = GenPhyOp.compNotEqualToExpr();
+        g.setLhs(lt);
+        g.setRhs(rt);
+        g.setOperandType(DataType.DATETIME);
+        Result r = g.getNext(new Boolean(true));
+        assertEquals(POStatus.STATUS_OK, r.returnStatus);
+        assertFalse((Boolean)r.result);
+    }
+
+
+    @Test
+    public void testDateTimeAndNullValues() throws Exception {
+        
+        checkNullValues( DataType.DATETIME,  new DateTime(1L) );
+    }
+
+    @Test
     public void testStringNe() throws Exception {
         ConstantExpression lt = GenPhyOp.exprConst();
         lt.setValue(new String("a"));

Modified: pig/trunk/test/org/apache/pig/test/TestNull.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestNull.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestNull.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestNull.java Fri Aug 24 00:18:05 2012
@@ -22,6 +22,8 @@ import static org.junit.Assert.*;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
@@ -193,6 +195,22 @@ public class TestNull extends junit.fram
             if (!res.result.equals(true))
                 return false;
             return true;
+        case DataType.DATETIME:
+            inp1 = new DateTime(r.nextLong());
+            res = isNullExpr.getNext((Boolean) null);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Boolean) null);
+            ret = (DataType.compare(inp1, null) == 0);
+            if (!(res.result.equals(ret)))
+                return false;
+            // set the input to null and test
+            lt.setValue((DateTime)null);
+            res = isNullExpr.getNext((Boolean) null);
+            if (!res.result.equals(true))
+                return false;
+            return true;
         case DataType.MAP:
             inp1 = GenRandomData.genRandMap(r, 10);
             res = isNullExpr.getNext((Boolean) null);

Modified: pig/trunk/test/org/apache/pig/test/TestOrderBy.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestOrderBy.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestOrderBy.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestOrderBy.java Fri Aug 24 00:18:05 2012
@@ -28,6 +28,9 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
 import org.apache.pig.ExecType;
 import org.apache.pig.PigServer;
 import org.apache.pig.data.DataType;
@@ -65,6 +68,8 @@ public class TestOrderBy extends TestCas
             ps.println("1\t" + DATA[1][i] + "\t" + DATA[0][i]);
         }
         ps.close();
+        
+        DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.UTC.getOffset(null)));
     }
     
     @After
@@ -303,4 +308,52 @@ public class TestOrderBy extends TestCas
         return fp1;
     }
 
+    @Test
+    public void testOrderByDateTimeColumn() throws Exception {
+        File tmpFile = genDataSetFileForOrderByDateTimeColumn();
+        List<Tuple> expectedResults = new ArrayList<Tuple>();
+        expectedResults.add(Util.buildTuple("value3", null));
+        expectedResults.add(Util.buildTuple("value4", null));
+        expectedResults.add(Util.buildTuple("value10", null));
+        expectedResults.add(Util.buildTuple("value2", new DateTime("1970-01-01T00:00:00.000Z")));
+        expectedResults.add(Util.buildTuple("value6", new DateTime("1970-01-01T00:00:01.000Z")));
+        expectedResults.add(Util.buildTuple("value7", new DateTime("1970-01-01T00:00:01.000Z")));
+        expectedResults.add(Util.buildTuple("value1", new DateTime("1970-01-01T00:01:00.000Z")));
+        expectedResults.add(Util.buildTuple("value5", new DateTime("1970-01-01T01:00:00.000Z")));
+        expectedResults.add(Util.buildTuple("value8", new DateTime("1970-01-02T00:00:00.000Z")));
+        expectedResults.add(Util.buildTuple("value9", new DateTime("1970-02-01T00:00:00.000Z")));
+        
+        pig.registerQuery("blah = load '"
+                + Util.generateURI(tmpFile.toString(), pig.getPigContext())
+                + "' as (data:chararray, test:datetime);");
+        pig.registerQuery("ordered = order blah by test;");
+        Iterator<Tuple> expectedItr = expectedResults.iterator();
+        Iterator<Tuple> actualItr = pig.openIterator("ordered");
+        while (expectedItr.hasNext() && actualItr.hasNext()) {
+            Tuple expectedTuple = expectedItr.next();
+            Tuple actualTuple = actualItr.next();
+            assertEquals(expectedTuple, actualTuple);
+        }
+        assertEquals(expectedItr.hasNext(), actualItr.hasNext());
+    }
+
+    private File genDataSetFileForOrderByDateTimeColumn() throws IOException {
+
+        File fp1 = File.createTempFile("order_by_datetime", "txt");
+        PrintStream ps = new PrintStream(new FileOutputStream(fp1));
+        ps.println("value1\t1970-01-01T00:01:00.000Z");
+        ps.println("value2\t1970-01-01T00:00:00.000Z");
+        ps.println("value3\t");
+        ps.println("value4\t");
+        ps.println("value5\t1970-01-01T01:00:00.000Z");
+        ps.println("value6\t1970-01-01T00:00:01.000Z");
+        ps.println("value7\t1970-01-01T00:00:01.000Z");
+        ps.println("value8\t1970-01-02T00:00:00.000Z");
+        ps.println("value9\t1970-02-01T00:00:00.000Z");
+        ps.println("value10\t");
+
+        ps.close();
+
+        return fp1;
+    }
 }

Modified: pig/trunk/test/org/apache/pig/test/TestPOBinCond.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPOBinCond.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPOBinCond.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPOBinCond.java Fri Aug 24 00:18:05 2012
@@ -39,6 +39,7 @@ import org.apache.pig.backend.hadoop.exe
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.EqualToExpr;
 import org.apache.pig.impl.plan.PlanException;
 import org.apache.pig.test.utils.GenPhyOp;
+import org.joda.time.DateTime;
 import org.junit.Before;
 
 import junit.framework.TestCase;
@@ -275,7 +276,23 @@ public class TestPOBinCond extends TestC
 	    }
 
     }
-   
+
+    public void testPOBinCondWithDateTime() throws  ExecException, PlanException {
+        bag= getBag(DataType.DATETIME);
+        TestPoBinCondHelper testHelper= new TestPoBinCondHelper(DataType.DATETIME, new DateTime(1L) );
+    
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+               Tuple t = it.next();
+               testHelper.getPlan().attachInput(t);
+               DateTime value = (DateTime) t.get(0);
+               int expected = value.equals(new DateTime(1L))? 1:0 ;
+               Integer dummy = new Integer(0);
+               Integer result=(Integer)testHelper.getOperator().getNext(dummy).result;
+               int actual = result.intValue();
+               assertEquals( expected, actual );
+        }
+    }
+
     public void testPOBinCondIntWithNull() throws  ExecException, PlanException {
    	
     	bag= getBagWithNulls(DataType.INTEGER);
@@ -364,6 +381,33 @@ public class TestPOBinCond extends TestC
 	       }
 
 	}
+
+    public void testPOBinCondDateTimeWithNull() throws  ExecException, PlanException {
+        
+        bag= getBagWithNulls(DataType.DATETIME);
+        TestPoBinCondHelper testHelper= new TestPoBinCondHelper(DataType.DATETIME, new DateTime(1L) );
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+               Tuple t = it.next();
+               testHelper.getPlan().attachInput(t);
+               
+               DateTime value=null;
+               if ( t.get(0)!=null){
+                   value = (DateTime) t.get(0);
+               }
+               Integer dummy = new Integer(0);
+               Integer result=(Integer)testHelper.getOperator().getNext(dummy).result;                  
+               int expected;
+               int actual;
+               if ( value!=null ) {
+                   expected=value.equals(new DateTime(1L))? 1:0 ;
+                   actual  = result.intValue();
+                   assertEquals( expected, actual );
+               } else {
+                   assertEquals( null, result );
+               }
+           }
+    }
    
     protected class TestPoBinCondHelper {
     	
@@ -451,7 +495,10 @@ public class TestPOBinCond extends TestC
                     break;
                 case DataType.DOUBLE:
                     t.append((i % 2 == 0 ? 1.0 : 0.0));
-                    break;                
+                    break;
+                case DataType.DATETIME:
+                    t.append(new DateTime(r.nextLong() % 2L));
+                    break;
             }
             t.append(1);
             t.append(0);
@@ -483,6 +530,9 @@ public class TestPOBinCond extends TestC
                     case DataType.DOUBLE:
                         t.append( (i % 2 == 0 ? 1.0 : 0.0));
                         break;
+                    case DataType.DATETIME:
+                        t.append(new DateTime(r.nextLong() % 2L));
+                        break;
                 }
             }            
             t.append(1);

Modified: pig/trunk/test/org/apache/pig/test/TestPOCast.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPOCast.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPOCast.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPOCast.java Fri Aug 24 00:18:05 2012
@@ -25,6 +25,8 @@ import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.joda.time.DateTime;
+
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.InputFormat;
 import org.apache.hadoop.mapreduce.Job;
@@ -167,7 +169,15 @@ public class TestPOCast extends TestCase
                 assertEquals(d, res.result);
             }
         }
-        
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = null;
+            Result res = op.getNext(dt);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+
         for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
             Tuple t = it.next();
             plan.attachInput(t);
@@ -345,6 +355,21 @@ public class TestPOCast extends TestCase
 				assertEquals(d, res.result);
 			}
 		}
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = new DateTime(((Integer)t.get(0)).longValue());
+            Result res = op.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                assertEquals(dt, res.result);
+            }
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                assertEquals(dt, res.result);
+            }
+        }
 		
 		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
 			Tuple t = it.next();
@@ -531,7 +556,23 @@ public class TestPOCast extends TestCase
 			if(res.returnStatus == POStatus.STATUS_OK)
 				assertEquals(d, res.result);
 		}
-		
+
+		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = new DateTime((Long)t.get(0));
+            Result res = op.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + l);
+                assertEquals(dt, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(dt, res.result);
+        }
+
 		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
 			Tuple t = it.next();
 			plan.attachInput(t);
@@ -712,7 +753,23 @@ public class TestPOCast extends TestCase
 			if(res.returnStatus == POStatus.STATUS_OK)
 				assertEquals(d, res.result);
 		}
-		
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = new DateTime(((Float)t.get(0)).longValue());
+            Result res = op.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + dt);
+                assertEquals(dt, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(dt, res.result);
+        }   
+
 		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
 			Tuple t = it.next();
 			plan.attachInput(t);
@@ -902,7 +959,23 @@ public class TestPOCast extends TestCase
 			if(res.returnStatus == POStatus.STATUS_OK)
 				assertEquals(d, res.result);
 		}
-		
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = new DateTime(((Double)t.get(0)).longValue());
+            Result res = op.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + dt);
+                assertEquals(dt, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(dt, res.result);
+        }		
+
 		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
 			Tuple t = it.next();
 			plan.attachInput(t);
@@ -980,7 +1053,202 @@ public class TestPOCast extends TestCase
             }
         }
 	}
-	
+
+    @Test
+    public void testDateTimeToOther() throws IOException {
+        //Create data
+        DataBag bag = BagFactory.getInstance().newDefaultBag();
+        for(int i = 0; i < MAX; i++) {
+            Tuple t = TupleFactory.getInstance().newTuple();
+            t.append(i == 0 ? new DateTime(0L) : new DateTime(r.nextLong()));
+            bag.add(t);
+        }
+        
+        POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
+        LoadFunc load = new TestLoader();
+        op.setFuncSpec(new FuncSpec(load.getClass().getName()));
+        POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
+        PhysicalPlan plan = new PhysicalPlan();
+        plan.add(prj);
+        plan.add(op);
+        plan.connect(prj, op);
+        
+        prj.setResultType(DataType.DATETIME);
+        
+        // Plan to test when result type is ByteArray and casting is requested
+        // for example casting of values coming out of map lookup.
+        POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
+        PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
+
+        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Boolean b = null;
+            Result res = op.getNext(b);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Integer i = new Long(((DateTime) t.get(0)).getMillis()).intValue();
+            Result res = op.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + i);
+                assertEquals(i, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(i, res.result);
+            
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Float f = new Float(Long.valueOf(((DateTime) t.get(0)).getMillis()).floatValue());
+            Result res = op.getNext(f);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + f);
+                assertEquals(f, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(f);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(f, res.result);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Long l = new Long(((DateTime)t.get(0)).getMillis());
+            Result res = op.getNext(l);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + l);
+                assertEquals(l, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(l);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(l, res.result);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Double d = new Double(Long.valueOf(((DateTime) t.get(0)).getMillis()).doubleValue());
+            Result res = op.getNext(d);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + f);
+                assertEquals(d, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(d);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(d, res.result);
+        }
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DateTime dt = (DateTime)t.get(0);
+            Result res = op.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + l);
+                assertEquals(dt, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dt);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(dt, res.result);
+        }
+
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            String str = ((DateTime)t.get(0)).toString();
+            Result res = op.getNext(str);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + str);
+                assertEquals(str, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(str);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(str, res.result);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DataByteArray dba = new DataByteArray(((DateTime)t.get(0)).toString().getBytes());
+            Result res = op.getNext(dba);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + dba);
+                assertEquals(dba, res.result);
+            }
+            
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(dba);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(dba, res.result);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Map map = null;
+            Result res = op.getNext(map);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            Result res = op.getNext(t);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            DataBag b = null;
+            Result res = op.getNext(b);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+        {
+            planToTestBACasts.attachInput(dummyTuple);
+            try{
+                opWithInputTypeAsBA.getNext(dummyMap);
+            }catch (Exception e) {
+                assertEquals(ExecException.class, e.getClass());
+            }
+        }
+        {
+            planToTestBACasts.attachInput(dummyTuple);
+            try{
+                opWithInputTypeAsBA.getNext(dummyTuple);
+            }catch (Exception e) {
+                assertEquals(ExecException.class, e.getClass());
+            }
+        }
+        {
+            planToTestBACasts.attachInput(dummyTuple);
+            try{
+                opWithInputTypeAsBA.getNext(dummyBag);
+            }catch (Exception e) {
+                assertEquals(ExecException.class, e.getClass());
+            }
+        }
+    }
+
 	@Test
 	public void testStringToOther() throws IOException {
 		POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
@@ -1099,7 +1367,23 @@ public class TestPOCast extends TestCase
 			if(res.returnStatus == POStatus.STATUS_OK)
 				assertEquals(i, res.result);
 		}
-		
+
+        {
+            Tuple t = tf.newTuple();
+            t.append((new DateTime(r.nextLong())).toString());
+            plan.attachInput(t);
+            DateTime i = new DateTime(((String) t.get(0)));
+            Result res = op.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + i);
+                assertEquals(i, res.result);
+            }
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(i, res.result);
+        }
+
 		{
 			Tuple t = tf.newTuple();
 			t.append(GenRandomData.genRandString(r));
@@ -1237,6 +1521,10 @@ public class TestPOCast extends TestCase
             return new Long(Long.valueOf(new DataByteArray(b).toString()));
         }
 
+        public DateTime bytesToDateTime(byte[] b) throws IOException {
+            return new DateTime(new DataByteArray(b).toString());
+        }
+
         public Map<String, Object> bytesToMap(byte[] b) throws IOException {
           return null;
         }
@@ -1272,6 +1560,10 @@ public class TestPOCast extends TestCase
         public byte[] toBytes(Long l) throws IOException {
             return l.toString().getBytes();
         }
+        
+        public byte[] toBytes(DateTime dt) throws IOException {
+            return dt.toString().getBytes();
+        }
 
         public byte[] toBytes(Boolean b) throws IOException {
             return b.toString().getBytes();
@@ -1423,7 +1715,23 @@ public class TestPOCast extends TestCase
 			if(res.returnStatus == POStatus.STATUS_OK)
 				assertEquals(i, res.result);
 		}
-		
+
+		{
+            Tuple t = tf.newTuple();
+            t.append(new DataByteArray((new DateTime(r.nextLong())).toString().getBytes()));
+            plan.attachInput(t);
+            DateTime i = new DateTime(((DataByteArray) t.get(0)).toString());
+            Result res = op.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + i);
+                assertEquals(i, res.result);
+            }
+            planToTestBACasts.attachInput(t);
+            res = opWithInputTypeAsBA.getNext(i);
+            if(res.returnStatus == POStatus.STATUS_OK)
+                assertEquals(i, res.result);
+        }
+
 		{
 			Tuple t = tf.newTuple();
 			t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
@@ -1622,7 +1930,24 @@ public class TestPOCast extends TestCase
                 assertEquals(input, res.result);
             }
         }
-        
+
+        {
+            // create a new POCast each time since we 
+            // maintain a state variable per POCast object
+            // indicating if cast is really required
+            POCast newOp = new POCast(new OperatorKey("", r.nextLong()), -1);
+            plan = constructPlan(newOp);
+            Tuple t = tf.newTuple();
+            DateTime input = new DateTime(r.nextLong());
+            t.append(input);
+            plan.attachInput(t);
+            Result res = newOp.getNext(new DateTime(0L));
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                //System.out.println(res.result + " : " + i);
+                assertEquals(input, res.result);
+            }
+        }
+
         {
             // create a new POCast each time since we 
             // maintain a state variable per POCast object
@@ -1777,7 +2102,18 @@ public class TestPOCast extends TestCase
 			Result res = op.getNext(i);
 			assertEquals(POStatus.STATUS_ERR, res.returnStatus);
 		}
-	      
+
+		{
+            Tuple t = tf.newTuple();
+            t.append(GenRandomData.genRandString(r));
+            Tuple tNew = tf.newTuple();
+            tNew.append(t);
+            plan.attachInput(tNew);
+            DateTime dt = null;
+            Result res = op.getNext(dt);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+		
 		{
 			Tuple t = tf.newTuple();
 			t.append(GenRandomData.genRandString(r));
@@ -1942,7 +2278,16 @@ public class TestPOCast extends TestCase
 			Result res = op.getNext(i);
 			assertEquals(POStatus.STATUS_ERR, res.returnStatus);
 		}
-		
+
+        {
+            Tuple t = tf.newTuple();
+            t.append(GenRandomData.genRandSmallTupDataBag(r, 1, 100));
+            plan.attachInput(t);
+            DateTime dt = null;
+            Result res = op.getNext(dt);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+
 		{
 			Tuple t = tf.newTuple();
 			t.append(GenRandomData.genRandSmallTupDataBag(r, 1, 100));
@@ -2102,7 +2447,15 @@ public class TestPOCast extends TestCase
 			Result res = op.getNext(i);
 			assertEquals(POStatus.STATUS_ERR, res.returnStatus);
 		}
-		
+
+        {     
+            Tuple t = tf.newTuple();
+            t.append(GenRandomData.genRandMap(r, 10));
+            DateTime dt = null;
+            Result res = op.getNext(dt);
+            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
+        }
+
 		{
 			Tuple t = tf.newTuple();
 			t.append(GenRandomData.genRandMap(r, 10));
@@ -2203,7 +2556,21 @@ public class TestPOCast extends TestCase
 
 			}
 		}
-		
+
+        prj.setResultType(DataType.DATETIME); 
+        
+        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+            Tuple t = it.next();
+            plan.attachInput(t);
+            if(t.get(0) == null) {
+                
+                DateTime result  = (DateTime)op.getNext((DateTime)null).result;
+                assertEquals( null, result);
+
+            } 
+            
+        }	
+
 		prj.setResultType(DataType.CHARARRAY);
 		
 		for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
@@ -2249,16 +2616,18 @@ public class TestPOCast extends TestCase
 		// Create a bag having tuples having values of different types.
 		for(int i = 0; i < MAX; i++) {
 			Tuple t = TupleFactory.getInstance().newTuple();
-			if (i % 5 == 0)
+			if (i % 6 == 0)
 			    t.append(r.nextBoolean());
-			if(i % 5 == 1)
+			if(i % 6 == 1)
 				t.append(r.nextInt());
-			if(i % 5 == 2)
+			if(i % 6 == 2)
 				t.append(r.nextLong());
-			if(i % 5 == 3)
+			if(i % 6 == 3)
 				t.append(r.nextDouble());
-			if(i % 5 == 4)
+			if(i % 6 == 4)
 				t.append(r.nextFloat());
+			if(i % 6 == 5)
+			    t.append(r.nextLong());
 			bag.add(t);
 		}
 
@@ -2294,6 +2663,14 @@ public class TestPOCast extends TestCase
 				assertEquals(d, res.result);
 			}
 
+			if (!(toCast instanceof Boolean)) {
+                DateTime dt = DataType.toDateTime(toCast);
+                res = opWithInputTypeAsBA.getNext(dt);
+                if(res.returnStatus == POStatus.STATUS_OK) {
+                    assertEquals(dt, res.result);
+                }
+			}
+
 			String s = DataType.toString(toCast);
 			res = opWithInputTypeAsBA.getNext(s);
 			if(res.returnStatus == POStatus.STATUS_OK) {

Modified: pig/trunk/test/org/apache/pig/test/TestPackage.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPackage.java?rev=1376800&r1=1376799&r2=1376800&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPackage.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPackage.java Fri Aug 24 00:18:05 2012
@@ -27,6 +27,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 
+import org.joda.time.DateTime;
+
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.HDataType;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
@@ -148,6 +150,9 @@ public class TestPackage extends junit.f
         case DataType.LONG:
             runTest(r.nextLong(),inner, DataType.LONG);
             break;
+        case DataType.DATETIME:
+            runTest(new DateTime(r.nextLong()),inner, DataType.DATETIME);
+            break;
         case DataType.MAP:
         case DataType.INTERNALMAP:
         case DataType.BYTE:



Mime
View raw message