38
38
import org .hpccsystems .commons .ecl .HpccSrcType ;
39
39
import org .hpccsystems .commons .ecl .RecordDefinitionTranslator ;
40
40
import org .hpccsystems .commons .errors .HpccFileException ;
41
+ import org .hpccsystems .commons .utils .Utils ;
41
42
import org .hpccsystems .ws .client .HPCCWsDFUClient ;
42
43
import org .hpccsystems .ws .client .HPCCWsWorkUnitsClient ;
43
44
import org .hpccsystems .ws .client .wrappers .wsworkunits .WorkunitWrapper ;
@@ -275,7 +276,6 @@ public void getNullMetadataTest() throws Exception
275
276
assertNull ("Meta should be null for nonexistent file" ,meta );
276
277
}
277
278
278
-
279
279
private static final String ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_" ;
280
280
private static final SecureRandom RANDOM = new SecureRandom ();
281
281
@@ -334,6 +334,87 @@ public void integrationLargeRecordTest() throws Exception
334
334
}
335
335
}
336
336
}
337
+
338
+ @ Test
339
+ public void unsigned8ToDecimalTest () throws Exception
340
+ {
341
+ // Create a large record dataset
342
+ FieldDef [] fieldDefs = new FieldDef [3 ];
343
+ fieldDefs [0 ] = new FieldDef ("field1" , FieldType .INTEGER , "UNSIGNED8" , 8 , true , true , HpccSrcType .LITTLE_ENDIAN , new FieldDef [0 ]);
344
+ fieldDefs [1 ] = new FieldDef ("field2" , FieldType .INTEGER , "UNSIGNED8" , 8 , true , true , HpccSrcType .LITTLE_ENDIAN , new FieldDef [0 ]);
345
+ fieldDefs [2 ] = new FieldDef ("field3" , FieldType .INTEGER , "UNSIGNED8" , 8 , true , true , HpccSrcType .LITTLE_ENDIAN , new FieldDef [0 ]);
346
+ FieldDef recordDef = new FieldDef ("RootRecord" , FieldType .RECORD , "rec" , 4 , false , false , HpccSrcType .LITTLE_ENDIAN , fieldDefs );
347
+
348
+ List <HPCCRecord > originalRecords = new ArrayList <HPCCRecord >();
349
+ for (int i = 0 ; i < 10 ; i ++)
350
+ {
351
+ Object [] fields = new Object [3 ];
352
+ fields [0 ] = new BigDecimal (Utils .extractUnsigned8Val ((long ) Long .MIN_VALUE )); // Max U8 value
353
+ fields [1 ] = new BigDecimal (0 ); // Min U8 value
354
+ fields [2 ] = new BigDecimal (BigInteger .valueOf (Long .MAX_VALUE ).add (BigInteger .ONE )); // First U8 value that would cause an overflow
355
+ HPCCRecord record = new HPCCRecord (fields , recordDef );
356
+ originalRecords .add (record );
357
+ }
358
+
359
+ String datasetName = "benchmark::unsigned8::10rows" ;
360
+ writeFile (originalRecords , datasetName , recordDef , connTO );
361
+
362
+ HPCCFile file = new HPCCFile (datasetName , connString , hpccUser , hpccPass );
363
+ List <HPCCRecord > readRecords = readFile (file , connTO , false , true );
364
+ if (readRecords .size () < 10 )
365
+ {
366
+ Assert .fail ("Failed to read " + datasetName );
367
+ }
368
+
369
+ for (int i = 0 ; i < 10 ; i ++)
370
+ {
371
+ HPCCRecord readRecord = readRecords .get (i );
372
+ HPCCRecord originalRecord = originalRecords .get (i );
373
+
374
+ assertEquals (readRecord , originalRecord );
375
+ }
376
+ }
377
+
378
+ @ Test
379
+ public void longStringTest () throws Exception
380
+ {
381
+ // Create a large record dataset
382
+ FieldDef [] fieldDefs = new FieldDef [4 ];
383
+ fieldDefs [0 ] = new FieldDef ("LongVarUnicode" , FieldType .VAR_STRING , "" , 4 , false , false , HpccSrcType .UTF16LE , new FieldDef [0 ]);
384
+ fieldDefs [1 ] = new FieldDef ("LongUnicode" , FieldType .STRING , "" , 64 , true , false , HpccSrcType .UTF16LE , new FieldDef [0 ]);
385
+ fieldDefs [2 ] = new FieldDef ("LongVarString" , FieldType .VAR_STRING , "" , 4 , false , false , HpccSrcType .SINGLE_BYTE_CHAR , new FieldDef [0 ]);
386
+ fieldDefs [3 ] = new FieldDef ("LongString" , FieldType .STRING , "" , 64 , true , false , HpccSrcType .SINGLE_BYTE_CHAR , new FieldDef [0 ]);
387
+ FieldDef recordDef = new FieldDef ("RootRecord" , FieldType .RECORD , "rec" , 4 , false , false , HpccSrcType .LITTLE_ENDIAN , fieldDefs );
388
+
389
+ List <HPCCRecord > originalRecords = new ArrayList <HPCCRecord >();
390
+ for (int i = 0 ; i < 10 ; i ++)
391
+ {
392
+ Object [] fields = new Object [4 ];
393
+ fields [0 ] = generateRandomString (1024 );
394
+ fields [1 ] = generateRandomString (64 );
395
+ fields [2 ] = generateRandomString (1024 );
396
+ fields [3 ] = generateRandomString (64 );
397
+ HPCCRecord record = new HPCCRecord (fields , recordDef );
398
+ originalRecords .add (record );
399
+ }
400
+
401
+ String datasetName = "benchmark::long_string::10rows" ;
402
+ writeFile (originalRecords , datasetName , recordDef ,connTO );
403
+
404
+ HPCCFile file = new HPCCFile (datasetName , connString , hpccUser , hpccPass );
405
+ List <HPCCRecord > readRecords = readFile (file , connTO , false );
406
+ if (readRecords .size () < 10 )
407
+ {
408
+ Assert .fail ("Failed to read " + datasetName + " dataset" );
409
+ }
410
+
411
+ for (int i = 0 ; i < 10 ; i ++)
412
+ {
413
+ HPCCRecord originalRecord = originalRecords .get (i );
414
+ HPCCRecord readRecord = originalRecords .get (i );
415
+ Assert .assertEquals (originalRecord , readRecord );
416
+ }
417
+ }
337
418
338
419
@ Test
339
420
public void numericOverflowTest () throws Exception
@@ -703,15 +784,22 @@ public void resumeFileReadTest() throws Exception
703
784
}
704
785
705
786
public List <HPCCRecord > readFile (HPCCFile file , Integer connectTimeoutMillis , boolean shouldForceTimeout ) throws Exception
787
+ {
788
+ return readFile (file , connectTimeoutMillis , shouldForceTimeout , false );
789
+ }
790
+
791
+ public List <HPCCRecord > readFile (HPCCFile file , Integer connectTimeoutMillis , boolean shouldForceTimeout , boolean useDecimalForUnsigned8 ) throws Exception
706
792
{
707
793
if (file == null )
708
794
{
709
795
Assert .fail ("HPCCFile construction failed." );
710
796
}
797
+
711
798
if (connectTimeoutMillis != null )
712
799
{
713
800
file .setFileAccessExpirySecs (connectTimeoutMillis /1000 );
714
801
}
802
+
715
803
DataPartition [] fileParts = file .getFileParts ();
716
804
if (fileParts == null || fileParts .length == 0 )
717
805
{
@@ -731,6 +819,8 @@ public List<HPCCRecord> readFile(HPCCFile file, Integer connectTimeoutMillis, bo
731
819
{
732
820
HPCCRecordBuilder recordBuilder = new HPCCRecordBuilder (file .getProjectedRecordDefinition ());
733
821
HpccRemoteFileReader <HPCCRecord > fileReader = new HpccRemoteFileReader <HPCCRecord >(fileParts [i ], originalRD , recordBuilder );
822
+ fileReader .getRecordReader ().setUseDecimalForUnsigned8 (useDecimalForUnsigned8 );
823
+
734
824
fileReaders .add (fileReader );
735
825
}
736
826
catch (Exception e )
0 commit comments