Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Jan 8, 2025
1 parent c2a90f8 commit 779387b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
18 changes: 10 additions & 8 deletions partiql-spi/src/main/java/org/partiql/spi/stream/PSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
49 changes: 36 additions & 13 deletions partiql-spi/src/main/kotlin/org/partiql/spi/value/ion/IonSink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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 <T : Any> writeVariant(value: T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 779387b

Please sign in to comment.