Skip to content

Commit

Permalink
Fix failing conformance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Dec 5, 2024
1 parent 4b9249f commit 4bd73cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
* TODO DOCS
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 4bd73cf

Please sign in to comment.