@@ -181,6 +181,101 @@ public void testNestedArrays()
181
181
tester .testRoundTrip (objectInspector , values , values , type );
182
182
}
183
183
184
+ @ Test
185
+ public void testNestedArraysDecimalBackedByINT32 ()
186
+ throws Exception
187
+ {
188
+ int precision = 1 ;
189
+ int scale = 0 ;
190
+ ObjectInspector objectInspector = getStandardListObjectInspector (javaIntObjectInspector );
191
+ Type type = new ArrayType (createDecimalType (precision , scale ));
192
+ Iterable <List <Integer >> values = createTestArrays (intsBetween (1 , 1_000 ));
193
+
194
+ List <List <SqlDecimal >> expectedValues = new ArrayList <>();
195
+ for (List <Integer > value : values ) {
196
+ List <SqlDecimal > expectedDecimal = new ArrayList <>();
197
+ for (Integer valueInt : value ) {
198
+ expectedDecimal .add (SqlDecimal .of (valueInt , precision , scale ));
199
+ }
200
+ expectedValues .add (expectedDecimal );
201
+ }
202
+
203
+ MessageType hiveSchema = parseMessageType (format ("message hive_list_decimal {" +
204
+ " optional group my_list (LIST){" +
205
+ " repeated group list {" +
206
+ " optional INT32 element (DECIMAL(%d, %d));" +
207
+ " }" +
208
+ " }" +
209
+ "} " , precision , scale ));
210
+
211
+ tester .testRoundTrip (objectInspector , values , expectedValues , "my_list" , type , Optional .of (hiveSchema ));
212
+ }
213
+
214
+ @ Test
215
+ public void testNestedArraysDecimalBackedByINT64 ()
216
+ throws Exception
217
+ {
218
+ int precision = 10 ;
219
+ int scale = 2 ;
220
+ ObjectInspector objectInspector = getStandardListObjectInspector (javaLongObjectInspector );
221
+ Type type = new ArrayType (createDecimalType (precision , scale ));
222
+ Iterable <List <Long >> values = createTestArrays (longsBetween (1 , 1_000 ));
223
+
224
+ List <List <SqlDecimal >> expectedValues = new ArrayList <>();
225
+ for (List <Long > value : values ) {
226
+ List <SqlDecimal > expectedDecimal = new ArrayList <>();
227
+ for (Long valueLong : value ) {
228
+ expectedDecimal .add (SqlDecimal .of (valueLong , precision , scale ));
229
+ }
230
+ expectedValues .add (expectedDecimal );
231
+ }
232
+
233
+ MessageType hiveSchema = parseMessageType (format ("message hive_list_decimal {" +
234
+ " optional group my_list (LIST){" +
235
+ " repeated group list {" +
236
+ " optional INT64 element (DECIMAL(%d, %d));" +
237
+ " }" +
238
+ " }" +
239
+ "} " , precision , scale ));
240
+ tester .testRoundTrip (objectInspector , values , expectedValues , "my_list" , type , Optional .of (hiveSchema ));
241
+ }
242
+
243
+ @ Test
244
+ public void testNestedArraysShortDecimalBackedByBinary ()
245
+ throws Exception
246
+ {
247
+ int precision = 1 ;
248
+ int scale = 0 ;
249
+ ObjectInspector objectInspector = getStandardListObjectInspector (new JavaHiveDecimalObjectInspector (new DecimalTypeInfo (precision , scale )));
250
+ Type type = new ArrayType (createDecimalType (precision , scale ));
251
+ ContiguousSet <BigInteger > bigIntegerValues = bigIntegersBetween (BigDecimal .valueOf (Math .pow (10 , precision - 1 )).toBigInteger (),
252
+ BigDecimal .valueOf (Math .pow (10 , precision )).toBigInteger ());
253
+ ImmutableList .Builder <HiveDecimal > writeValues = new ImmutableList .Builder <>();
254
+ for (BigInteger value : limit (bigIntegerValues , 1_000 )) {
255
+ writeValues .add (HiveDecimal .create (value , scale ));
256
+ }
257
+ Iterable <List <HiveDecimal >> values = createTestArrays (writeValues .build ());
258
+
259
+ List <List <SqlDecimal >> expectedValues = new ArrayList <>();
260
+ for (List <HiveDecimal > value : values ) {
261
+ List <SqlDecimal > expectedDecimal = new ArrayList <>();
262
+ for (HiveDecimal valueHiveDecimal : value ) {
263
+ expectedDecimal .add (new SqlDecimal (valueHiveDecimal .unscaledValue (), precision , scale ));
264
+ }
265
+ expectedValues .add (expectedDecimal );
266
+ }
267
+
268
+ MessageType hiveSchema = parseMessageType (format ("message hive_list_decimal {" +
269
+ " optional group my_list (LIST){" +
270
+ " repeated group list {" +
271
+ " optional BINARY element (DECIMAL(%d, %d));" +
272
+ " }" +
273
+ " }" +
274
+ "} " , precision , scale ));
275
+
276
+ tester .testRoundTrip (objectInspector , values , expectedValues , "my_list" , type , Optional .of (hiveSchema ));
277
+ }
278
+
184
279
@ Test
185
280
public void testSingleLevelSchemaNestedArrays ()
186
281
throws Exception
0 commit comments