Skip to content

Commit 5944cb1

Browse files
committed
Simplify listEntities
1 parent d6ae2c8 commit 5944cb1

File tree

11 files changed

+24
-241
lines changed

11 files changed

+24
-241
lines changed

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.polaris.extension.persistence.impl.eclipselink;
2020

2121
import com.google.common.annotations.VisibleForTesting;
22-
import com.google.common.base.Predicates;
2322
import jakarta.annotation.Nonnull;
2423
import jakarta.annotation.Nullable;
2524
import jakarta.persistence.EntityManager;
@@ -424,44 +423,6 @@ public List<EntityNameLookupRecord> lookupEntityActiveBatchInCurrentTxn(
424423
.collect(Collectors.toList());
425424
}
426425

427-
/** {@inheritDoc} */
428-
@Override
429-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
430-
@Nonnull PolarisCallContext callCtx,
431-
long catalogId,
432-
long parentId,
433-
@Nonnull PolarisEntityType entityType,
434-
@Nonnull PageToken pageToken) {
435-
return this.listEntitiesInCurrentTxn(
436-
callCtx, catalogId, parentId, entityType, Predicates.alwaysTrue(), pageToken);
437-
}
438-
439-
@Override
440-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
441-
@Nonnull PolarisCallContext callCtx,
442-
long catalogId,
443-
long parentId,
444-
@Nonnull PolarisEntityType entityType,
445-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
446-
@Nonnull PageToken pageToken) {
447-
// full range scan under the parent for that type
448-
return this.listEntitiesInCurrentTxn(
449-
callCtx,
450-
catalogId,
451-
parentId,
452-
entityType,
453-
entityFilter,
454-
entity ->
455-
new EntityNameLookupRecord(
456-
entity.getCatalogId(),
457-
entity.getId(),
458-
entity.getParentId(),
459-
entity.getName(),
460-
entity.getTypeCode(),
461-
entity.getSubTypeCode()),
462-
pageToken);
463-
}
464-
465426
@Override
466427
public @Nonnull <T> Page<T> listEntitiesInCurrentTxn(
467428
@Nonnull PolarisCallContext callCtx,

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void writeToEntitiesActive(EntityManager session, PolarisBaseEntity entity) {
105105

106106
ModelEntityActive model = lookupEntityActive(session, new PolarisEntitiesActiveKey(entity));
107107
if (model == null) {
108-
session.persist(ModelEntityActive.fromEntityActive(new EntityNameLookupRecord(entity)));
108+
session.persist(
109+
ModelEntityActive.fromEntityActive(EntityNameLookupRecord.fromEntity(entity)));
109110
}
110111
}
111112

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.function.Predicate;
3838
import java.util.stream.Collectors;
3939
import org.apache.polaris.core.PolarisCallContext;
40-
import org.apache.polaris.core.entity.EntityNameLookupRecord;
4140
import org.apache.polaris.core.entity.LocationBasedEntity;
4241
import org.apache.polaris.core.entity.PolarisBaseEntity;
4342
import org.apache.polaris.core.entity.PolarisChangeTrackingVersions;
@@ -413,50 +412,13 @@ public List<PolarisChangeTrackingVersions> lookupEntityVersions(
413412
.collect(Collectors.toList());
414413
}
415414

416-
@Nonnull
417-
@Override
418-
public Page<EntityNameLookupRecord> listEntities(
419-
@Nonnull PolarisCallContext callCtx,
420-
long catalogId,
421-
long parentId,
422-
@Nonnull PolarisEntityType entityType,
423-
@Nonnull PageToken pageToken) {
424-
return listEntities(
425-
callCtx,
426-
catalogId,
427-
parentId,
428-
entityType,
429-
entity -> true,
430-
EntityNameLookupRecord::new,
431-
pageToken);
432-
}
433-
434-
@Nonnull
435-
@Override
436-
public Page<EntityNameLookupRecord> listEntities(
437-
@Nonnull PolarisCallContext callCtx,
438-
long catalogId,
439-
long parentId,
440-
@Nonnull PolarisEntityType entityType,
441-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
442-
@Nonnull PageToken pageToken) {
443-
return listEntities(
444-
callCtx,
445-
catalogId,
446-
parentId,
447-
entityType,
448-
entityFilter,
449-
EntityNameLookupRecord::new,
450-
pageToken);
451-
}
452-
453415
@Nonnull
454416
@Override
455417
public <T> Page<T> listEntities(
456418
@Nonnull PolarisCallContext callCtx,
457419
long catalogId,
458420
long parentId,
459-
PolarisEntityType entityType,
421+
@Nonnull PolarisEntityType entityType,
460422
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
461423
@Nonnull Function<PolarisBaseEntity, T> transformer,
462424
@Nonnull PageToken pageToken) {

polaris-core/src/main/java/org/apache/polaris/core/entity/EntityNameLookupRecord.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public EntityNameLookupRecord(
8989
this.subTypeCode = subTypeCode;
9090
}
9191

92-
/** Constructor to create the object with provided entity */
93-
public EntityNameLookupRecord(PolarisBaseEntity entity) {
94-
this.catalogId = entity.getCatalogId();
95-
this.id = entity.getId();
96-
this.parentId = entity.getParentId();
97-
this.typeCode = entity.getTypeCode();
98-
this.name = entity.getName();
99-
this.subTypeCode = entity.getSubTypeCode();
92+
public static EntityNameLookupRecord fromEntity(PolarisBaseEntity entity) {
93+
return new EntityNameLookupRecord(
94+
entity.getCatalogId(),
95+
entity.getId(),
96+
entity.getParentId(),
97+
entity.getName(),
98+
entity.getTypeCode(),
99+
entity.getSubTypeCode());
100100
}
101101

102102
@Override
@@ -119,7 +119,7 @@ public int hashCode() {
119119

120120
@Override
121121
public String toString() {
122-
return "PolarisEntitiesActiveRecord{"
122+
return "EntityNameLookupRecord{"
123123
+ "catalogId="
124124
+ catalogId
125125
+ ", id="

polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,14 @@ private void revokeGrantRecord(
709709
: entity -> true;
710710

711711
Page<EntityNameLookupRecord> resultPage =
712-
ms.listEntities(callCtx, catalogId, parentId, entityType, filter, pageToken);
712+
ms.listEntities(
713+
callCtx,
714+
catalogId,
715+
parentId,
716+
entityType,
717+
filter,
718+
EntityNameLookupRecord::fromEntity,
719+
pageToken);
713720

714721
// TODO: Use post-validation to enforce consistent view against catalogPath. In the
715722
// meantime, happens-before ordering semantics aren't guaranteed during high-concurrency

polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ default EntityNameLookupRecord lookupEntityIdAndSubTypeByName(
241241
if (baseEntity == null) {
242242
return null;
243243
}
244-
return new EntityNameLookupRecord(baseEntity);
244+
return EntityNameLookupRecord.fromEntity(baseEntity);
245245
}
246246

247247
/**
@@ -268,45 +268,6 @@ List<PolarisBaseEntity> lookupEntities(
268268
List<PolarisChangeTrackingVersions> lookupEntityVersions(
269269
@Nonnull PolarisCallContext callCtx, List<PolarisEntityId> entityIds);
270270

271-
/**
272-
* List all entities of the specified type which are child entities of the specified parent
273-
*
274-
* @param callCtx call context
275-
* @param catalogId catalog id for that entity, NULL_ID if the entity is top-level
276-
* @param parentId id of the parent, can be the special 0 value representing the root entity
277-
* @param entityType type of entities to list
278-
* @param pageToken the token to start listing after
279-
* @return the list of entities for the specified list operation
280-
*/
281-
@Nonnull
282-
Page<EntityNameLookupRecord> listEntities(
283-
@Nonnull PolarisCallContext callCtx,
284-
long catalogId,
285-
long parentId,
286-
@Nonnull PolarisEntityType entityType,
287-
@Nonnull PageToken pageToken);
288-
289-
/**
290-
* List entities where some predicate returns true
291-
*
292-
* @param callCtx call context
293-
* @param catalogId catalog id for that entity, NULL_ID if the entity is top-level
294-
* @param parentId id of the parent, can be the special 0 value representing the root entity
295-
* @param entityType type of entities to list
296-
* @param entityFilter the filter to be applied to each entity. Only entities where the predicate
297-
* returns true are returned in the list
298-
* @param pageToken the token to start listing after
299-
* @return the list of entities for which the predicate returns true
300-
*/
301-
@Nonnull
302-
Page<EntityNameLookupRecord> listEntities(
303-
@Nonnull PolarisCallContext callCtx,
304-
long catalogId,
305-
long parentId,
306-
@Nonnull PolarisEntityType entityType,
307-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
308-
@Nonnull PageToken pageToken);
309-
310271
/**
311272
* List entities where some predicate returns true and transform the entities with a function
312273
*

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -351,37 +351,6 @@ public List<PolarisChangeTrackingVersions> lookupEntityVersions(
351351
callCtx, () -> this.lookupEntityVersionsInCurrentTxn(callCtx, entityIds));
352352
}
353353

354-
/** {@inheritDoc} */
355-
@Override
356-
@Nonnull
357-
public Page<EntityNameLookupRecord> listEntities(
358-
@Nonnull PolarisCallContext callCtx,
359-
long catalogId,
360-
long parentId,
361-
@Nonnull PolarisEntityType entityType,
362-
@Nonnull PageToken pageToken) {
363-
return runInReadTransaction(
364-
callCtx,
365-
() -> this.listEntitiesInCurrentTxn(callCtx, catalogId, parentId, entityType, pageToken));
366-
}
367-
368-
/** {@inheritDoc} */
369-
@Override
370-
@Nonnull
371-
public Page<EntityNameLookupRecord> listEntities(
372-
@Nonnull PolarisCallContext callCtx,
373-
long catalogId,
374-
long parentId,
375-
@Nonnull PolarisEntityType entityType,
376-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
377-
@Nonnull PageToken pageToken) {
378-
return runInReadTransaction(
379-
callCtx,
380-
() ->
381-
this.listEntitiesInCurrentTxn(
382-
callCtx, catalogId, parentId, entityType, entityFilter, pageToken));
383-
}
384-
385354
/** {@inheritDoc} */
386355
@Override
387356
@Nonnull

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ private void bootstrapPolarisService(
717717
resolver.getParentId(),
718718
entityType,
719719
filter,
720+
EntityNameLookupRecord::fromEntity,
720721
pageToken);
721722

722723
// done

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,6 @@ List<PolarisBaseEntity> lookupEntitiesInCurrentTxn(
201201
List<PolarisChangeTrackingVersions> lookupEntityVersionsInCurrentTxn(
202202
@Nonnull PolarisCallContext callCtx, List<PolarisEntityId> entityIds);
203203

204-
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
205-
@Nonnull
206-
Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
207-
@Nonnull PolarisCallContext callCtx,
208-
long catalogId,
209-
long parentId,
210-
@Nonnull PolarisEntityType entityType,
211-
@Nonnull PageToken pageToken);
212-
213-
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
214-
@Nonnull
215-
Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
216-
@Nonnull PolarisCallContext callCtx,
217-
long catalogId,
218-
long parentId,
219-
@Nonnull PolarisEntityType entityType,
220-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
221-
@Nonnull PageToken pageToken);
222-
223204
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
224205
@Nonnull
225206
<T> Page<T> listEntitiesInCurrentTxn(

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.polaris.core.persistence.transactional;
2020

21-
import com.google.common.base.Predicates;
2221
import jakarta.annotation.Nonnull;
2322
import jakarta.annotation.Nullable;
2423
import java.util.Comparator;
@@ -288,15 +287,7 @@ public EntityNameLookupRecord lookupEntityActiveInCurrentTxn(
288287
entityActiveKey.getName()));
289288

290289
// return record
291-
return (entity == null)
292-
? null
293-
: new EntityNameLookupRecord(
294-
entity.getCatalogId(),
295-
entity.getId(),
296-
entity.getParentId(),
297-
entity.getName(),
298-
entity.getTypeCode(),
299-
entity.getSubTypeCode());
290+
return (entity == null) ? null : EntityNameLookupRecord.fromEntity(entity);
300291
}
301292

302293
/** {@inheritDoc} */
@@ -311,44 +302,6 @@ public List<EntityNameLookupRecord> lookupEntityActiveBatchInCurrentTxn(
311302
.collect(Collectors.toList());
312303
}
313304

314-
/** {@inheritDoc} */
315-
@Override
316-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
317-
@Nonnull PolarisCallContext callCtx,
318-
long catalogId,
319-
long parentId,
320-
@Nonnull PolarisEntityType entityType,
321-
@Nonnull PageToken pageToken) {
322-
return this.listEntitiesInCurrentTxn(
323-
callCtx, catalogId, parentId, entityType, Predicates.alwaysTrue(), pageToken);
324-
}
325-
326-
@Override
327-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
328-
@Nonnull PolarisCallContext callCtx,
329-
long catalogId,
330-
long parentId,
331-
@Nonnull PolarisEntityType entityType,
332-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
333-
@Nonnull PageToken pageToken) {
334-
// full range scan under the parent for that type
335-
return this.listEntitiesInCurrentTxn(
336-
callCtx,
337-
catalogId,
338-
parentId,
339-
entityType,
340-
entityFilter,
341-
entity ->
342-
new EntityNameLookupRecord(
343-
entity.getCatalogId(),
344-
entity.getId(),
345-
entity.getParentId(),
346-
entity.getName(),
347-
entity.getTypeCode(),
348-
entity.getSubTypeCode()),
349-
pageToken);
350-
}
351-
352305
@Override
353306
public @Nonnull <T> Page<T> listEntitiesInCurrentTxn(
354307
@Nonnull PolarisCallContext callCtx,

0 commit comments

Comments
 (0)