@Override protected Object parseDate(Long value, boolean richDate) { return (richDate ? new TimestampWritable(new Timestamp(value)) : processLong(value)); }
public TimestampWritable evaluate(TimestampWritable t) { if (t == null) { return null; } final long originalTimestamp = t.getTimestamp().getTime(); // default final long originalTimestampUTC = new DateTime(originalTimestamp) .withZoneRetainFields(DateTimeZone.UTC).getMillis(); // default -> utc final long newTimestampUTC = granularity.truncate(originalTimestampUTC); // utc final long newTimestamp = new DateTime(newTimestampUTC, DateTimeZone.UTC) .withZoneRetainFields(DateTimeZone.getDefault()).getMillis(); // utc -> default result.setTime(newTimestamp); return result; }
/** * * @return double representation of the timestamp, accurate to nanoseconds */ public double getDouble() { double seconds, nanos; if (bytesEmpty) { seconds = TimestampUtils.millisToSeconds(timestamp.getTime()); nanos = timestamp.getNanos(); } else { seconds = getSeconds(); nanos = getNanos(); } return seconds + nanos / 1000000000; }
@Override public int hashCode() { long seconds = getSeconds(); seconds <<= 30; // the nanosecond part fits in 30 bits seconds |= getNanos(); return (int) ((seconds >>> 32) ^ seconds); }
public void set(TimestampWritable t) { if (t.bytesEmpty) { set(t.getTimestamp()); return; } if (t.currentBytes == t.externalBytes) { set(t.currentBytes, t.offset); } else { set(t.currentBytes, 0); } }
/** * @return byte[] representation of TimestampWritable that is binary * sortable (7 bytes for seconds, 4 bytes for nanoseconds) */ public byte[] getBinarySortable() { byte[] b = new byte[BINARY_SORTABLE_LENGTH]; int nanos = getNanos(); // We flip the highest-order bit of the seven-byte representation of seconds to make negative // values come before positive ones. long seconds = getSeconds() ^ SEVEN_BYTE_LONG_SIGN_FLIP; sevenByteLongToBytes(seconds, b, 0); intToBytes(nanos, b, 7); return b; }
return new ShortWritable((short) 0); case INT: return new IntWritable(0); case LONG: return new LongWritable(0); case TIMESTAMP: return new TimestampWritable(new Timestamp(0)); case DATE: return new DateWritable(new Date(0)); case FLOAT: return new FloatWritable(0); return new DoubleWritable(0); case BINARY: return new BytesWritable(ArrayUtils.EMPTY_BYTE_ARRAY); case STRING: return new Text(ArrayUtils.EMPTY_BYTE_ARRAY); case VARCHAR: return new HiveVarcharWritable(new HiveVarchar(StringUtils.EMPTY, -1)); case CHAR: return new HiveCharWritable(new HiveChar(StringUtils.EMPTY, -1)); case DECIMAL: return new HiveDecimalWritable(); case INTERVAL_YEAR_MONTH: return new HiveIntervalYearMonthWritable();
return null; Text t = new Text(); if (inputOI.preferWritable()) { .getStrippedValue()); .toString()); t.set(((DateObjectInspector) inputOI).getPrimitiveWritableObject(input).toString()); return t; .getPrimitiveWritableObject(input).toString()); return t; case BINARY: if (binaryOI.preferWritable()) { BytesWritable bytes = binaryOI.getPrimitiveWritableObject(input); t.set(bytes.getBytes(), 0, bytes.getLength()); t.set(((HiveDecimalObjectInspector) inputOI).getPrimitiveWritableObject(input).toString()); return t; default:
case BOOLEAN: longValue = ((BooleanObjectInspector) inputOI).get(o) ? 1 : 0; result = TimestampWritable.longToTimestamp(longValue, intToTimestampInSeconds); break; case BYTE: longValue = ((ByteObjectInspector) inputOI).get(o); result = TimestampWritable.longToTimestamp(longValue, intToTimestampInSeconds); break; case SHORT: longValue = ((ShortObjectInspector) inputOI).get(o); result = TimestampWritable.longToTimestamp(longValue, intToTimestampInSeconds); break; case INT: longValue = ((IntObjectInspector) inputOI).get(o); result = TimestampWritable.longToTimestamp(longValue, intToTimestampInSeconds); break; case LONG: longValue = ((LongObjectInspector) inputOI).get(o); result = TimestampWritable.longToTimestamp(longValue, intToTimestampInSeconds); break; case FLOAT: result = TimestampWritable.doubleToTimestamp(((FloatObjectInspector) inputOI).get(o)); break; case DOUBLE: result = TimestampWritable.doubleToTimestamp(((DoubleObjectInspector) inputOI).get(o)); break; case DECIMAL: result = TimestampWritable.decimalToTimestamp(((HiveDecimalObjectInspector) inputOI) .getPrimitiveJavaObject(o));
Timestamp inputTs = ((TimestampWritable) converted_o0).getTimestamp(); String tzStr = textConverter.convert(o1).toString(); TimeZone timezone = TimeZone.getTimeZone(tzStr); Timestamp fromTs = timestampFromString(inputTs.toString(), fromTz); if (fromTs == null) { return null; Timestamp result = Timestamp.valueOf(dateFormat.format(fromTs)); if (inputTs.getNanos() != 0) { result.setNanos(inputTs.getNanos());
case INT: ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = ((IntWritable) object).get(); break; case LONG: case TIMESTAMP: ((TimestampColumnVector) batch.cols[projectionColumnNum]).set( batchIndex, ((TimestampWritable) object).getTimestamp()); break; case DATE: ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = ((DateWritable) object).getDays(); break; case FLOAT: batchIndex, bw.getBytes(), 0, bw.getLength()); batchIndex, tw.getBytes(), 0, tw.getLength()); hiveVarchar = (HiveVarchar) object; } else { hiveVarchar = ((HiveVarcharWritable) object).getHiveVarchar(); hiveChar = (HiveChar) object; } else { hiveChar = ((HiveCharWritable) object).getHiveChar();
private Object fromWritable(Writable writable, Schema schema) { if (writable instanceof IntWritable) { return ((IntWritable) writable).get(); } else if (writable instanceof LongWritable) { return ((LongWritable) writable).get(); return writable.toString(); } else if (writable instanceof BytesWritable) { return ((BytesWritable) writable).getBytes(); } else if (writable instanceof ByteWritable) { return ((ByteWritable) writable).get(); } else if (writable instanceof DateWritable) { return ((DateWritable) writable).get().toLocalDate().toEpochDay(); } else if (writable instanceof org.apache.hadoop.hive.serde2.io.ShortWritable) { return ((org.apache.hadoop.hive.serde2.io.ShortWritable) writable).get(); } else if (writable instanceof HiveBaseCharWritable) { return ((HiveBaseCharWritable) writable).getTextValue().toString(); } else if (writable instanceof TimestampWritable) { return toEpochTimestamp(((TimestampWritable) writable).getTimestamp(), schema); } else if (writable instanceof org.apache.hadoop.hive.serde2.io.DoubleWritable) { return ((org.apache.hadoop.hive.serde2.io.DoubleWritable) writable).get(); } else if (writable instanceof HiveDecimalWritable) { return ((HiveDecimalWritable) writable).getHiveDecimal(); } else if (writable instanceof NullWritable) { return null;
public static Datum convertWritable2Datum(Writable value) throws UnsupportedDataTypeException { if (value == null) { return NullDatum.get(); } DataType type = convertWritableToTajoType(value.getClass()); switch(type.getType()) { case INT1: return new Int2Datum(((ByteWritable)value).get()); case INT2: return new Int2Datum(((ShortWritable)value).get()); case INT4: return new Int4Datum(((IntWritable)value).get()); case INT8: return new Int8Datum(((LongWritable)value).get()); case FLOAT4: return new Float4Datum(((FloatWritable)value).get()); case FLOAT8: return new Float8Datum(((DoubleWritable)value).get()); case DATE: return new DateDatum(((DateWritable)value).getDays() + DateTimeConstants.UNIX_EPOCH_JDATE); case TIMESTAMP: return new TimestampDatum(DateTimeUtil.javaTimeToJulianTime( ((TimestampWritable)value).getTimestamp().getTime())); case CHAR: return new CharDatum(value.toString()); case TEXT: return new TextDatum(value.toString()); case VARBINARY: return new BlobDatum(((BytesWritable)value).getBytes()); } throw new TajoRuntimeException(new UnsupportedDataTypeException(value.getClass().getTypeName())); } }
toBeAdded = ((ShortWritable) daysWritableObject).get(); } else if (daysWritableObject instanceof IntWritable) { toBeAdded = ((IntWritable) daysWritableObject).get(); } else { return null; String dateString = dateConverter.convert(arguments[0].get()).toString(); if (dateParser.parseDate(dateString, dateVal)) { output.set(dateVal); } else { return null; case TIMESTAMP: Timestamp ts = ((TimestampWritable) dateConverter.convert(arguments[0].get())) .getTimestamp(); output.set(DateWritable.millisToDays(ts.getTime())); break; case DATE:
private Object parseAsPrimitive(JsonNode value, TypeInfo typeInfo) throws SerDeException { switch (TypeInfoFactory.getPrimitiveTypeInfo(typeInfo.getTypeName()).getPrimitiveCategory()) { case TIMESTAMP: TimestampWritable timestampWritable = new TimestampWritable(); timestampWritable.setTime(TS_PARSER.get().parseMillis(value.textValue())); return timestampWritable; return (new ShortWritable(value.shortValue())); case INT: return new IntWritable(value.intValue()); case LONG: return (new LongWritable((value.longValue()))); return (new DoubleWritable(value.doubleValue())); case DECIMAL: return (new HiveDecimalWritable(HiveDecimal.create(value.decimalValue()))); case CHAR: return (new HiveCharWritable(new HiveChar(value.textValue(), ((CharTypeInfo) typeInfo).getLength()))); case VARCHAR: return (new HiveVarcharWritable(new HiveVarchar(value.textValue(), ((CharTypeInfo) typeInfo).getLength()))); case STRING: return (new Text(value.textValue())); case BOOLEAN: return (new BooleanWritable(value.isBoolean() ? value.booleanValue() : Boolean.valueOf(value.textValue())));
actualValue = new SqlVarbinary(((BytesWritable) actualValue).copyBytes()); actualValue = new SqlDate(((DateWritable) actualValue).getDays()); actualValue = ((IntWritable) actualValue).get(); actualValue = ((HiveCharWritable) actualValue).getPaddedValue().toString(); HiveDecimalWritable writable = (HiveDecimalWritable) actualValue; BigInteger rescaledValue = rescale(writable.getHiveDecimal().unscaledValue(), writable.getScale(), decimalType.getScale()); actualValue = new SqlDecimal(rescaledValue, decimalType.getPrecision(), decimalType.getScale()); actualValue = sqlTimestampOf((timestamp.getSeconds() * 1000) + (timestamp.getNanos() / 1000000L), SESSION);
/** * * @return seconds corresponding to this TimestampWritable */ public long getSeconds() { if (!timestampEmpty) { return TimestampUtils.millisToSeconds(timestamp.getTime()); } else if (!bytesEmpty) { return TimestampWritable.getSeconds(currentBytes, offset); } else { throw new IllegalStateException("Both timestamp and bytes are empty"); } }
public static Writable convertDatum2Writable(Datum value) { switch(value.kind()) { case INT1: return new ByteWritable(value.asByte()); case INT2: return new ShortWritable(value.asInt2()); case INT4: return new IntWritable(value.asInt4()); case INT8: return new LongWritable(value.asInt8()); case FLOAT4: return new FloatWritable(value.asFloat4()); case FLOAT8: return new DoubleWritable(value.asFloat8()); // NOTE: value should be DateDatum case DATE: return new DateWritable(value.asInt4() - DateTimeConstants.UNIX_EPOCH_JDATE); // NOTE: value should be TimestampDatum case TIMESTAMP: TimestampWritable result = new TimestampWritable(); result.setTime(DateTimeUtil.julianTimeToJavaTime(value.asInt8())); return result; case CHAR: { String str = value.asChars(); return new HiveCharWritable(new HiveChar(str, str.length())); } case TEXT: return new Text(value.asChars()); case VARBINARY: return new BytesWritable(value.asByteArray()); case NULL_TYPE: return null; } throw new TajoRuntimeException(new NotImplementedException(TypeStringEncoder.encode(value.type()))); }
String dateString = textConverter.convert(arguments[0].get()).toString(); if (dateParser.parseDate(dateString, date)) { output.set(date); } else { return null; case TIMESTAMP: Timestamp ts = ((TimestampWritable) timestampConverter.convert(arguments[0].get())) .getTimestamp(); output.set(DateWritable.millisToDays(ts.getTime())); break; case DATE:
case TIMESTAMP: Timestamp ts = ((TimestampWritable) converter.convert(argument.get())) .getTimestamp(); date.setTime(ts.getTime()); break; case DATE: DateWritable dw = (DateWritable) converter.convert(argument.get()); date = dw.get(); break; default: