From a08318402f52fc7f01fc6c1170f73eff74c9d29d Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 26 Nov 2024 17:22:34 -0500 Subject: [PATCH] Update Datum from PartiQLValue --- .../java/org/partiql/spi/value/Datum.java | 80 ++++++++++--------- .../java/org/partiql/spi/value/DatumNull.java | 13 +-- .../spi/function/builtins/FnDateAddMonth.kt | 12 +-- .../spi/function/builtins/FnDateAddSecond.kt | 12 +-- .../spi/function/builtins/FnDateAddYear.kt | 12 +-- .../spi/function/builtins/FnExtract.kt | 36 ++++----- .../partiql/spi/function/builtins/FnGte.kt | 12 +-- .../org/partiql/spi/function/builtins/FnLt.kt | 12 +-- .../partiql/spi/function/builtins/FnLte.kt | 12 +-- 9 files changed, 106 insertions(+), 95 deletions(-) diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java index 514d07cb80..8274036b15 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java @@ -9,9 +9,6 @@ import org.partiql.value.PartiQL; import org.partiql.value.PartiQLValue; import org.partiql.value.PartiQLValueType; -import org.partiql.value.datetime.Date; -import org.partiql.value.datetime.Time; -import org.partiql.value.datetime.Timestamp; import java.math.BigDecimal; import java.math.BigInteger; @@ -130,6 +127,7 @@ default boolean getBoolean() { *

* ! ! ! EXPERIMENTAL ! ! ! This is an experimental API under development by the PartiQL maintainers. *

+ * * @return the underlying value applicable to the types: * {@link PType#BLOB}, * {@link PType#CLOB} @@ -138,7 +136,7 @@ default boolean getBoolean() { * will throw this exception upon invocation. * @throws NullPointerException if this instance also returns true on {@link #isNull()}; callers should check that * {@link #isNull()} returns false before attempting to invoke this method. - * Please abstain from using this API until given notice otherwise. This may break between iterations without prior notice. + * Please abstain from using this API until given notice otherwise. This may break between iterations without prior notice. * @deprecated BINARY doesn't exist in SQL or Ion. This is subject to deletion. BLOB and CLOB are typically represented * in a fashion that can support much larger values -- this may be modified at any time. */ @@ -149,6 +147,7 @@ default byte[] getBytes() { /** * ! ! ! EXPERIMENTAL ! ! ! This is an experimental API under development by the PartiQL maintainers. + * * @return the underlying value applicable to the types: * {@link PType#TINYINT} * @throws UnsupportedOperationException if the operation is not applicable to the type returned from @@ -156,7 +155,7 @@ default byte[] getBytes() { * will throw this exception upon invocation. * @throws NullPointerException if this instance also returns true on {@link #isNull()}; callers should check that * {@link #isNull()} returns false before attempting to invoke this method. - * Please abstain from using this API until given notice otherwise. This may break between iterations without prior notice. + * Please abstain from using this API until given notice otherwise. This may break between iterations without prior notice. * @deprecated BYTE is not present in SQL or Ion. This is subject to deletion. */ @Deprecated @@ -166,7 +165,6 @@ default byte getByte() { /** * @return a {@link LocalDate} for DATE, TIMESTAMP, and TIMESTAMPZ types. - * * @throws UnsupportedOperationException if type not in (DATE, TIMESTAMP, TIMESTAMPZ) * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @@ -176,9 +174,8 @@ default LocalDate getLocalDate() { } /** - * @return an {@link OffsetTime} for TIME and TIMESTAMP types. - * - * @throws UnsupportedOperationException if type not in (TIME, TIMESTAMP) + * @return an {@link OffsetTime} for TIME, TIMEZ, TIMESTAMP, TIMESTAMPZ types. + * @throws UnsupportedOperationException if type not in (TIME, TIMEZ, TIMESTAMP, TIMESTAMPZ) * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @NotNull @@ -188,7 +185,6 @@ default LocalTime getLocalTime() { /** * @return an {@link OffsetTime} for TIMEZ and TIMESTAMPZ types. - * * @throws UnsupportedOperationException if type not in (TIMEZ, TIMESTAMPZ) * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @@ -198,9 +194,8 @@ default OffsetTime getOffsetTime() { } /** - * @return a {@link LocalDateTime} for TIMESTAMP types. - * - * @throws UnsupportedOperationException if type not TIMESTAMP + * @return a {@link LocalDateTime} for TIMESTAMP, TIMESTAMPZ types. + * @throws UnsupportedOperationException if type not in (TIMESTAMP, TIMESTAMPZ) * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @NotNull @@ -210,7 +205,6 @@ default LocalDateTime getLocalDateTime() { /** * @return a {@link OffsetDateTime} for TIMESTAMPZ types. - * * @throws UnsupportedOperationException if type not TIMESTAMPZ * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @@ -220,9 +214,8 @@ default OffsetDateTime getOffsetDateTime() { } /** - * @return a {@link Period} for the INTERVALYM type. - * - * @throws UnsupportedOperationException if type not in [INTERVAL] + * @return a {@link Period} for the INTERVAL_YM type. + * @throws UnsupportedOperationException if type not INTERVAL_YM * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @NotNull @@ -231,9 +224,8 @@ default Period getPeriod() { } /** - * @return a {@link Duration} for the INTERVALDT type. - * - * @throws UnsupportedOperationException if type not in [INTERVALDT] + * @return a {@link Duration} for the INTERVAL_DT type. + * @throws UnsupportedOperationException if type not in INTERVAL_DT * @throws NullPointerException if isNull() is true; callers should check to avoid NPEs. */ @NotNull @@ -454,13 +446,13 @@ default PartiQLValue toPartiQLValue() { case CLOB: return this.isNull() ? PartiQL.clobValue(null) : PartiQL.clobValue(this.getBytes()); case DATE: - return this.isNull() ? PartiQL.dateValue(null) : PartiQL.dateValue(this.getDate()); + throw new UnsupportedOperationException("Datum date to PartiQLValue is not supported"); case TIMEZ: - case TIME: // TODO - return this.isNull() ? PartiQL.timeValue(null) : PartiQL.timeValue(this.getTime()); + case TIME: + throw new UnsupportedOperationException("Datum time/timez to PartiQLValue is not supported"); case TIMESTAMPZ: case TIMESTAMP: - return this.isNull() ? PartiQL.timestampValue(null) : PartiQL.timestampValue(this.getTimestamp()); + throw new UnsupportedOperationException("Datum timestamp/timestampz to PartiQLValue is not supported"); case BAG: return this.isNull() ? PartiQL.bagValue((Iterable) null) : PartiQL.bagValue(new PQLToPartiQLIterable(this)); case ARRAY: @@ -532,17 +524,34 @@ static Datum of(PartiQLValue value) { case BINARY: throw new UnsupportedOperationException(); case DATE: - org.partiql.value.DateValue DATEValue = (org.partiql.value.DateValue) value; - return new DatumDate(Objects.requireNonNull(DATEValue.getValue())); + org.partiql.value.datetime.Date DATEValue = ((org.partiql.value.DateValue) value).getValue(); + Objects.requireNonNull(DATEValue); + LocalDate date = LocalDate.of(DATEValue.getYear(), DATEValue.getMonth(), DATEValue.getDay()); + return new DatumDate(date); case INTERVAL: - org.partiql.value.IntervalValue INTERVALValue = (org.partiql.value.IntervalValue) value; - return new DatumInterval(Objects.requireNonNull(INTERVALValue.getValue())); + throw new UnsupportedOperationException("INTERVAL not implemented"); case TIMESTAMP: - org.partiql.value.TimestampValue TIMESTAMPValue = (org.partiql.value.TimestampValue) value; - return new DatumTimestamp(Objects.requireNonNull(TIMESTAMPValue.getValue())); + org.partiql.value.datetime.Timestamp TIMESTAMPValue = ((org.partiql.value.TimestampValue) value).getValue(); + Objects.requireNonNull(TIMESTAMPValue); + // calculate seconds precision + BigDecimal tsds = TIMESTAMPValue.getDecimalSecond(); + int tsprec = tsds.scale(); + int tssecs = tsds.intValue(); + int tsnano = tsds.remainder(BigDecimal.ONE).movePointRight(tsds.scale()).abs().intValue(); + // make datum + LocalDateTime timestamp = LocalDateTime.of(TIMESTAMPValue.getYear(), TIMESTAMPValue.getMonth(), TIMESTAMPValue.getDay(), TIMESTAMPValue.getHour(), TIMESTAMPValue.getMinute(), tssecs, tsnano); + return new DatumTimestamp(timestamp, tsprec); case TIME: - org.partiql.value.TimeValue TIMEValue = (org.partiql.value.TimeValue) value; - return new DatumTime(Objects.requireNonNull(TIMEValue.getValue())); + org.partiql.value.datetime.Timestamp TIMEValue = ((org.partiql.value.TimestampValue) value).getValue(); + Objects.requireNonNull(TIMEValue); + // calculate seconds precision + BigDecimal tds = TIMEValue.getDecimalSecond(); + int tprec = tds.scale(); + int tsecs = tds.intValue(); + int tnano = tds.remainder(BigDecimal.ONE).movePointRight(tds.scale()).abs().intValue(); + // make datum + LocalTime time = LocalTime.of(TIMEValue.getHour(), TIMEValue.getMinute(), tsecs, tnano); + return new DatumTime(time, tprec); case FLOAT32: org.partiql.value.Float32Value FLOAT32Value = (org.partiql.value.Float32Value) value; return new DatumFloat(Objects.requireNonNull(FLOAT32Value.getValue())); @@ -592,6 +601,7 @@ static Datum nullValue(@NotNull PType type) { /** * Returns a typed missing value * ! EXPERIMENTAL ! This is subject to breaking changes and/or removal without prior notice. + * * @param type the type of the value * @return a typed missing value * @deprecated this may not be required. This is subject to removal. @@ -668,7 +678,6 @@ static Datum string(@NotNull String value) { } /** - * * @param value the string to place in the varchar * @return a varchar value with a default length of 255 */ @@ -678,7 +687,6 @@ static Datum varchar(@NotNull String value) { } /** - * * @param value the string to place in the varchar * @return a varchar value * TODO: Error or coerce here? Right now coerce, though I think this should likely error. @@ -700,7 +708,6 @@ static Datum varchar(@NotNull String value, int length) { } /** - * * @param value the string to place in the char * @return a char value with a default length of 255 */ @@ -710,7 +717,6 @@ static Datum character(@NotNull String value) { } /** - * * @param value the string to place in the char * @return a char value */ @@ -823,6 +829,7 @@ static Datum struct(@NotNull Iterable values) { * {@link java.util.TreeSet} in combination with this {@link Comparator} to implement the before-mentioned * operations. *

+ * * @return the default comparator for {@link Datum}. The comparator orders null values first. * @see Datum * @see java.util.TreeSet @@ -843,6 +850,7 @@ static Comparator comparator() { * {@link java.util.TreeSet} in combination with this {@link Comparator} to implement the before-mentioned * operations. *

+ * * @param nullsFirst if true, nulls are ordered before non-null values, otherwise after. * @return the default comparator for {@link Datum}. * @see Datum diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java index 878d4814bf..9e1fbb32d1 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java @@ -179,6 +179,7 @@ public LocalDate getLocalDate() { public LocalTime getLocalTime() { switch (_type.code()) { case PType.TIME: + case PType.TIMEZ: case PType.TIMESTAMP: case PType.TIMESTAMPZ: throw new NullPointerException(); @@ -202,17 +203,19 @@ public OffsetTime getOffsetTime() { @NotNull @Override public LocalDateTime getLocalDateTime() { - if (_type.getKind() == PType.Kind.TIMESTAMP) { - throw new NullPointerException(); - } else { - throw new UnsupportedOperationException(); + switch (_type.code()) { + case PType.TIMESTAMP: + case PType.TIMESTAMPZ: + throw new NullPointerException(); + default: + throw new UnsupportedOperationException(); } } @NotNull @Override public OffsetDateTime getOffsetDateTime() { - if (_type.getKind() == PType.Kind.TIMESTAMPZ) { + if (_type.code() == PType.TIMESTAMPZ) { throw new NullPointerException(); } else { throw new UnsupportedOperationException(); diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt index 5a61e31c59..9a44b8951a 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt @@ -21,7 +21,7 @@ internal val Fn_DATE_ADD_MONTH__INT32_DATE__DATE = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = interval.toLong() Datum.date(datetimeValue.plusMonths(intervalValue)) @@ -38,7 +38,7 @@ internal val Fn_DATE_ADD_MONTH__INT64_DATE__DATE = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = interval Datum.date(datetimeValue.plusMonths(intervalValue)) @@ -55,7 +55,7 @@ internal val Fn_DATE_ADD_MONTH__INT_DATE__DATE = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = try { interval.toLong() @@ -76,7 +76,7 @@ internal val Fn_DATE_ADD_MONTH__INT32_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval.toLong() Datum.timestamp(datetimeValue.plusMonths(intervalValue)) @@ -93,7 +93,7 @@ internal val Fn_DATE_ADD_MONTH__INT64_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval Datum.timestamp(datetimeValue.plusMonths(intervalValue)) @@ -110,7 +110,7 @@ internal val Fn_DATE_ADD_MONTH__INT_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = try { interval.toLong() diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt index 53c3415e58..eff6dc9dcb 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt @@ -21,7 +21,7 @@ internal val Fn_DATE_ADD_SECOND__INT32_TIME__TIME = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].time + val datetime = args[1].localTime val datetimeValue = datetime val intervalValue = interval.toLong() Datum.time(datetimeValue.plusSeconds(intervalValue)) @@ -38,7 +38,7 @@ internal val Fn_DATE_ADD_SECOND__INT64_TIME__TIME = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].time + val datetime = args[1].localTime val datetimeValue = datetime val intervalValue = interval Datum.time(datetimeValue.plusSeconds(intervalValue)) @@ -55,7 +55,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIME__TIME = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].time + val datetime = args[1].localTime val datetimeValue = datetime val intervalValue = try { interval.toLong() @@ -76,7 +76,7 @@ internal val Fn_DATE_ADD_SECOND__INT32_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval.toLong() Datum.timestamp(datetimeValue.plusSeconds(intervalValue)) @@ -93,7 +93,7 @@ internal val Fn_DATE_ADD_SECOND__INT64_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval Datum.timestamp(datetimeValue.plusSeconds(intervalValue)) @@ -110,7 +110,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = try { interval.toLong() diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt index 4beae8cbb3..810845b494 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt @@ -21,7 +21,7 @@ internal val Fn_DATE_ADD_YEAR__INT32_DATE__DATE = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = interval.toLong() Datum.date(datetimeValue.plusYears(intervalValue)) @@ -38,7 +38,7 @@ internal val Fn_DATE_ADD_YEAR__INT64_DATE__DATE = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = interval Datum.date(datetimeValue.plusYears(intervalValue)) @@ -55,7 +55,7 @@ internal val Fn_DATE_ADD_YEAR__INT_DATE__DATE = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].date + val datetime = args[1].localDate val datetimeValue = datetime val intervalValue = try { interval.toLong() @@ -76,7 +76,7 @@ internal val Fn_DATE_ADD_YEAR__INT32_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].int - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval.toLong() Datum.timestamp(datetimeValue.plusYears(intervalValue)) @@ -93,7 +93,7 @@ internal val Fn_DATE_ADD_YEAR__INT64_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].long - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = interval Datum.timestamp(datetimeValue.plusYears(intervalValue)) @@ -110,7 +110,7 @@ internal val Fn_DATE_ADD_YEAR__INT_TIMESTAMP__TIMESTAMP = Function.static( ) { args -> val interval = args[0].bigInteger - val datetime = args[1].timestamp + val datetime = args[1].localDateTime val datetimeValue = datetime val intervalValue = try { interval.toLong() diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt index dfe6db4cbc..12281ae805 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt @@ -21,7 +21,7 @@ internal val Fn_EXTRACT_YEAR__DATE__INT32 = Function.static( ), ) { args -> - val v = args[0].date + val v = args[0].localDate Datum.integer(v.year) } @@ -34,7 +34,7 @@ internal val Fn_EXTRACT_YEAR__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp + val v = args[0].localDateTime Datum.integer(v.year) } @@ -50,8 +50,8 @@ internal val Fn_EXTRACT_MONTH__DATE__INT32 = Function.static( ), ) { args -> - val v = args[0].date - Datum.integer(v.month) + val v = args[0].localDate + Datum.integer(v.monthValue) } internal val Fn_EXTRACT_MONTH__TIMESTAMP__INT32 = Function.static( @@ -63,8 +63,8 @@ internal val Fn_EXTRACT_MONTH__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp - Datum.integer(v.month) + val v = args[0].localDateTime + Datum.integer(v.monthValue) } // @@ -80,8 +80,8 @@ internal val Fn_EXTRACT_DAY__DATE__INT32 = Function.static( ), ) { args -> - val v = args[0].date - Datum.integer(v.day) + val v = args[0].localDate + Datum.integer(v.dayOfMonth) } internal val Fn_EXTRACT_DAY__TIMESTAMP__INT32 = Function.static( @@ -93,8 +93,8 @@ internal val Fn_EXTRACT_DAY__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp - Datum.integer(v.day) + val v = args[0].localDateTime + Datum.integer(v.dayOfMonth) } // @@ -109,7 +109,7 @@ internal val Fn_EXTRACT_HOUR__TIME__INT32 = Function.static( ), ) { args -> - val v = args[0].time + val v = args[0].localTime Datum.integer(v.hour) } @@ -122,7 +122,7 @@ internal val Fn_EXTRACT_HOUR__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp + val v = args[0].localDateTime Datum.integer(v.hour) } @@ -138,7 +138,7 @@ internal val Fn_EXTRACT_MINUTE__TIME__INT32 = Function.static( ), ) { args -> - val v = args[0].time + val v = args[0].localTime Datum.integer(v.minute) } @@ -151,7 +151,7 @@ internal val Fn_EXTRACT_MINUTE__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp + val v = args[0].localDateTime Datum.integer(v.minute) } @@ -196,7 +196,7 @@ internal val Fn_EXTRACT_TIMEZONE_HOUR__TIME__INT32 = Function.static( ), ) { args -> - val v = args[0].time + val v = args[0].offsetTime when (val tz = v.timeZone) { TimeZone.UnknownTimeZone -> Datum.integer(0) // TODO: Should this be NULL? is TimeZone.UtcOffset -> Datum.integer(tz.tzHour) @@ -213,7 +213,7 @@ internal val Fn_EXTRACT_TIMEZONE_HOUR__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp + val v = args[0].localDateTime when (val tz = v.timeZone) { TimeZone.UnknownTimeZone -> Datum.integer(0) // TODO: Should this be NULL? is TimeZone.UtcOffset -> Datum.integer(tz.tzHour) @@ -233,7 +233,7 @@ internal val Fn_EXTRACT_TIMEZONE_MINUTE__TIME__INT32 = Function.static( ), ) { args -> - val v = args[0].time + val v = args[0].localTime when (val tz = v.timeZone) { TimeZone.UnknownTimeZone -> Datum.integer(0) // TODO: Should this be NULL? is TimeZone.UtcOffset -> Datum.integer(tz.tzMinute) @@ -250,7 +250,7 @@ internal val Fn_EXTRACT_TIMEZONE_MINUTE__TIMESTAMP__INT32 = Function.static( ), ) { args -> - val v = args[0].timestamp + val v = args[0].localDateTime when (val tz = v.timeZone) { TimeZone.UnknownTimeZone -> Datum.integer(0) // TODO: Should this be NULL? is TimeZone.UtcOffset -> Datum.integer(tz.tzMinute) diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt index 9a581b5c2b..17a93d619b 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt @@ -109,24 +109,24 @@ internal object FnGte : DiadicComparisonOperator("gte") { override fun getTimestampInstance(timestampLhs: PType, timestampRhs: PType): Function.Instance { return basic(PType.bool(), timestampLhs, timestampRhs) { args -> - val lhs = args[0].timestamp - val rhs = args[1].timestamp + val lhs = args[0].localDateTime + val rhs = args[1].localDateTime Datum.bool(lhs >= rhs) } } override fun getDateInstance(dateLhs: PType, dateRhs: PType): Function.Instance { return basic(PType.bool(), PType.date()) { args -> - val lhs = args[0].date - val rhs = args[1].date + val lhs = args[0].localDate + val rhs = args[1].localDate Datum.bool(lhs >= rhs) } } override fun getTimeInstance(timeLhs: PType, timeRhs: PType): Function.Instance { return basic(PType.bool(), timeLhs, timeRhs) { args -> - val lhs = args[0].time - val rhs = args[1].time + val lhs = args[0].localTime + val rhs = args[1].localTime Datum.bool(lhs >= rhs) } } diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt index 8e526a2beb..092752eea4 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt @@ -85,24 +85,24 @@ internal object FnLt : DiadicComparisonOperator("lt") { override fun getTimestampInstance(timestampLhs: PType, timestampRhs: PType): Function.Instance { return basic(PType.bool(), timestampLhs, timestampRhs) { args -> - val lhs = args[0].timestamp - val rhs = args[1].timestamp + val lhs = args[0].localDateTime + val rhs = args[1].localDateTime Datum.bool(lhs < rhs) } } override fun getDateInstance(dateLhs: PType, dateRhs: PType): Function.Instance { return basic(PType.bool(), PType.date()) { args -> - val lhs = args[0].date - val rhs = args[1].date + val lhs = args[0].localDate + val rhs = args[1].localDate Datum.bool(lhs < rhs) } } override fun getTimeInstance(timeLhs: PType, timeRhs: PType): Function.Instance { return basic(PType.bool(), timeLhs, timeRhs) { args -> - val lhs = args[0].time - val rhs = args[1].time + val lhs = args[0].localTime + val rhs = args[1].localTime Datum.bool(lhs < rhs) } } diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt index 35d6cba0e1..c096c5c966 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt @@ -85,24 +85,24 @@ internal object FnLte : DiadicComparisonOperator("lte") { override fun getTimestampInstance(timestampLhs: PType, timestampRhs: PType): Function.Instance { return basic(PType.bool(), timestampLhs, timestampRhs) { args -> - val lhs = args[0].timestamp - val rhs = args[1].timestamp + val lhs = args[0].localDateTime + val rhs = args[1].localDateTime Datum.bool(lhs <= rhs) } } override fun getDateInstance(dateLhs: PType, dateRhs: PType): Function.Instance { return basic(PType.bool(), PType.date()) { args -> - val lhs = args[0].date - val rhs = args[1].date + val lhs = args[0].localDate + val rhs = args[1].localDate Datum.bool(lhs <= rhs) } } override fun getTimeInstance(timeLhs: PType, timeRhs: PType): Function.Instance { return basic(PType.bool(), timeLhs, timeRhs) { args -> - val lhs = args[0].time - val rhs = args[1].time + val lhs = args[0].localTime + val rhs = args[1].localTime Datum.bool(lhs <= rhs) } }