public Timestamp getPrimitiveJavaObject(Object o) { return o == null ? null : ((TimestampWritableV2) o).getTimestamp(); }
public Object set(Object o, TimestampWritableV2 tw) { if (tw == null) { return null; } Timestamp t = (Timestamp) o; t.set(tw.getTimestamp()); return t; }
public Timestamp getPrimitiveJavaObject(Object o) { return o == null ? null : ((LazyTimestamp) o).getWritableObject().getTimestamp(); }
public IntWritable evaluate(TimestampWritableV2 t) { if (t == null) { return null; } Timestamp ts = t.getTimestamp(); calendar.setTimeInMillis(ts.toEpochMilli()); result.set(calendar.get(Calendar.WEEK_OF_YEAR)); return result; }
protected void assignTimestamp(TimestampWritableV2 tw, int index) { outCol.set(index, tw.getTimestamp().toSqlTimestamp()); } }
public IntWritable evaluate(TimestampWritableV2 t) { if (t == null) { return null; } result.set(t.getTimestamp().getDayOfWeek()); return result; }
protected Timestamp getTimestampValue(DeferredObject[] arguments, int i, Converter[] converters) throws HiveException { Object obj; if ((obj = arguments[i].get()) == null) { return null; } Object writableValue = converters[i].convert(obj); // if string can not be parsed converter will return null if (writableValue == null) { return null; } Timestamp ts = ((TimestampWritableV2) writableValue).getTimestamp(); return ts; }
public void set(TimestampWritableV2 t) { if (t.bytesEmpty) { set(t.getTimestamp()); return; } if (t.currentBytes == t.externalBytes) { set(t.currentBytes, t.offset); } else { set(t.currentBytes, 0); } }
public TimestampWritableV2 evaluate(TimestampWritableV2 t) { if (t == null) { return null; } final long originalTimestamp = t.getTimestamp().toEpochMilli(); final long newTimestamp = granularity.truncate(originalTimestamp); resultTS.set(Timestamp.ofEpochMilli(newTimestamp)); return resultTS; }
private void compareToUDFUnixTimeStampDate(long t, long y) { TimestampWritableV2 tsw = toTimestampWritable(t); LongWritable res = getLongWritable(tsw); if(res.get() != y) { System.out.printf("%d vs %d for %d, %d\n", res.get(), y, t, tsw.getTimestamp().toEpochMilli()/1000); } Assert.assertEquals(res.get(), y); }
case TIMESTAMP: Timestamp ts = ((TimestampWritableV2) timestampConverter.convert(arguments[0].get())) .getTimestamp(); output.set(DateWritableV2.millisToDays(ts.toEpochMilli())); break;
@Test public void testIntervalYearMonthPlusTimestamp() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2")); TimestampWritableV2 right = new TimestampWritableV2(Timestamp.valueOf("2001-11-15 01:02:03.123456789")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp()); }
@Test public void testTimestampPlusIntervalYearMonth() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); TimestampWritableV2 left = new TimestampWritableV2(Timestamp.valueOf("2001-11-15 01:02:03.123456789")); HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp()); }
@Test public void testTimestampMinusIntervalDayTime() throws Exception { GenericUDFOPMinus udf = new GenericUDFOPMinus(); TimestampWritableV2 left = new TimestampWritableV2(Timestamp.valueOf("2001-01-02 2:3:4.567")); HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-01-01 00:00:00"), res.getTimestamp()); }
@Test public void testIntervalDayTimePlusTimestamp() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); HiveIntervalDayTimeWritable left = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567")); TimestampWritableV2 right = new TimestampWritableV2(Timestamp.valueOf("2001-01-01 00:00:00")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp()); }
@Test public void testTimestampPlusIntervalDayTime() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); TimestampWritableV2 left = new TimestampWritableV2(Timestamp.valueOf("2001-01-01 00:00:00")); HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp()); }
@Test public void testDateMinusIntervalDayTime() throws Exception { GenericUDFOPMinus udf = new GenericUDFOPMinus(); DateWritableV2 left = new DateWritableV2(Date.valueOf("2001-01-01")); HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 0:0:0.555")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2000-12-30 23:59:59.445"), res.getTimestamp()); } }
@Test public void testTimestampMinusIntervalYearMonth() throws Exception { GenericUDFOPMinus udf = new GenericUDFOPMinus(); TimestampWritableV2 left = new TimestampWritableV2(Timestamp.valueOf("2004-01-15 01:02:03.123456789")); HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-11-15 01:02:03.123456789"), res.getTimestamp()); }
@Test public void testDatePlusIntervalDayTime() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); DateWritableV2 left = new DateWritableV2(Date.valueOf("2001-01-01")); HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; // Date + day-time interval = timestamp PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp()); } }
@Test public void testIntervalDayTimePlusDate() throws Exception { GenericUDFOPPlus udf = new GenericUDFOPPlus(); HiveIntervalDayTimeWritable left = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567")); DateWritableV2 right = new DateWritableV2(Date.valueOf("2001-01-01")); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector }; DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right), }; // Date + day-time interval = timestamp PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args); Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp()); }