From 2807c2bc1870e8b5d18c824b1f54301ad77899a9 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Thu, 12 Sep 2024 14:25:45 +0100 Subject: [PATCH] fix: potential fix for decimal template error Signed-off-by: Andrew Coleman --- .../java/io/substrait/type/parser/ParseToPojo.java | 10 ++++++++++ .../java/io/substrait/type/parser/TestTypeParser.java | 3 +++ 2 files changed, 13 insertions(+) diff --git a/core/src/main/java/io/substrait/type/parser/ParseToPojo.java b/core/src/main/java/io/substrait/type/parser/ParseToPojo.java index d68dbae60..d27bd03e2 100644 --- a/core/src/main/java/io/substrait/type/parser/ParseToPojo.java +++ b/core/src/main/java/io/substrait/type/parser/ParseToPojo.java @@ -261,6 +261,16 @@ public TypeExpression visitDecimal(final SubstraitTypeParser.DecimalContext ctx) return withNullP(nullable).decimalE((String) precision, (String) scale); } + if (precision instanceof String && scale instanceof Integer) { + checkParameterizedOrExpression(); + return withNullP(nullable).decimalE((String) precision, String.valueOf(scale)); + } + + if (precision instanceof Integer && scale instanceof String) { + checkParameterizedOrExpression(); + return withNullP(nullable).decimalE(String.valueOf(precision), (String) scale); + } + checkExpression(); return withNullE(nullable).decimalE(ctx.precision.accept(this), ctx.scale.accept(this)); } diff --git a/core/src/test/java/io/substrait/type/parser/TestTypeParser.java b/core/src/test/java/io/substrait/type/parser/TestTypeParser.java index 56a6ce51f..980c494cd 100644 --- a/core/src/test/java/io/substrait/type/parser/TestTypeParser.java +++ b/core/src/test/java/io/substrait/type/parser/TestTypeParser.java @@ -119,6 +119,9 @@ private void parameterizedTests(ParseToPojo.Visitor v) { test(v, pn.listE(pr.parameter("any")), "list?"); test(v, pn.listE(pn.parameter("any")), "list?"); test(v, pn.structE(r.I8, r.I16, n.I8, pr.parameter("K")), "STRUCT?"); + test(v, pr.decimalE("P", "S"), "DECIMAL"); + test(v, pr.decimalE("P", "0"), "DECIMAL"); + test(v, pr.decimalE("14", "S"), "DECIMAL<14, S>"); } private static void test(ParseToPojo.Visitor visitor, TypeExpression expected, String toParse) {