diff --git serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyDate.java serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyDate.java index 8492522..7af2374 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyDate.java +++ serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyDate.java @@ -62,6 +62,7 @@ public void init(ByteArrayRef bytes, int start, int length) { try { s = Text.decode(bytes.getData(), start, length); data.set(Date.valueOf(s)); + isNull = false; } catch (Exception e) { isNull = true; logExceptionMessage(bytes, start, length, "DATE"); diff --git serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java index 3cb10af..868dd4c 100644 --- serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java +++ serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.hive.serde2.lazy; +import java.sql.Date; import java.sql.Timestamp; import junit.framework.TestCase; @@ -408,6 +409,25 @@ public void testLazyTimestamp() throws Throwable { assertEquals(true, t.isNull); } + public void testLazyDate() throws Throwable { + LazyDate t = new LazyDate(LazyPrimitiveObjectInspectorFactory.LAZY_DATE_OBJECT_INSPECTOR); + String nullDate = "NULL"; + byte[] nullBytes = nullDate.getBytes(); + initLazyObject(t, nullBytes, 0, nullBytes.length); + assertEquals(true, t.isNull); + String sampleDate = "2013-02-12"; + byte[] good2013 = sampleDate.getBytes(); + initLazyObject(t, good2013, 0, good2013.length); + assertEquals(false, t.isNull); + assertEquals(Date.valueOf(sampleDate), + t.getWritableObject().get()); + String badDate = "X013-02-12"; + byte[] bad2013 = badDate.getBytes(); + initLazyObject(t, bad2013, 0, bad2013.length); + assertEquals(true, t.isNull); + + } + public void testLazyIntegerWrite() throws Throwable { try { ByteStream.Output out = new ByteStream.Output();