2019-08-31 20:51:14 -07:00
|
|
|
package com.linkedin.metadata.dao;
|
|
|
|
|
|
|
|
import com.linkedin.data.template.RecordTemplate;
|
|
|
|
import com.linkedin.metadata.dao.utils.Statement;
|
|
|
|
import com.linkedin.metadata.query.Filter;
|
2019-11-19 02:26:51 -08:00
|
|
|
import com.linkedin.metadata.query.RelationshipFilter;
|
2019-08-31 20:51:14 -07:00
|
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
2019-11-19 02:26:51 -08:00
|
|
|
import org.javatuples.Triplet;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
2020-06-11 10:21:51 -07:00
|
|
|
import static com.linkedin.metadata.dao.utils.QueryUtils.*;
|
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A base class for all Query DAOs.
|
|
|
|
*
|
2020-08-25 13:38:37 -07:00
|
|
|
* <p>Query DAO is a standardized interface to query the centralized graph DB. See http://go/gma for more details.
|
2019-08-31 20:51:14 -07:00
|
|
|
*/
|
|
|
|
public abstract class BaseQueryDAO {
|
|
|
|
|
|
|
|
/**
|
2020-08-25 13:38:37 -07:00
|
|
|
* Finds a list of entities of a specific type based on the given filter on the entity.
|
2019-08-31 20:51:14 -07:00
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param entityClass the entity class to query
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param filter the filter to apply when querying
|
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
|
|
|
* @param <ENTITY> returned entity type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @return a list of entities that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
2019-10-02 11:08:52 -07:00
|
|
|
public abstract <ENTITY extends RecordTemplate> List<ENTITY> findEntities(@Nonnull Class<ENTITY> entityClass,
|
2019-08-31 20:51:14 -07:00
|
|
|
@Nonnull Filter filter, int offset, int count);
|
|
|
|
|
|
|
|
/**
|
2019-10-02 11:08:52 -07:00
|
|
|
* Finds a list of entities of a specific type using a raw graph query statement.
|
2019-08-31 20:51:14 -07:00
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param entityClass the entity class to query
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param queryStatement a {@link Statement} with query text and parameters
|
|
|
|
* @param <ENTITY> returned entity type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @return a list of entities from the outcome of the query statement
|
|
|
|
*/
|
|
|
|
@Nonnull
|
2019-10-02 11:08:52 -07:00
|
|
|
public abstract <ENTITY extends RecordTemplate> List<ENTITY> findEntities(@Nonnull Class<ENTITY> entityClass,
|
2019-08-31 20:51:14 -07:00
|
|
|
@Nonnull Statement queryStatement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a list of entities containing a mixture of different types using a graph query.
|
|
|
|
*
|
|
|
|
* @param queryStatement a {@link Statement} with query text and parameters
|
|
|
|
* @return a list of entities from the outcome of the query statement
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public abstract List<RecordTemplate> findMixedTypesEntities(@Nonnull Statement queryStatement);
|
|
|
|
|
2019-10-02 11:08:52 -07:00
|
|
|
/**
|
2020-08-25 13:38:37 -07:00
|
|
|
* Finds a list of entities through certain relationships given an entity filter.
|
|
|
|
*
|
|
|
|
* <p>For more details on design and use cases, refer to interface 1 in go/gma/graph/dao.
|
2019-11-19 02:26:51 -08:00
|
|
|
*
|
|
|
|
* @param sourceEntityClass the source entity class to query
|
|
|
|
* @param sourceEntityFilter the filter to apply to the source entity when querying
|
|
|
|
* @param destinationEntityClass the destination entity class for result entity types
|
|
|
|
* @param destinationEntityFilter the filter to apply to the destination entity when querying
|
|
|
|
* @param relationshipType the type of relationship to query
|
|
|
|
* @param relationshipFilter the filter to apply to relationship when querying including the direction
|
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
|
|
|
*
|
|
|
|
* @param <SRC_ENTITY> source ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <DEST_ENTITY> destination ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of entities that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public <SRC_ENTITY extends RecordTemplate, DEST_ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate>
|
|
|
|
List<RecordTemplate> findEntities(
|
|
|
|
@Nullable Class<SRC_ENTITY> sourceEntityClass, @Nonnull Filter sourceEntityFilter,
|
|
|
|
@Nullable Class<DEST_ENTITY> destinationEntityClass, @Nonnull Filter destinationEntityFilter,
|
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull RelationshipFilter relationshipFilter,
|
|
|
|
int offset, int count) {
|
|
|
|
return findEntities(sourceEntityClass, sourceEntityFilter, destinationEntityClass, destinationEntityFilter,
|
|
|
|
relationshipType, relationshipFilter, 1, 1, offset, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-25 13:38:37 -07:00
|
|
|
* Finds a list of entities of a specific type via multiple hops traversal based on the given relationship filter and
|
|
|
|
* source/destination entity filter.
|
2019-10-02 11:08:52 -07:00
|
|
|
*
|
|
|
|
* @param sourceEntityClass the source entity class to query
|
|
|
|
* @param sourceEntityFilter the filter to apply to the source entity when querying
|
|
|
|
* @param destinationEntityClass the destination entity class
|
|
|
|
* @param destinationEntityFilter the filter to apply to the destination entity when querying
|
|
|
|
* @param relationshipType the type of relationship to query
|
|
|
|
* @param relationshipFilter the filter to apply to relationship when querying
|
2019-11-19 02:26:51 -08:00
|
|
|
* @param minHops the lower bound of hops for graph traversing.
|
|
|
|
* @param maxHops the upper bound of hops for graph traversing.
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
|
|
|
*
|
|
|
|
* @param <SRC_ENTITY> source ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <DEST_ENTITY> destination ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of entities that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public abstract <SRC_ENTITY extends RecordTemplate, DEST_ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate>
|
2019-11-19 02:26:51 -08:00
|
|
|
List<RecordTemplate> findEntities(
|
|
|
|
@Nullable Class<SRC_ENTITY> sourceEntityClass, @Nonnull Filter sourceEntityFilter,
|
|
|
|
@Nullable Class<DEST_ENTITY> destinationEntityClass, @Nonnull Filter destinationEntityFilter,
|
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull RelationshipFilter relationshipFilter, int minHops,
|
|
|
|
int maxHops, int offset, int count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a list of entities based on the given traversing paths.
|
|
|
|
*
|
|
|
|
* @param sourceEntityClass the source entity class as the starting point for the query
|
|
|
|
* @param sourceEntityFilter the filter to apply to the source entity when querying
|
2020-08-25 13:38:37 -07:00
|
|
|
* @param traversePaths specify the traverse paths via a list of (relationship type, relationship filter,
|
|
|
|
* intermediate entities)
|
2019-11-19 02:26:51 -08:00
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
|
|
|
*
|
2020-08-25 13:38:37 -07:00
|
|
|
* @param <SRC_ENTITY> source ENTITY type. Starting point of the traverse path. Must be a type defined in
|
|
|
|
* com.linkedin.metadata.entity.
|
|
|
|
* @param <INTER_ENTITY> intermediate entity type on the traverse path. Must be a type defined in
|
|
|
|
* com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> relationship type on the traverse path. Must be a type defined in
|
|
|
|
* com.linkedin.metadata.relationship.
|
2019-11-19 02:26:51 -08:00
|
|
|
* @return a list of entities that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public abstract <SRC_ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate, INTER_ENTITY extends RecordTemplate>
|
|
|
|
List<RecordTemplate> findEntities(
|
|
|
|
@Nullable Class<SRC_ENTITY> sourceEntityClass, @Nonnull Filter sourceEntityFilter,
|
|
|
|
@Nonnull List<Triplet<Class<RELATIONSHIP>, RelationshipFilter, Class<INTER_ENTITY>>> traversePaths, int offset, int count);
|
2019-10-02 11:08:52 -07:00
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
/**
|
|
|
|
* Finds a list of relationships of a specific type based on the given relationship filter and source entity filter.
|
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param sourceEntityClass the source entity class to query
|
|
|
|
* @param sourceEntityFilter the filter to apply to the source entity when querying
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param relationshipType the type of relationship to query
|
|
|
|
* @param relationshipFilter the filter to apply to relationship when querying
|
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
2019-11-19 02:26:51 -08:00
|
|
|
*
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param <ENTITY> source ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of relationships that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public <ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate> List<RELATIONSHIP> findRelationshipsFromSource(
|
2019-10-02 11:08:52 -07:00
|
|
|
@Nullable Class<ENTITY> sourceEntityClass, @Nonnull Filter sourceEntityFilter,
|
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull Filter relationshipFilter, int offset, int count) {
|
|
|
|
return findRelationships(sourceEntityClass, sourceEntityFilter, null,
|
2020-06-11 10:21:51 -07:00
|
|
|
EMPTY_FILTER, relationshipType, relationshipFilter, offset, count);
|
2019-08-31 20:51:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-25 13:38:37 -07:00
|
|
|
* Finds a list of relationships of a specific type based on the given relationship filter and destination entity
|
|
|
|
* filter.
|
2019-08-31 20:51:14 -07:00
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param destinationEntityClass the destination entity class
|
|
|
|
* @param destinationEntityFilter the filter to apply to the destination entity when querying
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param relationshipType the type of relationship to query
|
|
|
|
* @param relationshipFilter the filter to apply to relationship when querying
|
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
2019-11-19 02:26:51 -08:00
|
|
|
*
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param <ENTITY> destination ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of relationships that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public <ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate> List<RELATIONSHIP> findRelationshipsFromDestination(
|
2019-10-02 11:08:52 -07:00
|
|
|
@Nullable Class<ENTITY> destinationEntityClass, @Nonnull Filter destinationEntityFilter,
|
2019-08-31 20:51:14 -07:00
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull Filter relationshipFilter, int offset, int count) {
|
2020-06-11 10:21:51 -07:00
|
|
|
return findRelationships(null, EMPTY_FILTER, destinationEntityClass,
|
2019-10-02 11:08:52 -07:00
|
|
|
destinationEntityFilter, relationshipType, relationshipFilter, offset, count);
|
2019-08-31 20:51:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-25 13:38:37 -07:00
|
|
|
* Finds a list of relationships of a specific type based on the given relationship filter and source/destination
|
|
|
|
* entity filter.
|
2019-08-31 20:51:14 -07:00
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param sourceEntityClass the source entity class to query
|
|
|
|
* @param sourceEntityFilter the filter to apply to the source entity when querying
|
|
|
|
* @param destinationEntityClass the destination entity class
|
|
|
|
* @param destinationEntityFilter the filter to apply to the destination entity when querying
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param relationshipType the type of relationship to query
|
|
|
|
* @param relationshipFilter the filter to apply to relationship when querying
|
|
|
|
* @param offset the offset query should start at. Ignored if set to a negative value.
|
|
|
|
* @param count the maximum number of entities to return. Ignored if set to a non-positive value.
|
2019-11-19 02:26:51 -08:00
|
|
|
*
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param <SRC_ENTITY> source ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <DEST_ENTITY> destination ENTITY type. Must be a type defined in com.linkedin.metadata.entity.
|
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of relationships that match the conditions specified in {@code filter}
|
|
|
|
*/
|
|
|
|
@Nonnull
|
2019-10-02 11:08:52 -07:00
|
|
|
public abstract <SRC_ENTITY extends RecordTemplate, DEST_ENTITY extends RecordTemplate, RELATIONSHIP extends RecordTemplate>
|
|
|
|
List<RELATIONSHIP> findRelationships(
|
|
|
|
@Nullable Class<SRC_ENTITY> sourceEntityClass, @Nonnull Filter sourceEntityFilter,
|
|
|
|
@Nullable Class<DEST_ENTITY> destinationEntityClass, @Nonnull Filter destinationEntityFilter,
|
2019-08-31 20:51:14 -07:00
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull Filter relationshipFilter, int offset, int count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a list of relationships of a specific type using a graph query.
|
|
|
|
*
|
2019-10-02 11:08:52 -07:00
|
|
|
* @param relationshipClass the relationship class to query
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param queryStatement a {@link Statement} with query text and parameters
|
2019-11-19 02:26:51 -08:00
|
|
|
*
|
2019-08-31 20:51:14 -07:00
|
|
|
* @param <RELATIONSHIP> returned relationship type. Must be a type defined in com.linkedin.metadata.relationship.
|
|
|
|
* @return a list of relationships from the outcome of the query statement
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public abstract <RELATIONSHIP extends RecordTemplate> List<RELATIONSHIP> findRelationships(
|
2019-10-02 11:08:52 -07:00
|
|
|
@Nonnull Class<RELATIONSHIP> relationshipClass, @Nonnull Statement queryStatement);
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a list of relationships containing a mixture of different types using a graph query.
|
|
|
|
*
|
|
|
|
* @param queryStatement a {@link Statement} with query text and parameters
|
|
|
|
* @return a list of relationships from the outcome of the query statement
|
|
|
|
*/
|
|
|
|
@Nonnull
|
|
|
|
public abstract List<RecordTemplate> findMixedTypesRelationships(@Nonnull Statement queryStatement);
|
|
|
|
}
|