@@ -424,40 +424,45 @@ private QueryExpression rewriteUpdateQueryForCompositeSearch(CompositeMetadata m
424
424
CompositeFindImpl finder = new CompositeFindImpl (md );
425
425
finder .setParallelism (9 );
426
426
CRUDFindResponse response = finder .find (findCtx , freq .getCRUDFindRequest ());
427
- DocumentStream <DocCtx > docStream = findCtx .getDocumentStream ();
428
-
429
- // Now write a query
430
- List <QueryExpression > orq = new ArrayList <>();
431
- for (;docStream .hasNext ();) {
432
- DocCtx doc =docStream .next ();
433
- if (!doc .hasErrors ()) {
434
- DocId id = docIdx .getDocId (doc );
435
- List <QueryExpression > idList = new ArrayList <>(identityFields .length );
436
- for (int ix = 0 ; ix < identityFields .length ; ix ++) {
437
- if (!identityFields [ix ].equals (PredefinedFields .OBJECTTYPE_PATH )) {
438
- Object value = id .getValue (ix );
439
- idList .add (new ValueComparisonExpression (identityFields [ix ],
440
- BinaryComparisonOperator ._eq ,
441
- new Value (value )));
427
+ if (findCtx .hasErrors ()) {
428
+ ctx .addErrors (findCtx .getErrors ());
429
+ } else {
430
+ DocumentStream <DocCtx > docStream = findCtx .getDocumentStream ();
431
+
432
+ // Now write a query
433
+ List <QueryExpression > orq = new ArrayList <>();
434
+ for (;docStream .hasNext ();) {
435
+ DocCtx doc =docStream .next ();
436
+ if (!doc .hasErrors ()) {
437
+ DocId id = docIdx .getDocId (doc );
438
+ List <QueryExpression > idList = new ArrayList <>(identityFields .length );
439
+ for (int ix = 0 ; ix < identityFields .length ; ix ++) {
440
+ if (!identityFields [ix ].equals (PredefinedFields .OBJECTTYPE_PATH )) {
441
+ Object value = id .getValue (ix );
442
+ idList .add (new ValueComparisonExpression (identityFields [ix ],
443
+ BinaryComparisonOperator ._eq ,
444
+ new Value (value )));
445
+ }
442
446
}
447
+ QueryExpression idq ;
448
+ if (idList .size () == 1 ) {
449
+ idq = idList .get (0 );
450
+ } else {
451
+ idq = new NaryLogicalExpression (NaryLogicalOperator ._and , idList );
452
+ }
453
+ orq .add (idq );
443
454
}
444
- QueryExpression idq ;
445
- if (idList .size () == 1 ) {
446
- idq = idList .get (0 );
447
- } else {
448
- idq = new NaryLogicalExpression (NaryLogicalOperator ._and , idList );
449
- }
450
- orq .add (idq );
455
+ }
456
+ docStream .close ();
457
+ if (orq .isEmpty ()) {
458
+ return null ;
459
+ } else if (orq .size () == 1 ) {
460
+ return orq .get (0 );
461
+ } else {
462
+ return new NaryLogicalExpression (NaryLogicalOperator ._or , orq );
451
463
}
452
464
}
453
- docStream .close ();
454
- if (orq .isEmpty ()) {
455
- return null ;
456
- } else if (orq .size () == 1 ) {
457
- return orq .get (0 );
458
- } else {
459
- return new NaryLogicalExpression (NaryLogicalOperator ._or , orq );
460
- }
465
+ return null ;
461
466
}
462
467
463
468
/**
@@ -499,25 +504,25 @@ public Response find(FindRequest req) {
499
504
CRUDFindResponse result = finder .find (ctx , req .getCRUDFindRequest ());
500
505
ctx .measure .end ("finder.find" );
501
506
502
- ctx .measure .begin ("postProcessFound" );
503
- DocumentStream <DocCtx > docStream =ctx .getDocumentStream ();
504
- List <ResultMetadata > rmd =new ArrayList <>();
505
- response .setEntityData (factory .getNodeFactory ().arrayNode ());
506
- for (;docStream .hasNext ();) {
507
- DocCtx doc =docStream .next ();
508
- if (!doc .hasErrors ()) {
509
- response .addEntityData (doc .getOutputDocument ().getRoot ());
510
- rmd .add (doc .getResultMetadata ());
507
+ if (!ctx .hasErrors ()) {
508
+ ctx .measure .begin ("postProcessFound" );
509
+ DocumentStream <DocCtx > docStream =ctx .getDocumentStream ();
510
+ List <ResultMetadata > rmd =new ArrayList <>();
511
+ response .setEntityData (factory .getNodeFactory ().arrayNode ());
512
+ for (;docStream .hasNext ();) {
513
+ DocCtx doc =docStream .next ();
514
+ if (!doc .hasErrors ()) {
515
+ response .addEntityData (doc .getOutputDocument ().getRoot ());
516
+ rmd .add (doc .getResultMetadata ());
511
517
} else {
512
- DataError error =doc .getDataError ();
513
- if (error !=null )
514
- response .getDataErrors ().add (error );
518
+ DataError error =doc .getDataError ();
519
+ if (error !=null )
520
+ response .getDataErrors ().add (error );
521
+ }
515
522
}
516
- }
517
- docStream .close ();
518
- response .setResultMetadata (rmd );
519
- ctx .measure .end ("postProcessFound" );
520
- if (!ctx .hasErrors ()) {
523
+ docStream .close ();
524
+ response .setResultMetadata (rmd );
525
+ ctx .measure .end ("postProcessFound" );
521
526
ctx .setStatus (OperationStatus .COMPLETE );
522
527
} else {
523
528
ctx .setStatus (OperationStatus .ERROR );
@@ -793,23 +798,25 @@ private List<DataError> setResponseResults(OperationContext ctx,
793
798
int t =to ==null ?Integer .MAX_VALUE :to .intValue ();
794
799
int ix =0 ;
795
800
DocumentStream <DocCtx > docStream =ctx .getDocumentStream ();
796
- List <ResultMetadata > rmd =new ArrayList <>();
797
- for (;docStream .hasNext ();) {
798
- DocCtx doc =docStream .next ();
799
- if (!doc .hasErrors ()) {
800
- if (ix >=f &&ix <=t ) {
801
- response .addEntityData (doc .getOutputDocument ().getRoot ());
802
- rmd .add (doc .getResultMetadata ());
801
+ if (docStream !=null ) {
802
+ List <ResultMetadata > rmd =new ArrayList <>();
803
+ for (;docStream .hasNext ();) {
804
+ DocCtx doc =docStream .next ();
805
+ if (!doc .hasErrors ()) {
806
+ if (ix >=f &&ix <=t ) {
807
+ response .addEntityData (doc .getOutputDocument ().getRoot ());
808
+ rmd .add (doc .getResultMetadata ());
809
+ }
810
+ ix ++;
811
+ } else {
812
+ DataError error =doc .getDataError ();
813
+ if (error !=null )
814
+ dataErrors .add (error );
803
815
}
804
- ix ++;
805
- } else {
806
- DataError error =doc .getDataError ();
807
- if (error !=null )
808
- dataErrors .add (error );
809
816
}
817
+ docStream .close ();
818
+ response .setResultMetadata (rmd );
810
819
}
811
- docStream .close ();
812
- response .setResultMetadata (rmd );
813
820
return dataErrors ;
814
821
}
815
822
}
0 commit comments