You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 12
Next »
Background : we want to include limit/depth/pagination in CPS-Core query APIs where output size is large. it will allow user to limit query outputs.
It was discussed on 11th Nov 2022 in weekly meeting to use 'depth' parameter to limit large outputs.
Implementation :
'depth' query parameter added in below URLs | Notes | Decision |
---|
URL: http://<IP:PORT>/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/node?xpath=/&include-descendants=true&depth=1 | - depth is an optional query parameter or mandatory
- how to handle include-descendants query parameter? can we remove this parameter and use only depth parameter. depth = -1 is same as include-descendants= true
- depth values treated as below
- -1 : all descendants
- 0 : no descendants
- 1, 2, 3, ... : number or descendants
|
|
URL: http://<IP:PORT>/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query?cps-path=/&include-descendents=true&depth=1 |
|
|
|
|
|
Implementations:
changes files | changes/notes | Decision |
---|
cpsData.yml | nodeByDataspaceAndAnchor: get: ... - $ref: 'components.yml#/components/parameters/depthInQuery' ... |
|
cpsQuery.yml | nodesByDataspaceAndAnchorAndCpsPath: get: ... - $ref: 'components.yml#/components/parameters/depthInQuery' ... |
|
components.yml | depthInQuery: name: depth in: query description: depth parameter for large query outputs required: false schema: type: string default: all example: 1 |
|
FetchDescendantsOption.java | We Need to change this class to accept for any other depth values except -1, 0 and 1. Do we need to change FetchDescendantsOption to support multiple depths or add depth as separate argument along with FetchDescendantsOption |
|
FragmentRepository.java | @Query(value = "SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId," + " CAST(attributes AS TEXT) AS attributes" + " FROM FRAGMENT WHERE anchor_id = :anchorId" + " AND ( xpath = :parentXpath OR xpath LIKE CONCAT(:parentXpath,'/%') )", nativeQuery = true) List<FragmentExtract> findByAnchorIdAndParentXpath(@Param("anchorId") int anchorId, @Param("parentXpath") String parentXpath, @Param("depth") Integer depth); | we need to change query to support depth or we can query all fragments and then select fragment data till given depth value(in below code). |
FragmentEntityArranger.java | private static FragmentEntity reuniteChildrenWithTheirParents(final Map<Long, FragmentEntity> fragmentEntityPerId, Integer depth) { final Collection<FragmentEntity> fragmentEntitiesWithoutParentInResultSet = new HashSet<>(); for (final FragmentEntity fragmentEntity : fragmentEntityPerId.values()) { final FragmentEntity parentFragmentEntity = fragmentEntityPerId.get(fragmentEntity.getParentId()); if (parentFragmentEntity == null) { fragmentEntitiesWithoutParentInResultSet.add(fragmentEntity); } else { parentFragmentEntity.getChildFragments().add(fragmentEntity); } } return fragmentEntitiesWithoutParentInResultSet.stream().findFirst().orElse(null); } | we can reunite children as per given depth value. |