Search in sources :

Example 16 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo04.

@Test
public void testDeserializationWithTypeInfo04() throws Exception {
    Instant now = Instant.now();
    OffsetDateTime expected = OffsetDateTime.ofInstant(now, UTC);
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(now, ZoneOffset.UTC);
    Temporal actual = m.readValue("[\"" + OffsetDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 17 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo04NonUTCOffset.

@Test
public void testDeserializationWithTypeInfo04NonUTCOffset() throws Exception {
    Instant now = Instant.now();
    OffsetDateTime expected = OffsetDateTime.ofInstant(now, Z1);
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(now, expected.getOffset());
    Temporal actual = m.readValue("[\"" + OffsetDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 18 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationAsIonTimestamp04UnknownOffsetNonUTCDefault.

@Test
public void testDeserializationAsIonTimestamp04UnknownOffsetNonUTCDefault() throws Exception {
    OffsetDateTime expected = OffsetDateTime.now(Z1);
    Timestamp timestamp = TimestampUtils.toTimestamp(expected.toInstant(), null);
    OffsetDateTime actual = READER_Z1_DEFAULT.readValue(timestamp.toString());
    assertEquals("The value is not correct.", expected, actual);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Timestamp(com.amazon.ion.Timestamp) Test(org.junit.Test)

Example 19 with Timestamp

use of com.amazon.ion.Timestamp in project ion-hive-serde by amzn.

the class TimestampSerializer method serialize.

@Override
public void serialize(final IonWriter writer, final Object data, final ObjectInspector objectInspector) throws IOException {
    final PrimitiveCategory category = ((PrimitiveObjectInspector) objectInspector).getPrimitiveCategory();
    switch(category) {
        case DATE:
            final Date date = ((DateObjectInspector) objectInspector).getPrimitiveJavaObject(data);
            writer.writeTimestamp(Timestamp.forDateZ(date));
            break;
        case TIMESTAMP:
            final java.sql.Timestamp hiveTimestamp = ((TimestampObjectInspector) objectInspector).getPrimitiveJavaObject(data);
            final Timestamp value = Timestamp.forSqlTimestampZ(hiveTimestamp);
            final Timestamp timestampWithOffset = value.withLocalOffset(offsetInMinutes);
            writer.writeTimestamp(timestampWithOffset);
            break;
        default:
            throw new IllegalArgumentException("Invalid object category for timestamp serializer: " + category);
    }
}
Also used : DateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector) TimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) Timestamp(com.amazon.ion.Timestamp) Date(java.sql.Date)

Example 20 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationAsIonTimestamp02.

@Test
public void testDeserializationAsIonTimestamp02() throws Exception {
    ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), UTC);
    Timestamp timestamp = TimestampUtils.toTimestamp(expected.toInstant(), expected.getOffset());
    ZonedDateTime actual = READER_UTC_DEFAULT.readValue(timestamp.toString());
    assertEquals("The value is not correct.", expected, actual);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Timestamp(com.amazon.ion.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.amazon.ion.Timestamp)51 Test (org.junit.Test)38 Instant (java.time.Instant)13 OffsetDateTime (java.time.OffsetDateTime)10 ZonedDateTime (java.time.ZonedDateTime)10 IonReader (com.amazon.ion.IonReader)8 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)8 RepeatInputStream (com.amazon.ion.util.RepeatInputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)7 SequenceInputStream (java.io.SequenceInputStream)7 BigInteger (java.math.BigInteger)7 IonTimestamp (com.amazon.ion.IonTimestamp)6 BigDecimal (java.math.BigDecimal)5 Temporal (java.time.temporal.Temporal)5 Decimal (com.amazon.ion.Decimal)2 IonException (com.amazon.ion.IonException)2 IonWriter (com.amazon.ion.IonWriter)2 IonBlob (com.amazon.ion.IonBlob)1