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) {