Skip to content

Commit

Permalink
Removes use of deprecated PType.numeric()
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Nov 26, 2024
1 parent c14896e commit b36a420
Show file tree
Hide file tree
Showing 40 changed files with 95 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,5 @@ internal object RelConverter {
private val STRUCT: CompilerType = CompilerType(PType.struct())
private val BAG: CompilerType = CompilerType(PType.bag())
private val LIST: CompilerType = CompilerType(PType.array())
private val INT: CompilerType = CompilerType(PType.numeric())
private val INT: CompilerType = CompilerType(PType.numeric(38, 0))
}
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ internal object RexConverter {
private val STRUCT: CompilerType = CompilerType(PType.struct())
private val BAG: CompilerType = CompilerType(PType.bag())
private val LIST: CompilerType = CompilerType(PType.array())
private val INT: CompilerType = CompilerType(PType.numeric())
private val INT: CompilerType = CompilerType(PType.numeric(38, 0))
private val INT4: CompilerType = CompilerType(PType.integer())
private val TIMESTAMP: CompilerType = CompilerType(PType.timestamp(6))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ internal class DynamicTyper {
PType.SMALLINT -> PType.smallint()
PType.INTEGER -> PType.integer()
PType.BIGINT -> PType.bigint()
PType.NUMERIC -> PType.numeric()
PType.NUMERIC -> PType.numeric(38, 0) // TODO: To be updated
PType.DECIMAL -> PType.decimal(38, 0) // TODO: To be updated.
PType.REAL -> PType.real()
PType.DOUBLE -> PType.doublePrecision()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ internal class PlanTyper(private val env: Env, config: Context) {
val limit = node.limit.type(input.type.schema, outer, Strategy.GLOBAL)
// check types
if (limit.type.isNumeric().not()) {
val problem = PErrors.typeUnexpected(null, limit.type, listOf(PType.numeric()))
val problem = PErrors.typeUnexpected(null, limit.type, listOf(PType.numeric(38, 0)))
val err = errorRexAndReport(_listener, problem)
return rel(input.type, relOpLimit(input, err))
}
Expand All @@ -400,7 +400,7 @@ internal class PlanTyper(private val env: Env, config: Context) {
val offset = node.offset.type(input.type.schema, outer, Strategy.GLOBAL)
// check types
if (offset.type.isNumeric().not()) {
val problem = PErrors.typeUnexpected(null, offset.type, listOf(PType.numeric()))
val problem = PErrors.typeUnexpected(null, offset.type, listOf(PType.numeric(38, 0)))
val err = errorRexAndReport(_listener, problem)
return rel(input.type, relOpLimit(input, err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4340,7 +4340,7 @@ internal class PlanTyperTestsPorted {
query = "SELECT * FROM pets LIMIT '5'",
expected = TABLE_AWS_DDB_PETS,
problemHandler = assertProblemExists(
PErrors.typeUnexpected(null, PType.string(), listOf(PType.numeric()))
PErrors.typeUnexpected(null, PType.string(), listOf(PType.numeric(38, 0)))
)
),
SuccessTestCase(
Expand All @@ -4357,7 +4357,7 @@ internal class PlanTyperTestsPorted {
query = "SELECT * FROM pets LIMIT 1 OFFSET '5'",
expected = TABLE_AWS_DDB_PETS,
problemHandler = assertProblemExists(
PErrors.typeUnexpected(null, PType.string(), listOf(PType.numeric()))
PErrors.typeUnexpected(null, PType.string(), listOf(PType.numeric(38, 0)))
)
),
SuccessTestCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class OpBitwiseAndTest : PartiQLTyperTestBase() {
val arg0 = args.first()
val arg1 = args[1]
val output = when {
arg0 !in allIntPType && arg1 !in allIntPType -> PType.numeric()
arg0 in allIntPType && arg1 !in allIntPType -> PType.numeric()
arg0 !in allIntPType && arg1 in allIntPType -> PType.numeric()
arg0 !in allIntPType && arg1 !in allIntPType -> PType.numeric(38, 0)
arg0 in allIntPType && arg1 !in allIntPType -> PType.numeric(38, 0)
arg0 !in allIntPType && arg1 in allIntPType -> PType.numeric(38, 0)
arg0 == arg1 -> arg1
castTablePType(arg1, arg0) == CastType.COERCION -> arg0
castTablePType(arg0, arg1) == CastType.COERCION -> arg1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val allBooleanPType = setOf(
PType.bool()
)

val allIntPType = setOf(PType.tinyint(), PType.smallint(), PType.integer(), PType.bigint(), PType.numeric())
val allIntPType = setOf(PType.tinyint(), PType.smallint(), PType.integer(), PType.bigint(), PType.numeric(38, 0))

val allNumberPType = allIntPType + setOf(
PType.decimal(38, 19),
Expand Down
25 changes: 24 additions & 1 deletion partiql-spi/src/main/java/org/partiql/spi/value/Datum.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@
import java.util.Iterator;
import java.util.Objects;

import static org.partiql.types.PType.*; // TODO
import static org.partiql.types.PType.DYNAMIC;
import static org.partiql.types.PType.BOOL;
import static org.partiql.types.PType.TINYINT;
import static org.partiql.types.PType.SMALLINT;
import static org.partiql.types.PType.INTEGER;
import static org.partiql.types.PType.BIGINT;
import static org.partiql.types.PType.NUMERIC;
import static org.partiql.types.PType.DECIMAL;
import static org.partiql.types.PType.REAL;
import static org.partiql.types.PType.DOUBLE;
import static org.partiql.types.PType.CHAR;
import static org.partiql.types.PType.STRING;
import static org.partiql.types.PType.BLOB;
import static org.partiql.types.PType.CLOB;
import static org.partiql.types.PType.DATE;
import static org.partiql.types.PType.TIME;
import static org.partiql.types.PType.TIMEZ;
import static org.partiql.types.PType.TIMESTAMP;
import static org.partiql.types.PType.TIMESTAMPZ;
import static org.partiql.types.PType.ARRAY;
import static org.partiql.types.PType.BAG;
import static org.partiql.types.PType.ROW;
import static org.partiql.types.PType.STRUCT;
import static org.partiql.types.PType.UNKNOWN;

/**
* This is an EXPERIMENTAL representation of a value in PartiQL's type system. The intention of this modeling is to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DatumBigInteger implements Datum {
@NotNull
private final BigInteger _value;

private final static PType _type = PType.numeric();
private final static PType _type = PType.numeric(38, 0);

DatumBigInteger(@NotNull BigInteger value) {
_value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal object Builtins {
Fn_ABS__INT16__INT16,
Fn_ABS__INT32__INT32,
Fn_ABS__INT64__INT64,
Fn_ABS__INT__INT,
Fn_ABS__NUMERIC__NUMERIC,
Fn_ABS__FLOAT32__FLOAT32,
Fn_ABS__FLOAT64__FLOAT64,
Fn_ABS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Expand Down Expand Up @@ -261,7 +261,7 @@ internal object Builtins {
Agg_AVG__INT16__INT16,
Agg_AVG__INT32__INT32,
Agg_AVG__INT64__INT64,
Agg_AVG__INT__INT,
Agg_AVG__NUMERIC__NUMERIC,
Agg_AVG__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_AVG__FLOAT32__FLOAT32,
Agg_AVG__FLOAT64__FLOAT64,
Expand All @@ -273,7 +273,7 @@ internal object Builtins {
Agg_MAX__INT16__INT16,
Agg_MAX__INT32__INT32,
Agg_MAX__INT64__INT64,
Agg_MAX__INT__INT,
Agg_MAX__NUMERIC__NUMERIC,
Agg_MAX__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_MAX__FLOAT32__FLOAT32,
Agg_MAX__FLOAT64__FLOAT64,
Expand All @@ -293,7 +293,7 @@ internal object Builtins {
Agg_SUM__INT16__INT16,
Agg_SUM__INT32__INT32,
Agg_SUM__INT64__INT64,
Agg_SUM__INT__INT,
Agg_SUM__NUMERIC__NUMERIC,
Agg_SUM__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_SUM__FLOAT32__FLOAT32,
Agg_SUM__FLOAT64__FLOAT64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ internal val Agg_AVG__INT64__INT64 = Aggregation.static(
accumulator = ::AccumulatorAvg,
)

internal val Agg_AVG__INT__INT = Aggregation.static(
internal val Agg_AVG__NUMERIC__NUMERIC = Aggregation.static(

name = "avg",
returns = PType.decimal(38, 19),
returns = PType.decimal(38, 19), // TODO: Return Numeric once Datum is updated to use BigDecimal
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.numeric()),
Parameter("value", DefaultNumeric.NUMERIC),
),
accumulator = ::AccumulatorAvg,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ internal val Agg_MAX__INT64__INT64 = Aggregation.static(
accumulator = ::AccumulatorMax,
)

internal val Agg_MAX__INT__INT = Aggregation.static(
internal val Agg_MAX__NUMERIC__NUMERIC = Aggregation.static(

name = "max",
returns = PType.numeric(),
returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.numeric()),
Parameter("value", DefaultNumeric.NUMERIC),
),
accumulator = ::AccumulatorMax,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ internal val Agg_MIN__INT64__INT64 = Aggregation.static(

internal val Agg_MIN__INT__INT = Aggregation.static(
name = "min",
returns = PType.numeric(),
returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.numeric()),
Parameter("value", DefaultNumeric.NUMERIC), // TODO: Rewrite aggregations using new function modeling.
),
accumulator = ::AccumulatorMin,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ internal val Agg_SUM__INT64__INT64 = Aggregation.static(
accumulator = { AccumulatorSum(PType.bigint()) },
)

internal val Agg_SUM__INT__INT = Aggregation.static(
internal val Agg_SUM__NUMERIC__NUMERIC = Aggregation.static(
name = "sum",
returns = PType.numeric(),
returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.numeric()),
Parameter("value", DefaultNumeric.NUMERIC),
),
accumulator = { AccumulatorSum(PType.numeric()) },
accumulator = { AccumulatorSum(DefaultNumeric.NUMERIC) },
)

internal val Agg_SUM__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Aggregation.static(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.partiql.spi.function.builtins

import org.partiql.types.PType

internal object DefaultNumeric {
// TODO: Once all functions are converted to use the new function modeling, this can be removed.
val NUMERIC: PType = PType.numeric(38, 19)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ internal val Fn_ABS__INT64__INT64 = Function.static(
Datum.bigint(value.absoluteValue)
}

internal val Fn_ABS__INT__INT = Function.static(
internal val Fn_ABS__NUMERIC__NUMERIC = Function.static(
name = "abs",
returns = PType.numeric(),
parameters = arrayOf(Parameter("value", PType.numeric())),
returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(Parameter("value", DefaultNumeric.NUMERIC)),
) { args ->
val value = args[0].bigInteger
Datum.numeric(value.abs())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ internal val Fn_BETWEEN__INT_INT_INT__BOOL = Function.static(
name = "between",
returns = PType.bool(),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.numeric()),
@Suppress("DEPRECATION") Parameter("lower", PType.numeric()),
@Suppress("DEPRECATION") Parameter("upper", PType.numeric()),
Parameter("value", DefaultNumeric.NUMERIC),
Parameter("lower", DefaultNumeric.NUMERIC),
Parameter("upper", DefaultNumeric.NUMERIC),
),

) { args ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal object FnBitwiseAnd : DiadicArithmeticOperator("bitwise_and") {

// TODO: Probably remove this if we don't expose NUMERIC
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
return basic(PType.numeric()) { args ->
return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 and arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_DAY__INT_DATE__DATE = Function.static(
name = "date_add_day",
returns = PType.date(),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_DAY__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_day",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_HOUR__INT_TIME__TIME = Function.static(
name = "date_add_hour",
returns = PType.time(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_HOUR__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_hour",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_MINUTE__INT_TIME__TIME = Function.static(
name = "date_add_minute",
returns = PType.time(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_MINUTE__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_minute",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_MONTH__INT_DATE__DATE = Function.static(
name = "date_add_month",
returns = PType.date(),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_MONTH__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_month",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIME__TIME = Function.static(
name = "date_add_second",
returns = PType.time(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_second",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_YEAR__INT_DATE__DATE = Function.static(
name = "date_add_year",
returns = PType.date(),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),

Expand Down Expand Up @@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_YEAR__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_year",
returns = PType.timestamp(6),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
}

override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
return basic(PType.numeric()) { args ->
return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 / arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal object FnGt : DiadicComparisonOperator("gt") {

// TODO: Update numeric to use bigDecimal rather than bigInteger.
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
return basic(PType.bool(), PType.numeric()) { args ->
return basic(PType.bool(), DefaultNumeric.NUMERIC) { args ->
val lhs = args[0].bigInteger
val rhs = args[1].bigInteger
Datum.bool(lhs > rhs)
Expand Down
Loading

0 comments on commit b36a420

Please sign in to comment.