@@ -271,12 +271,12 @@ void insert(
271271 arity = "0..*" ,
272272 paramLabel = "<files>" ,
273273 description = "/path/to/file.parquet" )
274- String [] dataFiles ,
274+ String [] files ,
275275 @ CommandLine .Option (
276- names = "--from-file " ,
276+ names = "--files-from " ,
277277 description =
278278 "Read list of parquet files from the specified file (one file per line)" )
279- String fromFile ,
279+ String filesFrom ,
280280 @ CommandLine .Option (
281281 names = "--no-copy" ,
282282 description = "Add files to catalog without copying them" )
@@ -324,6 +324,11 @@ void insert(
324324 "/path/to/file where to save list of files to retry"
325325 + " (useful for retrying partially failed insert using `cat ice.retry | ice insert - --retry-list=ice.retry`)" )
326326 String retryList ,
327+ @ CommandLine .Option (
328+ names = {"--retry-list-exit-code" },
329+ description =
330+ "Exit code to return when insert produces non-empty --retry-list file (default: 0)" )
331+ int retryListExitCode ,
327332 @ CommandLine .Option (
328333 names = {"--partition" },
329334 description =
@@ -361,27 +366,30 @@ void insert(
361366 throw new UnsupportedOperationException (
362367 "--s3-no-sign-request + --s3-copy-object is not supported by AWS (see --help for details)" );
363368 }
369+ boolean filesSet = files != null && files .length > 0 ;
370+ boolean filesFromSet = !Strings .isNullOrEmpty (filesFrom );
371+ if (!filesSet && !filesFromSet ) {
372+ throw new IllegalArgumentException (
373+ "At least one <files> argument or --files-from is required" );
374+ }
375+ if (filesSet && filesFromSet ) {
376+ throw new IllegalArgumentException (
377+ "<files> arguments and --files-from are mutually exclusive" );
378+ }
364379 setAWSRegion (s3Region );
365380 try (RESTCatalog catalog = loadCatalog ()) {
366- // Handle --from-file option
367- if (!Strings .isNullOrEmpty (fromFile )) {
368- if (dataFiles != null && dataFiles .length > 0 ) {
369- throw new IllegalArgumentException ("Cannot specify both --from-file and file arguments" );
370- }
371- dataFiles = readInputFromFile (fromFile ).toArray (new String [0 ]);
372- if (dataFiles .length == 0 ) {
381+ if (filesFromSet ) {
382+ files = readInputFromFile (filesFrom ).toArray (new String [0 ]);
383+ if (files .length == 0 ) {
373384 logger .info ("Nothing to insert (file empty)" );
374385 return ;
375386 }
376- } else if (dataFiles != null && dataFiles .length == 1 && "-" .equals (dataFiles [0 ])) {
377- dataFiles = readInput ().toArray (new String [0 ]);
378- if (dataFiles .length == 0 ) {
387+ } else if (files .length == 1 && "-" .equals (files [0 ])) {
388+ files = readInput ().toArray (new String [0 ]);
389+ if (files .length == 0 ) {
379390 logger .info ("Nothing to insert (stdin empty)" );
380391 return ;
381392 }
382- } else if (dataFiles == null || dataFiles .length == 0 ) {
383- throw new IllegalArgumentException (
384- "No files specified. Provide files as arguments or use --from-file" );
385393 }
386394
387395 List <IcePartition > partitions = null ;
@@ -405,7 +413,7 @@ void insert(
405413 CreateTable .run (
406414 catalog ,
407415 tableId ,
408- dataFiles [0 ],
416+ files [0 ],
409417 null ,
410418 createTableIfNotExists ,
411419 useVendedCredentials ,
@@ -436,12 +444,14 @@ void insert(
436444 .build ();
437445
438446 if (!watchMode ) {
439- Insert .Result result = Insert .run (catalog , tableId , dataFiles , options );
440- if (result .anyFilesFailed ()) {
447+ Insert .Result result = Insert .run (catalog , tableId , files , options );
448+ if (! result .ok ()) {
441449 logger .error (
442- "{} file(s) failed to insert. Check logs or retry list for details." ,
443- result .failedCount ());
444- System .exit (1 );
450+ "{}/{} file(s) failed to insert (see {})" ,
451+ result .totalNumberOfFiles (),
452+ result .numberOfFilesFailedToInsert (),
453+ retryList );
454+ System .exit (retryListExitCode );
445455 }
446456 } else {
447457 if (!Strings .isNullOrEmpty (watchDebugAddr )) {
@@ -459,7 +469,7 @@ void insert(
459469 }
460470
461471 InsertWatch .run (
462- catalog , tableId , dataFiles , watch , watchFireOnce , createTableIfNotExists , options );
472+ catalog , tableId , files , watch , watchFireOnce , createTableIfNotExists , options );
463473 }
464474 }
465475 }
0 commit comments