@Override Datum next() throws IOException { super.next(); if (valuePresent) { long millis = decodeTimestamp(data.next(), nanos.next(), base_timestamp); return DatumFactory.createTimestamp(DateTimeUtil.javaTimeToJulianTime(millis)); } else { return NullDatum.get(); } }
@Override Datum next() throws IOException { super.next(); if (valuePresent) { long millis = decodeTimestamp(data.next(), nanos.next(), base_timestamp); return DatumFactory.createTimestamp(DateTimeUtil.javaTimeToJulianTime(millis)); } else { return NullDatum.get(); } }
@Override public Datum eval(Tuple params) { // cast to UTC timestamp Datum dateDatum = DatumFactory.createTimestamp(params.asDatum(0), getTimeZone()); int val = params.getInt4(1); if (val >= 0) { return dateDatum.plus(new IntervalDatum(val, 0)); } else { return dateDatum.minus(new IntervalDatum(-val, 0)); } } }
@Override public Datum eval(Tuple params) { // cast to UTC timestamp Datum dateDatum = DatumFactory.createTimestamp(params.asDatum(0), getTimeZone()); long val = params.getInt8(1); if (val >= 0) { return dateDatum.plus(new IntervalDatum(val * IntervalDatum.DAY_MILLIS)); } else { return dateDatum.minus(new IntervalDatum(0 - val * IntervalDatum.DAY_MILLIS)); } } }
@Override public Datum eval(Tuple params) { // cast to UTC timestamp Datum dateDatum = DatumFactory.createTimestamp(params.asDatum(0), getTimeZone()); long val = params.getInt8(1); if (val >= 0) { return dateDatum.plus(new IntervalDatum(val * IntervalDatum.DAY_MILLIS)); } else { return dateDatum.minus(new IntervalDatum(0 - val * IntervalDatum.DAY_MILLIS)); } } }
@Override public Datum eval(Tuple params) { // cast to UTC timestamp Datum dateDatum = DatumFactory.createTimestamp(params.asDatum(0), getTimeZone()); int val = params.getInt4(1); if (val >= 0) { return dateDatum.plus(new IntervalDatum(val, 0)); } else { return dateDatum.minus(new IntervalDatum(-val, 0)); } } }
private static Tuple makeRandomTuple(Tuple tuple) { tuple.put(new Datum[]{ DatumFactory.createInt8(random.nextLong()), DatumFactory.createInt4(random.nextInt()), DatumFactory.createInt2((short) random.nextInt(Short.MAX_VALUE)), DatumFactory.createDate(Math.abs(random.nextInt())), DatumFactory.createTimestamp(Math.abs(random.nextLong())), DatumFactory.createTime(Math.abs(random.nextLong())), DatumFactory.createFloat4(random.nextFloat()), DatumFactory.createFloat8(random.nextDouble()) }); for (int i = 0; i < 3; i++) { if (random.nextBoolean()) { tuple.put(i, tuple.asDatum(i).multiply(MINUS_ONE)); } } for (int i = 6; i < 8; i++) { if (random.nextBoolean()) { tuple.put(i, tuple.asDatum(i).multiply(MINUS_ONE)); } } return tuple; }
/** * This method uses the given calendar to construct an appropriate millisecond * value for the time if the underlying database does not store timezone information. */ private Timestamp getTimestamp(Tuple tuple, Calendar cal, int index) throws SQLException { if (handleNull(tuple, index)) return null; TimeMeta tm; TimeZone tz = cal == null ? TimeZone.getDefault() : cal.getTimeZone(); switch (tuple.type(index)) { case DATE: case TIME: tm = tuple.asDatum(index).asTimeMeta(); DateTimeUtil.toUTCTimezone(tm, tz); return toTimestamp(tm, null); case TIMESTAMP: return toTimestamp(tuple.asDatum(index).asTimeMeta(), timezone); case TEXT: tm = DatumFactory.createTimestamp(tuple.asDatum(index), tz).asTimeMeta(); return toTimestamp(tm, null); default: throw new TajoSQLException(Errors.ResultCode.INVALID_VALUE_FOR_CAST, tuple.type(index).name(), "timestamp"); } }
public Datum toDatum(int i) { if (keys[i] == null) { return NullDatum.get(); } switch (keyTypes[i]) { case NULL_TYPE: return NullDatum.get(); case BOOLEAN: return DatumFactory.createBool((Boolean) keys[i]); case BIT: return DatumFactory.createBit((Byte)keys[i]); case INT1: case INT2: return DatumFactory.createInt2((Short) keys[i]); case INT4: return DatumFactory.createInt4((Integer) keys[i]); case DATE: return DatumFactory.createDate((Integer) keys[i]); case INT8: return DatumFactory.createInt8((Long) keys[i]); case TIME: return DatumFactory.createTime((Long) keys[i]); case TIMESTAMP: return DatumFactory.createTimestamp((Long) keys[i]); case FLOAT4: return DatumFactory.createFloat4((Float) keys[i]); case FLOAT8: return DatumFactory.createFloat8((Double) keys[i]); case TEXT: return DatumFactory.createText((byte[]) keys[i]); case CHAR: return DatumFactory.createChar((byte[]) keys[i]); case BLOB: return DatumFactory.createBlob((byte[]) keys[i]); case DATUM: return (Datum)keys[i]; default: throw new IllegalArgumentException(); } } }
public Datum toDatum(int i) { if (keys[i] == null) { return NullDatum.get(); } switch (keyTypes[i]) { case NULL_TYPE: return NullDatum.get(); case BOOLEAN: return DatumFactory.createBool((Boolean) keys[i]); case BIT: return DatumFactory.createBit((Byte)keys[i]); case INT1: case INT2: return DatumFactory.createInt2((Short) keys[i]); case INT4: return DatumFactory.createInt4((Integer) keys[i]); case DATE: return DatumFactory.createDate((Integer) keys[i]); case INET4: return DatumFactory.createInet4((Integer) keys[i]); case INT8: return DatumFactory.createInt8((Long) keys[i]); case TIME: return DatumFactory.createTime((Long) keys[i]); case TIMESTAMP: return DatumFactory.createTimestamp((Long) keys[i]); case FLOAT4: return DatumFactory.createFloat4((Float) keys[i]); case FLOAT8: return DatumFactory.createFloat8((Double) keys[i]); case TEXT: return DatumFactory.createText((byte[]) keys[i]); case CHAR: return DatumFactory.createChar((byte[]) keys[i]); case BLOB: return DatumFactory.createBlob((byte[]) keys[i]); case DATUM: return (Datum)keys[i]; default: throw new IllegalArgumentException(); } } }
return createTime(value); case TIMESTAMP: return createTimestamp(value); case INTERVAL: return createInterval(value);
private static Tuple makeMinTuple(Tuple tuple) { tuple.put(new Datum[]{ DatumFactory.createInt8(Long.MIN_VALUE), DatumFactory.createInt4(Integer.MIN_VALUE), DatumFactory.createInt2(Short.MIN_VALUE), DatumFactory.createDate(0), DatumFactory.createTimestamp(0), DatumFactory.createTime(0), DatumFactory.createFloat4(Float.MIN_VALUE), DatumFactory.createFloat8(Double.MIN_VALUE) }); return tuple; }
private Timestamp getTimestamp(Tuple tuple, int index) throws SQLException { if (handleNull(tuple, index)) return null; TimeMeta tm; switch (tuple.type(index)) { case DATE: case TIME: tm = tuple.asDatum(index).asTimeMeta(); DateTimeUtil.toUTCTimezone(tm, timezone); return toTimestamp(tm, timezone); case TIMESTAMP: return toTimestamp(tuple.asDatum(index).asTimeMeta(), timezone); case TEXT: tm = DatumFactory.createTimestamp(tuple.asDatum(index), timezone).asTimeMeta(); return toTimestamp(tm, timezone); default: throw new TajoSQLException(Errors.ResultCode.INVALID_VALUE_FOR_CAST, tuple.type(index).name(), "timestamp"); } }
return createTime(value); case TIMESTAMP: return createTimestamp(value); case INTERVAL: return createInterval(value);
private static Tuple makeMaxTuple(Tuple tuple) { tuple.put(new Datum[]{ DatumFactory.createInt8(Long.MAX_VALUE), DatumFactory.createInt4(Integer.MAX_VALUE), DatumFactory.createInt2(Short.MAX_VALUE), DatumFactory.createDate(Integer.MAX_VALUE), DatumFactory.createTimestamp( // FIXME 'Out of Range of Time' //DateTimeUtil.toJulianDate(JULIAN_MAXYEAR, 1, 1) DateTimeUtil.toJulianTimestamp(DateTimeConstants.JULIAN_MAXYEAR / 20, 1, 1, 0, 0, 0, 0)), DatumFactory.createTime(Long.MAX_VALUE), DatumFactory.createFloat4(Float.MAX_VALUE), DatumFactory.createFloat8(Double.MAX_VALUE) }); return tuple; }
public static void fillRow(int i, RowWriter builder) { builder.startRow(); builder.putBool(i % 1 == 0 ? true : false); // 0 builder.putInt2((short) 1); // 1 builder.putInt4(i); // 2 builder.putInt8(i); // 3 builder.putFloat4(i); // 4 builder.putFloat8(i); // 5 builder.putText((UNICODE_FIELD_PREFIX + i).getBytes()); // 6 builder.putTimestamp(DatumFactory.createTimestamp("2014-04-16 08:48:00").asInt8() + i); // 7 builder.putDate(DatumFactory.createDate("2014-04-16").asInt4() + i); // 8 builder.putTime(DatumFactory.createTime("08:48:00").asInt8() + i); // 9 builder.putInterval(DatumFactory.createInterval((i + 1) + " hours")); // 10 builder.putProtoDatum(new ProtobufDatum(ProtoUtil.convertString(i + ""))); // 11 builder.endRow(); }
public static void validateTupleResult(int j, Tuple t) { assertTrue((j % 1 == 0) == t.getBool(0)); assertTrue(1 == t.getInt2(1)); assertEquals(j, t.getInt4(2)); assertEquals(j, t.getInt8(3)); assertTrue(j == t.getFloat4(4)); assertTrue(j == t.getFloat8(5)); assertEquals(new String(UNICODE_FIELD_PREFIX + j), t.getText(6)); assertEquals(DatumFactory.createTimestamp("2014-04-16 08:48:00").asInt8() + (long) j, t.getInt8(7)); assertEquals(DatumFactory.createDate("2014-04-16").asInt4() + j, t.getInt4(8)); assertEquals(DatumFactory.createTime("08:48:00").asInt8() + j, t.getInt8(9)); assertEquals(DatumFactory.createInterval((j + 1) + " hours"), t.getInterval(10)); assertEquals(new ProtobufDatum(ProtoUtil.convertString(j + "")), t.getProtobufDatum(11)); }
return DatumFactory.createBlob(getBytes(fieldId)); case TIMESTAMP: return DatumFactory.createTimestamp(getInt8(fieldId)); case DATE: return DatumFactory.createDate(getInt4(fieldId));
return DatumFactory.createBlob(getBytes(fieldId)); case TIMESTAMP: return DatumFactory.createTimestamp(getInt8(fieldId)); case DATE: return DatumFactory.createDate(getInt4(fieldId));
return DatumFactory.createBlob(getBytes(fieldId)); case TIMESTAMP: return DatumFactory.createTimestamp(getInt8(fieldId)); case DATE: return DatumFactory.createDate(getInt4(fieldId));