Search in sources :

Example 31 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TestDateWritableV2 method testConstructor.

@Test
@Concurrent(count = 4)
@Repeating(repetition = 100)
public void testConstructor() {
    Date date = Date.valueOf(getRandomDateString());
    DateWritableV2 dw1 = new DateWritableV2(date);
    DateWritableV2 dw2 = new DateWritableV2(dw1);
    DateWritableV2 dw3 = new DateWritableV2(dw1.getDays());
    assertEquals(dw1, dw1);
    assertEquals(dw1, dw2);
    assertEquals(dw2, dw3);
    assertEquals(date, dw1.get());
    assertEquals(date, dw2.get());
    assertEquals(date, dw3.get());
}
Also used : Date(org.apache.hadoop.hive.common.type.Date) Test(org.junit.Test) Repeating(com.google.code.tempusfugit.concurrency.annotations.Repeating) Concurrent(com.google.code.tempusfugit.concurrency.annotations.Concurrent)

Example 32 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TestDateWritableV2 method testComparison.

@Test
@Concurrent(count = 4)
@Repeating(repetition = 100)
public void testComparison() {
    // Get 2 different dates
    Date date1 = Date.valueOf(getRandomDateString());
    Date date2 = Date.valueOf(getRandomDateString());
    while (date1.equals(date2)) {
        date2 = Date.valueOf(getRandomDateString());
    }
    DateWritableV2 dw1 = new DateWritableV2(date1);
    DateWritableV2 dw2 = new DateWritableV2(date2);
    DateWritableV2 dw3 = new DateWritableV2(date1);
    assertTrue("Dates should be equal", dw1.equals(dw1));
    assertTrue("Dates should be equal", dw1.equals(dw3));
    assertTrue("Dates should be equal", dw3.equals(dw1));
    assertEquals("Dates should be equal", 0, dw1.compareTo(dw1));
    assertEquals("Dates should be equal", 0, dw1.compareTo(dw3));
    assertEquals("Dates should be equal", 0, dw3.compareTo(dw1));
    assertFalse("Dates not should be equal", dw1.equals(dw2));
    assertFalse("Dates not should be equal", dw2.equals(dw1));
    assertTrue("Dates not should be equal", 0 != dw1.compareTo(dw2));
    assertTrue("Dates not should be equal", 0 != dw2.compareTo(dw1));
}
Also used : Date(org.apache.hadoop.hive.common.type.Date) Test(org.junit.Test) Repeating(com.google.code.tempusfugit.concurrency.annotations.Repeating) Concurrent(com.google.code.tempusfugit.concurrency.annotations.Concurrent)

Example 33 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TestDateWritableV2 method testDateValueOf.

@Test
@Concurrent(count = 4)
@Repeating(repetition = 100)
public void testDateValueOf() {
    // Just making sure Date.valueOf() works ok
    String dateStr = getRandomDateString();
    Date date = Date.valueOf(dateStr);
    assertEquals(dateStr, date.toString());
}
Also used : Date(org.apache.hadoop.hive.common.type.Date) Test(org.junit.Test) Repeating(com.google.code.tempusfugit.concurrency.annotations.Repeating) Concurrent(com.google.code.tempusfugit.concurrency.annotations.Concurrent)

Example 34 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TestValueBoundaryScanner method testDateEquals.

@Test
public void testDateEquals() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableDateObjectInspector);
    DateValueBoundaryScanner scanner = new DateValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    Date date = new Date();
    // epoch+1 day
    date.setTimeInMillis(86400000);
    DateWritableV2 w1 = new DateWritableV2(date);
    DateWritableV2 w2 = new DateWritableV2(date);
    // empty
    DateWritableV2 w3 = new DateWritableV2();
    Assert.assertTrue(scanner.isEqual(w1, w2));
    Assert.assertTrue(scanner.isEqual(w2, w1));
    // empty == epoch
    Assert.assertTrue(scanner.isEqual(w3, new DateWritableV2(new Date())));
    // empty != another non-epoch
    Assert.assertFalse(scanner.isEqual(w3, w1));
    Assert.assertFalse(scanner.isEqual(null, w2));
    Assert.assertFalse(scanner.isEqual(w1, null));
    Assert.assertTrue(scanner.isEqual(null, null));
}
Also used : DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Date(org.apache.hadoop.hive.common.type.Date) Test(org.junit.Test)

Example 35 with Date

use of org.apache.hadoop.hive.common.type.Date in project hive by apache.

the class TestGenericUDFToUnixTimestamp method testDate.

@Test
public void testDate() throws HiveException {
    GenericUDFToUnixTimeStamp udf = new GenericUDFToUnixTimeStamp();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    Date date = Date.valueOf("1970-01-01");
    TimestampTZ tstz = TimestampTZUtil.convert(date, ZoneId.systemDefault());
    runAndVerify(udf, new DateWritableV2(date), new LongWritable(tstz.getEpochSecond()));
    // test null values
    runAndVerify(udf, null, null);
}
Also used : TimestampTZ(org.apache.hadoop.hive.common.type.TimestampTZ) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) LongWritable(org.apache.hadoop.io.LongWritable) Date(org.apache.hadoop.hive.common.type.Date) Test(org.junit.Test)

Aggregations

Date (org.apache.hadoop.hive.common.type.Date)71 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)26 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)21 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)18 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)18 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)17 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)15 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)14 Text (org.apache.hadoop.io.Text)14 Test (org.junit.Test)14 HiveIntervalYearMonth (org.apache.hadoop.hive.common.type.HiveIntervalYearMonth)13 BytesWritable (org.apache.hadoop.io.BytesWritable)12 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)11 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)11 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)11 List (java.util.List)10 LongWritable (org.apache.hadoop.io.LongWritable)10 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)9 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)9 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)9