4343import org .hypertrace .core .documentstore .Document ;
4444import org .hypertrace .core .documentstore .JSONDocument ;
4545import org .hypertrace .core .documentstore .Key ;
46- import org .hypertrace .core .documentstore .SingleValueKey ;
4746import org .hypertrace .core .documentstore .expression .impl .ConstantExpression ;
4847import org .hypertrace .core .documentstore .expression .impl .IdentifierExpression ;
4948import org .hypertrace .core .documentstore .expression .impl .LogicalExpression ;
@@ -155,7 +154,7 @@ public EntityQueryServiceImpl(
155154 entityChangeEventGenerator ,
156155 new EntityAttributeChangeEvaluator (config , entityAttributeMapping ),
157156 entityCounterMetricSender ,
158- entityTypeChannel ,
157+ EntityTypeClient . builder ( entityTypeChannel ). build () ,
159158 !config .hasPathOrNull (CHUNK_SIZE_CONFIG )
160159 ? DEFAULT_CHUNK_SIZE
161160 : config .getInt (CHUNK_SIZE_CONFIG ),
@@ -174,7 +173,7 @@ public EntityQueryServiceImpl(
174173 EntityChangeEventGenerator entityChangeEventGenerator ,
175174 EntityAttributeChangeEvaluator entityAttributeChangeEvaluator ,
176175 EntityCounterMetricSender entityCounterMetricSender ,
177- Channel entityTypeChannel ,
176+ EntityTypeClient entityTypeClient ,
178177 int chunkSize ,
179178 int maxEntitiesToDelete ,
180179 int maxStringLengthForUpdate ) {
@@ -186,7 +185,7 @@ public EntityQueryServiceImpl(
186185 entityAttributeChangeEvaluator ,
187186 entityCounterMetricSender ,
188187 new EntityFetcher (entitiesCollection , DOCUMENT_PARSER ),
189- entityTypeChannel ,
188+ entityTypeClient ,
190189 chunkSize ,
191190 maxEntitiesToDelete ,
192191 maxStringLengthForUpdate );
@@ -200,7 +199,7 @@ public EntityQueryServiceImpl(
200199 EntityAttributeChangeEvaluator entityAttributeChangeEvaluator ,
201200 EntityCounterMetricSender entityCounterMetricSender ,
202201 EntityFetcher entityFetcher ,
203- Channel entityTypeChannel ,
202+ EntityTypeClient entityTypeClient ,
204203 int chunkSize ,
205204 int maxEntitiesToDelete ,
206205 int maxStringLengthForUpdate ) {
@@ -213,7 +212,6 @@ public EntityQueryServiceImpl(
213212 this .entityFetcher = entityFetcher ;
214213 this .entityAttributeChangeEvaluator = entityAttributeChangeEvaluator ;
215214 this .entityCounterMetricSender = entityCounterMetricSender ;
216- EntityTypeClient entityTypeClient = EntityTypeClient .builder (entityTypeChannel ).build ();
217215 IdentifyingAttributeCache identifyingAttributeCache = new IdentifyingAttributeCache (datastore );
218216 this .entityNormalizer =
219217 new EntityNormalizer (entityTypeClient , new EntityIdGenerator (), identifyingAttributeCache );
@@ -457,14 +455,26 @@ public void bulkUpdateEntityArrayAttribute(
457455 responseObserver .onError (new ServiceException ("Tenant id is missing in the request." ));
458456 return ;
459457 }
458+
459+ if (StringUtils .isBlank (request .getEntityType ())) {
460+ LOG .warn ("Entity type is missing in bulk update entity array request" );
461+ responseObserver .onError (
462+ Status .INVALID_ARGUMENT
463+ .withDescription ("Entity type is missing in the request." )
464+ .asException ());
465+ return ;
466+ }
467+
460468 try {
461469 Set <Key > keys =
462470 request .getEntityIdsList ().stream ()
463- .map (entityId -> new SingleValueKey (tenantId , entityId ))
471+ .map (
472+ entityId ->
473+ this .entityNormalizer .getEntityDocKey (
474+ tenantId , request .getEntityType (), entityId ))
464475 .collect (Collectors .toCollection (LinkedHashSet ::new ));
465476
466477 String attributeId = request .getAttribute ().getColumnName ();
467-
468478 String subDocPath =
469479 entityAttributeMapping
470480 .getDocStorePathByAttributeId (requestContext , attributeId )
@@ -590,7 +600,8 @@ private void doBulkUpdate(
590600 continue ;
591601 }
592602 entitiesUpdateMap .put (
593- new SingleValueKey (requestContext .getTenantId ().orElseThrow (), entityId ),
603+ this .entityNormalizer .getEntityDocKey (
604+ requestContext .getTenantId ().orElseThrow (), entityType , entityId ),
594605 transformedUpdateOperations );
595606 boolean shouldSendNotification =
596607 this .entityAttributeChangeEvaluator .shouldSendNotification (
@@ -692,7 +703,7 @@ public void deleteEntities(
692703 return ;
693704 }
694705
695- if (existingEntities .size () == 0 ) {
706+ if (existingEntities .isEmpty () ) {
696707 LOG .debug ("{}. No entities found to delete" , request );
697708 responseObserver .onNext (DeleteEntitiesResponse .newBuilder ().build ());
698709 responseObserver .onCompleted ();
@@ -820,19 +831,17 @@ private BulkUpdateAllMatchingFilterResponse doBulkUpdate(
820831 queryConverter .convert (entityQueryRequest , requestContext );
821832 final List <Entity > existingEntities = entityFetcher .query (updateFilterQuery );
822833
823- final List <SingleValueKey > keys = getKeysToUpdate ( entityType , existingEntities );
824- final List < UpdatedEntity > updatedEntityResponses = buildUpdatedEntityResponse (keys );
834+ final List <UpdatedEntity > updatedEntityResponses =
835+ buildUpdatedEntityResponse (existingEntities );
825836 responseBuilder .addSummaries (
826837 UpdateSummary .newBuilder ().addAllUpdatedEntities (updatedEntityResponses ));
827-
828- if (keys .isEmpty ()) {
838+ if (updatedEntityResponses .isEmpty ()) {
829839 // Nothing to update
830840 LOG .debug ("No entity found with filter {} for updating" , update .getFilter ());
831841 continue ;
832842 }
833843
834844 final List <AttributeUpdateOperation > updateOperations = update .getOperationsList ();
835-
836845 final List <SubDocumentUpdate > updates = convertUpdates (requestContext , updateOperations );
837846
838847 final boolean shouldSendNotification =
@@ -856,9 +865,9 @@ private BulkUpdateAllMatchingFilterResponse doBulkUpdate(
856865 return responseBuilder .build ();
857866 }
858867
859- private List <UpdatedEntity > buildUpdatedEntityResponse (final List <SingleValueKey > keys ) {
860- return keys .stream ()
861- .map (SingleValueKey :: getValue )
868+ private List <UpdatedEntity > buildUpdatedEntityResponse (final List <Entity > entities ) {
869+ return entities .stream ()
870+ .map (Entity :: getEntityId )
862871 .map (id -> UpdatedEntity .newBuilder ().setId (id ))
863872 .map (UpdatedEntity .Builder ::build )
864873 .collect (toUnmodifiableList ());
@@ -871,8 +880,10 @@ private Converter<AttributeUpdateOperation, SubDocumentUpdate> getUpdateConverte
871880 new TypeLiteral <Converter <AttributeUpdateOperation , SubDocumentUpdate >>() {}));
872881 }
873882
874- private List <SingleValueKey > getKeysToUpdate (
875- final String entityType , final List <Entity > existingEntities ) {
883+ private List <Key > getKeysToUpdate (
884+ final RequestContext requestContext ,
885+ final String entityType ,
886+ final List <Entity > existingEntities ) {
876887 final Optional <String > idAttribute =
877888 entityAttributeMapping .getIdentifierAttributeId (entityType );
878889
@@ -883,7 +894,10 @@ private List<SingleValueKey> getKeysToUpdate(
883894 }
884895
885896 return existingEntities .stream ()
886- .map (entity -> new SingleValueKey (entity .getTenantId (), entity .getEntityId ()))
897+ .map (
898+ entity ->
899+ this .entityNormalizer .getEntityDocKey (
900+ requestContext .getTenantId ().orElseThrow (), entityType , entity .getEntityId ()))
887901 .collect (toUnmodifiableList ());
888902 }
889903
0 commit comments