diff --git a/partiql-spi/src/main/java/org/partiql/spi/stream/PSink.java b/partiql-spi/src/main/java/org/partiql/spi/stream/PSink.java index 495a0a482..95665bcf9 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/stream/PSink.java +++ b/partiql-spi/src/main/java/org/partiql/spi/stream/PSink.java @@ -2,11 +2,13 @@ import org.jetbrains.annotations.NotNull; import org.partiql.types.PType; -import org.partiql.value.datetime.Date; -import org.partiql.value.datetime.Time; -import org.partiql.value.datetime.Timestamp; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; /** * This is a PartiQL value stream sink. @@ -115,27 +117,27 @@ default void flush() { /** * Write DATE value. */ - void writeDate(@NotNull Date value); + void writeDate(@NotNull LocalDate value); /** * Write TIME value. */ - void writeTime(@NotNull Time value); + void writeTime(@NotNull LocalTime value); /** * Write TIMEZ value. */ - void writeTimez(@NotNull Time value); + void writeTimez(@NotNull OffsetTime value); /** * Write TIMESTAMP value. */ - void writeTimestamp(@NotNull Timestamp value); + void writeTimestamp(@NotNull LocalDateTime value); /** * Write TIMESTAMPZ with given precision. */ - void writeTimestampz(@NotNull Timestamp value); + void writeTimestampz(@NotNull OffsetDateTime value); /** * Write a VARIANT type. diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/value/ion/IonSink.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/value/ion/IonSink.kt index eb0eb2e7d..23e70047e 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/value/ion/IonSink.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/value/ion/IonSink.kt @@ -2,16 +2,19 @@ package org.partiql.spi.value.ion import com.amazon.ion.IonType import com.amazon.ion.IonWriter +import com.amazon.ion.Timestamp import com.amazon.ion.system.IonBinaryWriterBuilder import com.amazon.ion.system.IonTextWriterBuilder import org.partiql.spi.stream.PSink import org.partiql.types.PType -import org.partiql.value.datetime.Date -import org.partiql.value.datetime.Time -import org.partiql.value.datetime.Timestamp import java.io.OutputStream import java.lang.Double.parseDouble import java.math.BigDecimal +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.OffsetDateTime +import java.time.OffsetTime import java.util.BitSet /** @@ -243,24 +246,44 @@ public class IonSink : PSink { this.writer.writeClob(value) } - override fun writeDate(value: Date) { - TODO("datetime blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656") + override fun writeDate(value: LocalDate) { + if (elisions[PType.DATE]) { + this.writer.setTypeAnnotations() + } + val iso8601 = value.toString() + this.writer.writeString(iso8601) } - override fun writeTime(value: Time) { - TODO("datetime blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656") + override fun writeTime(value: LocalTime) { + if (elisions[PType.TIME]) { + this.writer.setTypeAnnotations() + } + val iso8601 = value.toString() + this.writer.writeString(iso8601) } - override fun writeTimez(value: Time) { - TODO("datetime blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656") + override fun writeTimez(value: OffsetTime) { + if (elisions[PType.TIMEZ]) { + this.writer.setTypeAnnotations() + } + val iso8601 = value.toString() + this.writer.writeString(iso8601) } - override fun writeTimestamp(value: Timestamp) { - TODO("datetime blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656") + override fun writeTimestamp(value: LocalDateTime) { + if (elisions[PType.TIMESTAMP]) { + this.writer.setTypeAnnotations() + } + val iso8601 = value.toString() + this.writer.writeString(iso8601) } - override fun writeTimestampz(value: Timestamp) { - TODO("datetime blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656") + override fun writeTimestampz(value: OffsetDateTime) { + if (elisions[PType.TIMESTAMPZ]) { + this.writer.setTypeAnnotations() + } + val iso8601 = value.toString() + this.writer.writeString(iso8601) } override fun writeVariant(value: T) { diff --git a/partiql-spi/src/test/kotlin/org/partiql/spi/value/ion/IonStreamTest.kt b/partiql-spi/src/test/kotlin/org/partiql/spi/value/ion/IonStreamTest.kt index 0b5f01050..6817e96bd 100644 --- a/partiql-spi/src/test/kotlin/org/partiql/spi/value/ion/IonStreamTest.kt +++ b/partiql-spi/src/test/kotlin/org/partiql/spi/value/ion/IonStreamTest.kt @@ -82,7 +82,16 @@ class IonStreamTest { @Test fun testDatetime() { - // TODO blocked on https://github.com/partiql/partiql-lang-kotlin/pull/1656 + // date + + // time + + // timez + + // timestamp + + // timestampz + case("'timestamp'::2017-01-01T00:00:00Z", Datum.timestamp(2017, 1, 1, 0, 0, 0, 0, 0)) } @Test