Skip to content

Commit

Permalink
TEIID-5368 allowing the json parser to work with larger numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 8, 2018
1 parent ae502aa commit c766b0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions engine/src/main/java/org/teiid/json/simple/Yylex.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package org.teiid.json.simple;

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

class Yylex {

/** This character denotes the end of file */
Expand Down Expand Up @@ -605,7 +608,7 @@ else if (zzAtEOF) {
}
case 32: break;
case 21:
{ Double val=Double.valueOf(yytext()); return new Yytoken(val);
{ BigDecimal val=new BigDecimal(yytext()); return new Yytoken(val);
}
case 33: break;
case 1:
Expand Down Expand Up @@ -659,7 +662,12 @@ else if (zzAtEOF) {
}
case 44: break;
case 2:
{ Long val=Long.valueOf(yytext()); return new Yytoken(val);
{
try {
Long val=Long.valueOf(yytext()); return new Yytoken(val);
} catch (NumberFormatException e) {
BigInteger val=new BigInteger(yytext()); return new Yytoken(val);
}
}
case 45: break;
case 18:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,19 @@ public static BlobType blobFromFile(final String file) {
processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(b));
}

@Test public void testLargeNumeric() throws Exception {
String sql = "select * from xmltable('/num' passing jsontoxml('num', '{\"a\":12345678901234567890, \"b\":12345678901234567890.0}') columns x string path 'a', y string path 'b') as x"; //$NON-NLS-1$

List<?>[] expected = new List<?>[] {
Arrays.asList("12345678901234567890", "12345678901234567890.0"),
};

Blob b = BlobType.createBlob(("{ \"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\", \"state\": \"NY\", "+
"\"postalCode\": \"10021\" }, \"phoneNumber\": [ { \"type\": \"home\", \"number\": \"212 555-1234\" }, { \"type\": \"fax\", \"number\": \"646 555-4567\" } ] }").getBytes(Charset.forName("UTF-8")));

processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(b));
}

@Test public void testStaxComment() throws Exception {
String sql = "select * from xmltable('/*:Person/phoneNumber' passing cast(? as xml) columns x string path 'type', y string path 'number') as x"; //$NON-NLS-1$

Expand Down

0 comments on commit c766b0a

Please sign in to comment.