Skip to content

Commit

Permalink
Merge pull request #670 from data-integrations/numeric-token-fix
Browse files Browse the repository at this point in the history
Fix grammar to identify and tokenize negative numbers
  • Loading branch information
vanathi-g authored Sep 26, 2023
2 parents ae63527 + c576d73 commit 6562f87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Space
;

fragment Int
: [1-9] Digit* [L]*
: '-'? [1-9] Digit* [L]*
| '0'
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ public void testToDecimalWithRound() throws Exception {
Assert.assertEquals(row.getValue(1), new BigDecimal("456"));
}

@Test
public void testToDecimalNegativeScale() throws Exception {
List<Row> rows = Collections.singletonList(new Row("scale_2", "125.45"));
String[] directives = new String[] {"set-type scale_2 decimal -1 'HALF_UP'"};
List<Row> results = TestingRig.execute(directives, rows);
Row row = results.get(0);

Assert.assertTrue(row.getValue(0) instanceof BigDecimal);
Assert.assertEquals(row.getValue(0), new BigDecimal("1.3E+2"));
}

@Test(expected = RecipeException.class)
public void testToDecimalRoundingRequired() throws Exception {
List<Row> rows = Collections.singletonList(new Row("scale_2", "123.45"));
Expand Down

0 comments on commit 6562f87

Please sign in to comment.