Skip to content

Commit

Permalink
Implements date_add builtin in partiql-eval (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
yliuuuu authored Jan 12, 2024
1 parent 390430e commit 1dabd4e
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 532 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,73 +369,49 @@ object PartiQLPlugin : Plugin {
Fn_DATE_ADD_YEAR__INT32_DATE__DATE,
Fn_DATE_ADD_YEAR__INT64_DATE__DATE,
Fn_DATE_ADD_YEAR__INT_DATE__DATE,
Fn_DATE_ADD_YEAR__INT32_TIME__TIME,
Fn_DATE_ADD_YEAR__INT64_TIME__TIME,
Fn_DATE_ADD_YEAR__INT_TIME__TIME,
Fn_DATE_ADD_YEAR__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_YEAR__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_YEAR__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MONTH__INT32_DATE__DATE,
Fn_DATE_ADD_MONTH__INT64_DATE__DATE,
Fn_DATE_ADD_MONTH__INT_DATE__DATE,
Fn_DATE_ADD_MONTH__INT32_TIME__TIME,
Fn_DATE_ADD_MONTH__INT64_TIME__TIME,
Fn_DATE_ADD_MONTH__INT_TIME__TIME,
Fn_DATE_ADD_MONTH__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MONTH__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MONTH__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_DAY__INT32_DATE__DATE,
Fn_DATE_ADD_DAY__INT64_DATE__DATE,
Fn_DATE_ADD_DAY__INT_DATE__DATE,
Fn_DATE_ADD_DAY__INT32_TIME__TIME,
Fn_DATE_ADD_DAY__INT64_TIME__TIME,
Fn_DATE_ADD_DAY__INT_TIME__TIME,
Fn_DATE_ADD_DAY__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_DAY__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_DAY__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_HOUR__INT32_DATE__DATE,
Fn_DATE_ADD_HOUR__INT64_DATE__DATE,
Fn_DATE_ADD_HOUR__INT_DATE__DATE,
Fn_DATE_ADD_HOUR__INT32_TIME__TIME,
Fn_DATE_ADD_HOUR__INT64_TIME__TIME,
Fn_DATE_ADD_HOUR__INT_TIME__TIME,
Fn_DATE_ADD_HOUR__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_HOUR__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_HOUR__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MINUTE__INT32_DATE__DATE,
Fn_DATE_ADD_MINUTE__INT64_DATE__DATE,
Fn_DATE_ADD_MINUTE__INT_DATE__DATE,
Fn_DATE_ADD_MINUTE__INT32_TIME__TIME,
Fn_DATE_ADD_MINUTE__INT64_TIME__TIME,
Fn_DATE_ADD_MINUTE__INT_TIME__TIME,
Fn_DATE_ADD_MINUTE__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MINUTE__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_MINUTE__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_SECOND__INT32_DATE__DATE,
Fn_DATE_ADD_SECOND__INT64_DATE__DATE,
Fn_DATE_ADD_SECOND__INT_DATE__DATE,
Fn_DATE_ADD_SECOND__INT32_TIME__TIME,
Fn_DATE_ADD_SECOND__INT64_TIME__TIME,
Fn_DATE_ADD_SECOND__INT_TIME__TIME,
Fn_DATE_ADD_SECOND__INT32_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_SECOND__INT64_TIMESTAMP__TIMESTAMP,
Fn_DATE_ADD_SECOND__INT_TIMESTAMP__TIMESTAMP,
Fn_DATE_DIFF_YEAR__DATE_DATE__INT64,
Fn_DATE_DIFF_YEAR__TIME_TIME__INT64,
Fn_DATE_DIFF_YEAR__TIMESTAMP_TIMESTAMP__INT64,
Fn_DATE_DIFF_MONTH__DATE_DATE__INT64,
Fn_DATE_DIFF_MONTH__TIME_TIME__INT64,
Fn_DATE_DIFF_MONTH__TIMESTAMP_TIMESTAMP__INT64,
Fn_DATE_DIFF_DAY__DATE_DATE__INT64,
Fn_DATE_DIFF_DAY__TIME_TIME__INT64,
Fn_DATE_DIFF_DAY__TIMESTAMP_TIMESTAMP__INT64,
Fn_DATE_DIFF_HOUR__DATE_DATE__INT64,
Fn_DATE_DIFF_HOUR__TIME_TIME__INT64,
Fn_DATE_DIFF_HOUR__TIMESTAMP_TIMESTAMP__INT64,
Fn_DATE_DIFF_MINUTE__DATE_DATE__INT64,
Fn_DATE_DIFF_MINUTE__TIME_TIME__INT64,
Fn_DATE_DIFF_MINUTE__TIMESTAMP_TIMESTAMP__INT64,
Fn_DATE_DIFF_SECOND__DATE_DATE__INT64,
Fn_DATE_DIFF_SECOND__TIME_TIME__INT64,
Fn_DATE_DIFF_SECOND__TIMESTAMP_TIMESTAMP__INT64,
Fn_CURRENT_USER____STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import org.partiql.spi.function.PartiQLFunction
import org.partiql.spi.function.PartiQLFunctionExperimental
import org.partiql.types.function.FunctionParameter
import org.partiql.types.function.FunctionSignature
import org.partiql.value.DateValue
import org.partiql.value.Int32Value
import org.partiql.value.Int64Value
import org.partiql.value.IntValue
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType.DATE
import org.partiql.value.PartiQLValueType.INT
import org.partiql.value.PartiQLValueType.INT32
import org.partiql.value.PartiQLValueType.INT64
import org.partiql.value.PartiQLValueType.TIME
import org.partiql.value.PartiQLValueType.TIMESTAMP
import org.partiql.value.TimestampValue
import org.partiql.value.check
import org.partiql.value.dateValue
import org.partiql.value.timestampValue

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal object Fn_DATE_ADD_DAY__INT32_DATE__DATE : PartiQLFunction.Scalar {
Expand All @@ -31,7 +38,15 @@ internal object Fn_DATE_ADD_DAY__INT32_DATE__DATE : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<Int32Value>()
val datetime = args[1].check<DateValue>()
return if (datetime.value == null || interval.value == null) {
dateValue(null)
} else {
val datetimeValue = datetime.value!!
val intervalValue = interval.long!!
dateValue(datetimeValue.plusDays(intervalValue))
}
}
}

Expand All @@ -50,7 +65,15 @@ internal object Fn_DATE_ADD_DAY__INT64_DATE__DATE : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<Int64Value>()
val datetime = args[1].check<DateValue>()
return if (datetime.value == null || interval.value == null) {
dateValue(null)
} else {
val datetimeValue = datetime.value!!
val intervalValue = interval.long!!
dateValue(datetimeValue.plusDays(intervalValue))
}
}
}

Expand All @@ -69,64 +92,16 @@ internal object Fn_DATE_ADD_DAY__INT_DATE__DATE : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
}
}

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal object Fn_DATE_ADD_DAY__INT32_TIME__TIME : PartiQLFunction.Scalar {

override val signature = FunctionSignature.Scalar(
name = "date_add_day",
returns = TIME,
parameters = listOf(
FunctionParameter("interval", INT32),
FunctionParameter("datetime", TIME),
),
isNullCall = true,
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
}
}

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal object Fn_DATE_ADD_DAY__INT64_TIME__TIME : PartiQLFunction.Scalar {

override val signature = FunctionSignature.Scalar(
name = "date_add_day",
returns = TIME,
parameters = listOf(
FunctionParameter("interval", INT64),
FunctionParameter("datetime", TIME),
),
isNullCall = true,
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
}
}

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal object Fn_DATE_ADD_DAY__INT_TIME__TIME : PartiQLFunction.Scalar {

override val signature = FunctionSignature.Scalar(
name = "date_add_day",
returns = TIME,
parameters = listOf(
FunctionParameter("interval", INT),
FunctionParameter("datetime", TIME),
),
isNullCall = true,
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<IntValue>()
val datetime = args[1].check<DateValue>()
return if (datetime.value == null || interval.value == null) {
dateValue(null)
} else {
val datetimeValue = datetime.value!!
// TODO: We need to consider overflow here
val intervalValue = interval.long!!
dateValue(datetimeValue.plusDays(intervalValue))
}
}
}

Expand All @@ -145,7 +120,15 @@ internal object Fn_DATE_ADD_DAY__INT32_TIMESTAMP__TIMESTAMP : PartiQLFunction.Sc
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<Int32Value>()
val datetime = args[1].check<TimestampValue>()
return if (datetime.value == null || interval.value == null) {
timestampValue(null)
} else {
val datetimeValue = datetime.value!!
val intervalValue = interval.long!!
timestampValue(datetimeValue.plusDays(intervalValue))
}
}
}

Expand All @@ -164,7 +147,15 @@ internal object Fn_DATE_ADD_DAY__INT64_TIMESTAMP__TIMESTAMP : PartiQLFunction.Sc
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<Int64Value>()
val datetime = args[1].check<TimestampValue>()
return if (datetime.value == null || interval.value == null) {
timestampValue(null)
} else {
val datetimeValue = datetime.value!!
val intervalValue = interval.long!!
timestampValue(datetimeValue.plusDays(intervalValue))
}
}
}

Expand All @@ -183,6 +174,15 @@ internal object Fn_DATE_ADD_DAY__INT_TIMESTAMP__TIMESTAMP : PartiQLFunction.Scal
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function date_add_day not implemented")
val interval = args[0].check<IntValue>()
val datetime = args[1].check<TimestampValue>()
return if (datetime.value == null || interval.value == null) {
timestampValue(null)
} else {
val datetimeValue = datetime.value!!
// TODO: We need to consider overflow here
val intervalValue = interval.long!!
timestampValue(datetimeValue.plusDays(intervalValue))
}
}
}
Loading

0 comments on commit 1dabd4e

Please sign in to comment.