From 4bd73cfde862baa1794032a4fdb8ca3cdc1d6d44 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Wed, 20 Nov 2024 17:02:09 -0800 Subject: [PATCH] Fix failing conformance tests --- partiql-ast/api/partiql-ast.api | 1 + .../java/org/partiql/ast/literal/LiteralExact.java | 6 ++++++ .../planner/internal/transforms/RexConverter.kt | 14 +++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/partiql-ast/api/partiql-ast.api b/partiql-ast/api/partiql-ast.api index 99c691270..21eb8a5b7 100644 --- a/partiql-ast/api/partiql-ast.api +++ b/partiql-ast/api/partiql-ast.api @@ -2595,6 +2595,7 @@ public class org/partiql/ast/literal/LiteralExact : org/partiql/ast/literal/Lite public fun getText ()Ljava/lang/String; public fun hashCode ()I public static fun litExact (Ljava/math/BigDecimal;)Lorg/partiql/ast/literal/LiteralExact; + public static fun litExact (Ljava/math/BigInteger;)Lorg/partiql/ast/literal/LiteralExact; } public class org/partiql/ast/literal/LiteralInteger : org/partiql/ast/literal/Literal { diff --git a/partiql-ast/src/main/java/org/partiql/ast/literal/LiteralExact.java b/partiql-ast/src/main/java/org/partiql/ast/literal/LiteralExact.java index 22c78c50c..96f23d518 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/literal/LiteralExact.java +++ b/partiql-ast/src/main/java/org/partiql/ast/literal/LiteralExact.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; import java.math.BigDecimal; +import java.math.BigInteger; /** * TODO DOCS @@ -22,6 +23,11 @@ public static LiteralExact litExact(BigDecimal value) { return new LiteralExact(value); } + @NotNull + public static LiteralExact litExact(BigInteger value) { + return new LiteralExact(new BigDecimal(value)); + } + @NotNull public BigDecimal getDecimal() { return value; diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt index 190c03915..c7b63f9cb 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt @@ -173,6 +173,9 @@ internal object RexConverter { is LiteralString -> stringValue(value) is LiteralBool -> boolValue(value) is LiteralExact -> { + // TODO previous behavior inferred decimals with scale = 0 to be a PartiQLValue.IntValue with + // PType of numeric. Since we're keeping numeric and decimal, need to take another look at + // whether the literal should have type decimal or numeric. val dec = this.decimal if (dec.scale() == 0) { intValue(dec.toBigInteger()) @@ -182,11 +185,12 @@ internal object RexConverter { } is LiteralInteger -> { val n = this.integer - // 1st, try parse as int - try { - val v = n.toInt() - int32Value(v) - } catch (ex: NumberFormatException) { + // try parsing as an int32 to preserve previous behavior. + // we could add always remove or add further narrowing + if (n in Int.MIN_VALUE..Int.MAX_VALUE) { + int32Value(n.toInt()) + } else { + // keep as an int64 int64Value(n) } }