RecordSerializer { public static Object convert(int type, Object value) throws StatementExecutionException { if (value == null && ColumnTypes.isNotNullDataType(type)) { throw new StatementExecutionException("Cannot have null value in non-NULL type " + ColumnTypes.sqlDataType(type)); } switch (type) { case ColumnTypes.TIMESTAMP: case ColumnTypes.NOTNULL_TIMESTAMP: if ((value instanceof java.sql.Timestamp)) { return value; } else if (value instanceof RawString || value instanceof String) { try { String asString = value.toString(); ZonedDateTime dateTime; try { dateTime = ZonedDateTime.parse(asString, TIMESTAMP_FORMATTER); } catch (DateTimeParseException tryAgain) { try { dateTime = ZonedDateTime.parse(asString, TIMESTAMP_FORMATTER_WITH_MILLIS); } catch (DateTimeParseException again) { dateTime = LocalDate.parse(asString, TIMESTAMP_FORMATTER_ONLY_DATE).atStartOfDay(UTC); } } Instant toInstant = dateTime.toInstant(); long millis = (toInstant.toEpochMilli()); Timestamp timestamp = new java.sql.Timestamp(millis); if (timestamp.getTime() != millis) { throw new StatementExecutionException("Unparsable timestamp " + value + " would been converted as java.sql.Timestamp to " + new java.sql.Timestamp(millis)); } return timestamp; } catch (DateTimeParseException err) { throw new StatementExecutionException("Unparsable timestamp " + value, err); } } case ColumnTypes.BYTEARRAY: case ColumnTypes.NOTNULL_BYTEARRAY: if (value instanceof RawString) { return ((RawString) value).toByteArray(); } return value; default: return value; } } private  RecordSerializer(); static Object deserialize(Bytes data, int type); static Object deserialize(byte[] data, int type); static int deserializeCompare(byte[] data, int type, Object cvalue); static SQLRecordPredicateFunctions.CompareResult deserializeCompare(Bytes data, int type, Object cvalue); static Object deserializeTypeAndValue(ByteArrayCursor dii); static SQLRecordPredicateFunctions.CompareResult compareDeserializeTypeAndValue(ByteArrayCursor dii, Object cvalue); static void skipTypeAndValue(ByteArrayCursor dii); static byte[] serialize(Object v, int type); static void serializeTo(Object v, int type, ExtendedDataOutputStream out); static void validate(Object v, int type); static void serializeTypeAndValue(Object v, int type, ExtendedDataOutputStream oo); static void serializeValue(Object v, int type, ExtendedDataOutputStream oo); static DateTimeFormatter getUTCTimestampFormatter(); static Object convert(int type, Object value); static DataAccessor buildRawDataAccessor(Record record, Table table); static DataAccessor buildRawDataAccessorForPrimaryKey(Bytes key, Table table); static Record makeRecord(Table table, Object... values); static Bytes serializePrimaryKey(Map<String, Object> record, ColumnsList table, String[] columns); static byte[] serializePrimaryKeyRaw(Map<String, Object> record, ColumnsList table, String[] columns); static Bytes serializeIndexKey(DataAccessor record, ColumnsList index, String[] columns); static void validateIndexableValue(DataAccessor record, ColumnsList indexDefinition, String[] columns); static Object deserializePrimaryKey(Bytes key, Table table); static Map<String, Object> deserializePrimaryKeyAsMap(Bytes key, Table table); static Bytes serializeValue(Map<String, Object> record, Table table); static byte[] serializeValueRaw(Map<String, Object> record, Table table, int expectedSize); static byte[] buildRecord(
            int expectedSize, Table table,
            Function<String, Object> evaluator
    ); static Record toRecord(Map<String, Object> record, Table table); @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") static Map<String, Object> toBean(Record record, Table table);  }
@Test public void testConvert() { testTimestamp("2015-03-29 01:00:00", "UTC", 1427590800000L); testTimestamp("2015-03-29 02:00:00", "UTC", 1427594400000L); testTimestamp("2015-03-29 03:00:00", "UTC", 1427598000000L); }