public DoubleWritable evaluate(TimestampWritableV2 i) { if (i == null) { return null; } else { try { doubleWritable.set(i.getDouble()); return doubleWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // But we decided to return NULL instead, which is more conservative. return null; } } }
public FloatWritable evaluate(TimestampWritableV2 i) { if (i == null) { return null; } else { try { floatWritable.set((float) i.getDouble()); return floatWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // But we decided to return NULL instead, which is more conservative. return null; } } }
private VectorizedRowBatch getBatchDecimalTimestamp(double[] doubleValues) { VectorizedRowBatch b = new VectorizedRowBatch(2); DecimalColumnVector dv; b.cols[0] = dv = new DecimalColumnVector(doubleValues.length, HiveDecimal.SYSTEM_DEFAULT_PRECISION, HiveDecimal.SYSTEM_DEFAULT_SCALE); b.cols[1] = new TimestampColumnVector(doubleValues.length); dv.noNulls = true; Random r = new Random(94830); for (int i = 0; i < doubleValues.length; i++) { long millis = RandomTypeUtil.randomMillis(r); Timestamp ts = new Timestamp(millis); int nanos = RandomTypeUtil.randomNanos(r); ts.setNanos(nanos); TimestampWritableV2 tsw = new TimestampWritableV2( org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(ts.getTime(), ts.getNanos())); double asDouble = tsw.getDouble(); doubleValues[i] = asDouble; HiveDecimal hiveDecimal = HiveDecimal.create(new BigDecimal(asDouble)); dv.set(i, hiveDecimal); } b.size = doubleValues.length; return b; }
break; case TIMESTAMP: result = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o).getDouble(); break; case DECIMAL:
case TIMESTAMP: Double ts = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o) .getDouble(); result = HiveDecimal.create(ts.toString()); break;
break; case TIMESTAMP: result = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o).getDouble(); break; case DECIMAL:
case TIMESTAMP: Double ts = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o) .getDouble(); result = HiveDecimal.create(ts.toString()); break;