Skip to content

Commit

Permalink
fix: decimal parsing reversed (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarua authored Jan 31, 2023
1 parent 63cfcb3 commit 35aa306
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/main/antlr/SubstraitType.g4
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ parameterizedType
: FixedChar isnull='?'? Lt len=numericParameter Gt #fixedChar
| VarChar isnull='?'? Lt len=numericParameter Gt #varChar
| FixedBinary isnull='?'? Lt len=numericParameter Gt #fixedBinary
| Decimal isnull='?'? Lt scale=numericParameter Comma precision=numericParameter Gt #decimal
| Decimal isnull='?'? Lt precision=numericParameter Comma scale=numericParameter Gt #decimal
| Struct isnull='?'? Lt expr (Comma expr)* Gt #struct
| NStruct isnull='?'? Lt Identifier expr (Comma Identifier expr)* Gt #nStruct
| List isnull='?'? Lt expr Gt #list
Expand Down
48 changes: 46 additions & 2 deletions core/src/test/java/io/substrait/type/parser/TestTypeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ public void basic() {
simpleTests(ParseToPojo.Visitor.SIMPLE);
}

@Test
public void compound() {
compoundTests(ParseToPojo.Visitor.SIMPLE);
}

@Test
public void parameterizedSimple() {
simpleTests(ParseToPojo.Visitor.PARAMETERIZED);
}

@Test
public void parameterizedCompound() {
compoundTests(ParseToPojo.Visitor.PARAMETERIZED);
}

@Test
public void parameterizedParameterized() {
parameterizedTests(ParseToPojo.Visitor.PARAMETERIZED);
Expand All @@ -40,6 +50,11 @@ public void derivationSimple() {
simpleTests(ParseToPojo.Visitor.EXPRESSION);
}

@Test
public void derivationCompound() {
compoundTests(ParseToPojo.Visitor.EXPRESSION);
}

@Test
public void derivationParameterized() {
parameterizedTests(ParseToPojo.Visitor.EXPRESSION);
Expand All @@ -58,10 +73,39 @@ public void derivationExpression() {
}

private <T> void simpleTests(ParseToPojo.Visitor v) {
test(v, r.I8, "I8");
test(v, r.I16, "I16");
test(v, r.I32, "I32");
test(v, r.I64, "I64");
test(v, r.FP32, "FP32");
test(v, r.FP64, "FP64");

// Nullable
test(v, n.I8, "I8?");
test(v, n.I32, "I32?");
test(v, n.I16, "I16?");
test(v, n.I32, "i32?");
test(v, r.I8, "I8");
test(v, n.I64, "i64?");
test(v, n.FP32, "FP32?");
test(v, n.FP64, "FP64?");
}

private void compoundTests(ParseToPojo.Visitor v) {
test(v, r.fixedChar(1), "FIXEDCHAR<1>");
test(v, r.varChar(2), "VARCHAR<2>");
test(v, r.fixedBinary(3), "FIXEDBINARY<3>");
test(v, r.decimal(1, 2), "DECIMAL<1, 2>");
test(v, r.struct(r.I8, r.I16), "STRUCT<i8, i16>");
test(v, r.list(r.I8), "LIST<i8>");
test(v, r.map(r.I16, r.I8), "MAP<i16, i8>");

// Nullable
test(v, n.fixedChar(1), "FIXEDCHAR?<1>");
test(v, n.varChar(2), "VARCHAR?<2>");
test(v, n.fixedBinary(3), "FIXEDBINARY?<3>");
test(v, n.decimal(1, 2), "DECIMAL?<1, 2>");
test(v, n.struct(r.I8, n.I16), "STRUCT?<i8, i16?>");
test(v, n.list(n.I8), "LIST?<i8?>");
test(v, n.map(r.I16, n.I8), "MAP?<i16, i8?>");
}

private <T> void parameterizedTests(ParseToPojo.Visitor v) {
Expand Down

0 comments on commit 35aa306

Please sign in to comment.