@@ -48,11 +48,11 @@ public class OracleSourceDBRecordUnitTest {
4848
4949 /**
5050 * Validate the precision less Numbers handling against following use cases.
51- * 1. Ensure that for Number(0,-127) non nullable type a Number(38,0) is returned by default.
52- * 2. Ensure that for Number(0,-127) non nullable type a Number(38,4) is returned,
51+ * 1. Ensure that for Number(0,-127) non nullable type a String is returned by default.
52+ * 2. Ensure that for Number(0,-127) non nullable type a String is returned,
5353 * if schema defined this as Number(38,4).
54- * 3. Ensure that for Number(0,-127) nullable type a Number(38,0) is returned by default.
55- * 4. Ensure that for Number(0,-127) nullable type a Number(38,4) is returned,
54+ * 3. Ensure that for Number(0,-127) nullable type a String type is returned by default.
55+ * 4. Ensure that for Number(0,-127) nullable type a String is returned,
5656 * if schema defined this as Number(38,4).
5757 * @throws Exception
5858 */
@@ -72,10 +72,10 @@ public void validatePrecisionLessDecimalParsing() throws Exception {
7272 );
7373
7474 when (resultSet .getMetaData ()).thenReturn (resultSetMetaData );
75- when (resultSet .getBigDecimal (eq (1 ), eq ( 0 ))) .thenReturn (new BigDecimal ( "123" ) );
76- when (resultSet .getBigDecimal (eq (2 ), eq ( 4 ))) .thenReturn (new BigDecimal ( "123.4568" ) );
77- when (resultSet .getBigDecimal (eq (3 ), eq ( 0 ))) .thenReturn (new BigDecimal ( "123" ) );
78- when (resultSet .getBigDecimal (eq (4 ), eq ( 4 ))) .thenReturn (new BigDecimal ( "123.4568" ) );
75+ when (resultSet .getString (eq (1 ))) .thenReturn ("123" );
76+ when (resultSet .getString (eq (2 ))) .thenReturn ("123.4568" );
77+ when (resultSet .getString (eq (3 ))) .thenReturn ("123" );
78+ when (resultSet .getString (eq (4 ))) .thenReturn ("123.4568" );
7979
8080 StructuredRecord .Builder builder = StructuredRecord .builder (schema );
8181 OracleSourceDBRecord dbRecord = new OracleSourceDBRecord (null , null );
@@ -85,9 +85,62 @@ public void validatePrecisionLessDecimalParsing() throws Exception {
8585 dbRecord .handleField (resultSet , builder , field4 , 4 , Types .NUMERIC , 0 , -127 );
8686
8787 StructuredRecord record = builder .build ();
88+ Assert .assertTrue (record .get ("ID1" ) instanceof String );
89+ Assert .assertEquals (record .get ("ID1" ), "123" );
90+ Assert .assertTrue (record .get ("ID2" ) instanceof String );
91+ Assert .assertEquals (record .get ("ID2" ), "123.4568" );
92+ Assert .assertTrue (record .get ("ID3" ) instanceof String );
93+ Assert .assertEquals (record .get ("ID3" ), "123" );
94+ Assert .assertTrue (record .get ("ID4" ) instanceof String );
95+ Assert .assertEquals (record .get ("ID4" ), "123.4568" );
96+ }
97+
98+ /**
99+ * Validate the default precision Numbers handling against following use cases.
100+ * 1. Ensure that for Number(38, 0) non nullable type a Number(38,0) is returned.
101+ * 2. Ensure that for Number(38, 4) non nullable type a Number(38,6) is returned,
102+ * if schema defined this as Number(38,6).
103+ * 3. Ensure that for Number(38, 0) nullable type a Number(38,0) is returned by default.
104+ * 4. Ensure that for Number(38, 4) nullable type a Number(38,6) is returned,
105+ * if schema defined this as Number(38,6).
106+ * @throws Exception
107+ */
108+ @ Test
109+ public void validateDefaultDecimalParsing () throws Exception {
110+ Schema .Field field1 = Schema .Field .of ("ID1" , Schema .decimalOf (DEFAULT_PRECISION ));
111+ Schema .Field field2 = Schema .Field .of ("ID2" , Schema .decimalOf (DEFAULT_PRECISION , 6 ));
112+ Schema .Field field3 = Schema .Field .of ("ID3" , Schema .nullableOf (Schema .decimalOf (DEFAULT_PRECISION )));
113+ Schema .Field field4 = Schema .Field .of ("ID4" , Schema .nullableOf (Schema .decimalOf (DEFAULT_PRECISION , 6 )));
114+
115+ Schema schema = Schema .recordOf (
116+ "dbRecord" ,
117+ field1 ,
118+ field2 ,
119+ field3 ,
120+ field4
121+ );
122+
123+ when (resultSet .getMetaData ()).thenReturn (resultSetMetaData );
124+ when (resultSet .getBigDecimal (eq (1 ), eq (0 ))).thenReturn (new BigDecimal ("123" ));
125+ when (resultSet .getBigDecimal (eq (2 ), eq (6 ))).thenReturn (new BigDecimal ("123.456789" ));
126+ when (resultSet .getBigDecimal (eq (3 ), eq (0 ))).thenReturn (new BigDecimal ("123" ));
127+ when (resultSet .getBigDecimal (eq (4 ), eq (6 ))).thenReturn (new BigDecimal ("123.456789" ));
128+
129+ StructuredRecord .Builder builder = StructuredRecord .builder (schema );
130+ OracleSourceDBRecord dbRecord = new OracleSourceDBRecord (null , null );
131+ dbRecord .handleField (resultSet , builder , field1 , 1 , Types .NUMERIC , DEFAULT_PRECISION , 0 );
132+ dbRecord .handleField (resultSet , builder , field2 , 2 , Types .NUMERIC , DEFAULT_PRECISION , 4 );
133+ dbRecord .handleField (resultSet , builder , field3 , 3 , Types .NUMERIC , DEFAULT_PRECISION , 0 );
134+ dbRecord .handleField (resultSet , builder , field4 , 4 , Types .NUMERIC , DEFAULT_PRECISION , 4 );
135+
136+ StructuredRecord record = builder .build ();
137+ Assert .assertTrue (record .getDecimal ("ID1" ) instanceof BigDecimal );
88138 Assert .assertEquals (record .getDecimal ("ID1" ).toPlainString (), "123" );
89- Assert .assertEquals (record .getDecimal ("ID2" ).toPlainString (), "123.4568" );
139+ Assert .assertTrue (record .getDecimal ("ID2" ) instanceof BigDecimal );
140+ Assert .assertEquals (record .getDecimal ("ID2" ).toPlainString (), "123.456789" );
141+ Assert .assertTrue (record .getDecimal ("ID3" ) instanceof BigDecimal );
90142 Assert .assertEquals (record .getDecimal ("ID3" ).toPlainString (), "123" );
91- Assert .assertEquals (record .getDecimal ("ID4" ).toPlainString (), "123.4568" );
143+ Assert .assertTrue (record .getDecimal ("ID4" ) instanceof BigDecimal );
144+ Assert .assertEquals (record .getDecimal ("ID4" ).toPlainString (), "123.456789" );
92145 }
93146}
0 commit comments