Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Jira Refs:

Jira
serverONAP Jira
columnIdsissuekey,summary,issuetype,created,updated,duedate,assignee,reporter,priority,status,resolution
columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
serverId425b2b0a-557c-3c0c-b515-579789cceedb
keyCPS-1605

Background

To query large outputs or large number of fragments across all anchors, we need to provide pagination for Query API(query data nodes across all anchors). it will help client to fetch limited set of data per request. below is are two possible solutions for further discussions to decide appropriate choice.  

Issues and Decisions

#IssuesNotesDecision
1How to support pagination.we need to decide on how to support pagination for query API from two possible alternatives given below (pagination over fragments or pagination over anchors)

it was discussed in weekly meeting and decided by team members to implement pagination over anchors. 

2Default page sizeshould we go with some default page size or query all records if pagination parameter in not provided. 

By default if pagination parameter in not provided then query all records.

Pagination over fragments 

...

ParameterisRequiredDescription
cps-pathyesnode path to be queried.
descendantsnoNumber of descendants to be queried. default is none.
pageIndexnopage index starting from 1.  default is -1 for all records.
resultSizepageSizenonumber of fragments per page starting from 1 (TBD). . default is -1 for all fragments.

Query

QueryDescriptionDecision 
SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId, CAST(attributes AS TEXT) AS attributes FROM FRAGMENT WHERE xpath ~ :xpathRegex ORDERED BY id LIMIT :pageSize resultSize OFFSET  (:pageIndex resultIndex - 1) * :pageSize resultSize Query limited fragments in order of fragment id


...

we can provide pagination over anchors where client can chose choose number of anchors per request to fetch fragments from. 

...

API : GET http://<IP>:<PORT>/cps/api/v2/dataspaces/{dataspace-name}/nodes/query?cps-path={cps-path}&descendants={descendants}&pageIndex={pageIndex}&anchorSizepageSize={anchorSizepageSize}

Request Parameters:

ParameterisRequiredDescription
cps-pathyesnode path to be queried
descendantsnoNumber of descendants to be queried. default is none
pageIndexnopage index starting from 1.  default is -1 for all pages(all anchors)
pageSizeanchorSizenonumber of records per request. It is nothing but number of anchors per page starting from 1 (TBD). 

Query

to be queried. Default is -1 for all pages(all anchors)

Response Headers

Headerdescription
totalPagesTotal number of pages for given page size

Response body

FormatExample

[

{"anchorName":"anchor-01",

"dataNodes":[{data-tree1},...{data-tree-n}]

...

,{"anchorName":"anchor-02",

"dataNodes": [{datatree1},...,{data-tree-n}]

}

]


Code Block
titleExample
collapsetrue
[
   {
      "anchorName":"anchor01",
      "dataNodes":[
         {
            "test:bookstore":{
               "bookstore-name":"Chapters",
               "categories":[
                  {
                     "code":1,
                     "name":"SciFi"
                  }
               ]
            }
         }
      ]
   },
   {
      "anchorName":"anchor02",
      "dataNodes":[
         {
            "test:bookstore":{
               "bookstore-name":"store01",
               "categories":[
                  {
                     "code":2,
                     "name":"SciFi"
                  }
               ]
            }
         }
      ]
   }
]


Query executed in persistence layer. 

QueryDescription
QueryDescriptionDecision
SELECT id FROM anchor order by id LIMIT : anchorSize pageSize OFFSET : (pageIndex -1) * :anchorSize   pageSize query number list of anchors to query from fragment table
SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId, CAST(attributes AS TEXT) AS attributes FROM FRAGMENT WHERE anchor_id IN :anchorList AND xpath ~ :xpathRegexquery fragments for list of anchors from above query.