Skip to content

Commit

Permalink
Revert "[v1] Change integer types to error on overflow; give explicit…
Browse files Browse the repository at this point in the history
… data ex…"

This reverts commit 36fbfeb.
  • Loading branch information
alancai98 authored Jan 14, 2025
1 parent 36fbfeb commit 0c8bfcd
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 385 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class PartiQLEvaluatorTest {
int64Value(2),
),
globals = listOf(
Global(
SuccessTestCase.Global(
name = "t",
value = """
[
Expand All @@ -150,7 +150,7 @@ class PartiQLEvaluatorTest {
int64Value(2),
),
globals = listOf(
Global(
SuccessTestCase.Global(
name = "t",
value = """
[
Expand All @@ -177,7 +177,7 @@ class PartiQLEvaluatorTest {
),
),
globals = listOf(
Global(
SuccessTestCase.Global(
name = "customers",
value = """
[{id:1, name: "Mary"},
Expand All @@ -186,7 +186,7 @@ class PartiQLEvaluatorTest {
]
"""
),
Global(
SuccessTestCase.Global(
name = "orders",
value = """
[{custId:1, name: "foo"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PlusTest {
mode = Mode.STRICT(),
expected = Datum.decimal(BigDecimal.valueOf(457023), 14, 7),
globals = listOf(
Global(
SuccessTestCase.Global(
"dynamic_decimal",
"456789.0000000"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ import org.partiql.types.fromStaticType
import org.partiql.value.PartiQLValue
import kotlin.test.assertEquals

/**
* @property value is a serialized Ion value.
*/
class Global(
val name: String,
val value: String,
val type: StaticType = StaticType.ANY,
)

public class SuccessTestCase(
val input: String,
val expected: Datum,
Expand All @@ -46,6 +37,15 @@ public class SuccessTestCase(
private val parser = PartiQLParser.standard()
private val planner = PartiQLPlanner.standard()

/**
* @property value is a serialized Ion value.
*/
class Global(
val name: String,
val value: String,
val type: StaticType = StaticType.ANY,
)

override fun run() {
val parseResult = parser.parse(input)
assertEquals(1, parseResult.statements.size)
Expand Down Expand Up @@ -92,51 +92,3 @@ public class SuccessTestCase(
return input
}
}

public class FailureTestCase(
val input: String,
val mode: Mode = Mode.STRICT(), // default to run in STRICT mode
val globals: List<Global> = emptyList(),
) : PTestCase {
private val compiler = PartiQLCompiler.standard()
private val parser = PartiQLParser.standard()
private val planner = PartiQLPlanner.standard()

override fun run() {
val parseResult = parser.parse(input)
assertEquals(1, parseResult.statements.size)
val statement = parseResult.statements[0]
val catalog = Catalog.builder()
.name("memory")
.apply {
globals.forEach {
val table = Table.standard(
name = Name.of(it.name),
schema = fromStaticType(it.type),
datum = DatumReader.ion(it.value.byteInputStream()).next()!!
)
define(table)
}
}
.build()
val session = Session.builder()
.catalog("memory")
.catalogs(catalog)
.build()
var thrown: Throwable? = null
val plan = planner.plan(statement, session).plan
val actual: Datum = try {
DatumMaterialize.materialize(compiler.prepare(plan, mode).execute())
} catch (t: Throwable) {
thrown = t
Datum.nullValue()
}
if (thrown == null) {
val message = buildString {
appendLine("Expected error to be thrown but none was thrown.")
appendLine("Actual Result: $actual")
}
error(message)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package org.partiql.spi.function.builtins

import org.partiql.spi.errors.DataException
import org.partiql.spi.function.Function
import org.partiql.spi.types.PType
import org.partiql.spi.value.Datum
Expand All @@ -16,13 +15,8 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {

override fun getTinyIntInstance(tinyIntLhs: PType, tinyIntRhs: PType): Function.Instance {
return basic(PType.tinyint()) { args ->
val arg0 = args[0].byte
val arg1 = args[1].byte
if (arg1 == 0.toByte()) {
throw DataException("Division by zero for TINYINT: $arg0 / $arg1")
} else if (arg0 == Byte.MIN_VALUE && arg1.toInt() == -1) {
throw DataException("Resulting value out of range for: $arg0 / $arg1")
}
@Suppress("DEPRECATION") val arg0 = args[0].byte
@Suppress("DEPRECATION") val arg1 = args[1].byte
Datum.tinyint((arg0 / arg1).toByte())
}
}
Expand All @@ -31,11 +25,6 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
return basic(PType.smallint()) { args ->
val arg0 = args[0].short
val arg1 = args[1].short
if (arg1 == 0.toShort()) {
throw DataException("Division by zero for SMALLINT: $arg0 / $arg1")
} else if (arg0 == Short.MIN_VALUE && arg1.toInt() == -1) {
throw DataException("Resulting value out of range for: $arg0 / $arg1")
}
Datum.smallint((arg0 / arg1).toShort())
}
}
Expand All @@ -44,11 +33,6 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
return basic(PType.integer()) { args ->
val arg0 = args[0].int
val arg1 = args[1].int
if (arg1 == 0) {
throw DataException("Division by zero for INT: $arg0 / $arg1")
} else if (arg0 == Int.MIN_VALUE && arg1 == -1) {
throw DataException("Resulting value out of range for INT: $arg0 / $arg1")
}
Datum.integer(arg0 / arg1)
}
}
Expand All @@ -57,11 +41,6 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
return basic(PType.bigint()) { args ->
val arg0 = args[0].long
val arg1 = args[1].long
if (arg1 == 0L) {
throw DataException("Division by zero for BIGINT: $arg0 / $arg1")
} else if (arg0 == Long.MIN_VALUE && arg1 == -1L) {
throw DataException("Resulting value out of range for BIGINT: $arg0 / $arg1")
}
Datum.bigint(arg0 / arg1)
}
}
Expand Down
Loading

0 comments on commit 0c8bfcd

Please sign in to comment.