You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2010/03/31 00:53:21 UTC

svn commit: r929330 [2/2] - in /hadoop/pig/branches/branch-0.7/contrib: ./ piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/datetime/convert/ piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/datetime/diff/ piggybank/java...

Added: hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/convert/TestConvertDateTime.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/convert/TestConvertDateTime.java?rev=929330&view=auto
==============================================================================
--- hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/convert/TestConvertDateTime.java (added)
+++ hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/convert/TestConvertDateTime.java Tue Mar 30 22:53:20 2010
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.piggybank.test.evaluation.datetime.convert;
+
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.datetime.convert.*;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class TestConvertDateTime extends TestCase {
+    @Test
+    public void testUnixToISO() throws Exception {
+
+        // Verify that (long) unix datetimes convert to ISO datetimes
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, 1231290421000L);
+
+        UnixToISO func = new UnixToISO();
+        String iso = func.exec(t1);
+
+        assertTrue(iso.equals("2009-01-07T01:07:01.000Z"));
+    }
+
+    @Test
+    public void testISOToUnix() throws Exception {
+
+        // Verify that ISO string datetimes convert to Unix (long) datetimes
+        Tuple t2 = TupleFactory.getInstance().newTuple(1);
+        t2.set(0, "2009-01-07T01:07:01.000Z");
+        ISOToUnix func2 = new ISOToUnix();
+        Long unix = func2.exec(t2);
+
+        assertTrue(unix == 1231290421000L);
+
+    }
+
+    @Test
+    public void testCustomFormatToISO() throws Exception {
+
+        Tuple t = TupleFactory.getInstance().newTuple(2);
+        t.set(0, "10/10/2010");
+        t.set(1, "dd/MM/yyyy");
+        CustomFormatToISO func = new CustomFormatToISO();
+        String iso = func.exec(t);
+
+        assertTrue(iso.equals("2010-10-10T00:00:00.000Z"));
+    }
+}

Added: hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/diff/TestDiffDateTime.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/diff/TestDiffDateTime.java?rev=929330&view=auto
==============================================================================
--- hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/diff/TestDiffDateTime.java (added)
+++ hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/diff/TestDiffDateTime.java Tue Mar 30 22:53:20 2010
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.piggybank.test.evaluation.datetime.diff;
+
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.datetime.diff.*;
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class TestDiffDateTime {
+    
+    @Test
+    public void testYearDiff() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, "2009-01-07T01:07:01.000Z");
+        t1.set(1, "2002-01-01T00:00:00.000Z");
+
+        ISOYearsBetween func = new ISOYearsBetween();
+        Long years = func.exec(t1);
+
+        System.out.println("Years: " + years.toString());
+
+        Assert.assertTrue(years == 7L);
+    }
+
+    @Test
+    public void testMonthDiff() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, "2009-01-07T00:00:00.000Z");
+        t1.set(1, "2002-01-01T00:00:00.000Z");
+
+        ISOMonthsBetween func = new ISOMonthsBetween();
+        Long months = func.exec(t1);
+
+        System.out.println("Months: " + months.toString());
+
+        Assert.assertTrue(months == 84L);
+    }
+
+    @Test
+    public void testDayDiff() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, "2009-01-07T00:00:00.000Z");
+        t1.set(1, "2002-01-01T00:00:00.000Z");
+
+        ISODaysBetween func = new ISODaysBetween();
+        Long days = func.exec(t1);
+
+        System.out.println("Days: " + days.toString());
+
+        Assert.assertTrue(days == 2563L);
+    }
+
+    @Test
+    public void testMinuteDiff() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, "2009-01-07T00:00:00.000Z");
+        t1.set(1, "2002-01-01T00:00:00.000Z");
+
+        ISOMinutesBetween func = new ISOMinutesBetween();
+        Long mins = func.exec(t1);
+
+        System.out.println("Minutes: " + mins.toString());
+
+        Assert.assertTrue(mins == 3690720L);
+    }
+
+    @Test
+    public void testSecondsDiff() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, "2009-01-07T00:00:00.000Z");
+        t1.set(1, "2002-01-01T00:00:00.000Z");
+
+        ISOSecondsBetween func = new ISOSecondsBetween();
+        Long secs = func.exec(t1);
+
+        System.out.println("Seconds: " + secs.toString());
+
+        Assert.assertTrue(secs == 221443200L);
+    }
+}

Added: hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/truncate/TestTruncateDateTime.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/truncate/TestTruncateDateTime.java?rev=929330&view=auto
==============================================================================
--- hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/truncate/TestTruncateDateTime.java (added)
+++ hadoop/pig/branches/branch-0.7/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/datetime/truncate/TestTruncateDateTime.java Tue Mar 30 22:53:20 2010
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.piggybank.test.evaluation.datetime.truncate;
+
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.datetime.truncate.*;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class TestTruncateDateTime extends TestCase {
+
+    @Test
+    public void testToYear() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToYear func = new ISOToYear();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-01-01T00:00:00.000Z"));
+    }
+
+    @Test
+    public void testToMonth() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToMonth func = new ISOToMonth();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-04-01T00:00:00.000Z"));
+    }
+
+    @Test
+    public void testToWeek() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToWeek func = new ISOToWeek();
+        String truncated = func.exec(t1);
+
+        System.out.println("Truncateed week: " + truncated);
+
+        assertTrue(truncated.equals("2010-04-12T00:00:00.000Z"));
+    }
+
+    @Test
+    public void testToDay() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToDay func = new ISOToDay();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-04-15T00:00:00.000Z"));
+    }
+
+    @Test
+    public void testToHour() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToHour func = new ISOToHour();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-04-15T08:00:00.000Z"));
+    }
+
+    @Test
+    public void testToMinute() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToMinute func = new ISOToMinute();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-04-15T08:11:00.000Z"));
+    }
+
+    @Test
+    public void testToSecond() throws Exception {
+
+        Tuple t1 = TupleFactory.getInstance().newTuple(1);
+        t1.set(0, "2010-04-15T08:11:33.020Z");
+
+        ISOToSecond func = new ISOToSecond();
+        String truncated = func.exec(t1);
+
+        assertTrue(truncated.equals("2010-04-15T08:11:33.000Z"));
+    }
+}
\ No newline at end of file