Skip to content

Commit

Permalink
feat(oaf): Add support to return feature properties in a specific ord…
Browse files Browse the repository at this point in the history
…er + use constant for prev/next fid
  • Loading branch information
rkettelerij committed Sep 20, 2024
1 parent fe3c8c5 commit b33ad9f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/ogc/features/datasources/geopackage/geopackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewGeoPackage(collections config.GeoSpatialCollections, gpkgConfig config.G
log.Fatal("unknown GeoPackage config encountered")
}

g.selectClauseFids = []string{g.fidColumn, "prevfid", "nextfid"}
g.selectClauseFids = []string{g.fidColumn, domain.PrevFid, domain.NextFid}

metadata, err := readDriverMetadata(g.backend.getDB())
if err != nil {
Expand Down Expand Up @@ -353,9 +353,9 @@ with
next as (select * from "%[1]s" where "%[2]s" >= :fid %[3]s %[4]s order by %[2]s asc limit :limit + 1),
prev as (select * from "%[1]s" where "%[2]s" < :fid %[3]s %[4]s order by %[2]s desc limit :limit),
nextprev as (select * from next union all select * from prev),
nextprevfeat as (select *, lag("%[2]s", :limit) over (order by %[2]s) as prevfid, lead("%[2]s", :limit) over (order by "%[2]s") as nextfid from nextprev)
nextprevfeat as (select *, lag("%[2]s", :limit) over (order by %[2]s) as %[6]s, lead("%[2]s", :limit) over (order by "%[2]s") as %[7]s from nextprev)
select %[5]s from nextprevfeat where "%[2]s" >= :fid %[3]s %[4]s limit :limit
`, table.TableName, g.fidColumn, temporalClause, pfClause, selectClause) // don't add user input here, use named params for user input!
`, table.TableName, g.fidColumn, temporalClause, pfClause, selectClause, domain.PrevFid, domain.NextFid) // don't add user input here, use named params for user input!

namedParams := map[string]any{
"fid": criteria.Cursor.FID,
Expand Down Expand Up @@ -415,10 +415,10 @@ with
limit (select iif(bbox_size == 'big', :limit, 0) from bbox_size)),
prev as (select * from prev_bbox_rtree union all select * from prev_bbox_btree),
nextprev as (select * from next union all select * from prev),
nextprevfeat as (select *, lag("%[2]s", :limit) over (order by "%[2]s") as prevfid, lead("%[2]s", :limit) over (order by "%[2]s") as nextfid from nextprev)
nextprevfeat as (select *, lag("%[2]s", :limit) over (order by "%[2]s") as %[9]s, lead("%[2]s", :limit) over (order by "%[2]s") as %[10]s from nextprev)
select %[5]s from nextprevfeat where "%[2]s" >= :fid %[6]s %[7]s limit :limit
`, table.TableName, g.fidColumn, g.maxBBoxSizeToUseWithRTree, table.GeometryColumnName,
selectClause, temporalClause, pfClause, btreeIndexHint) // don't add user input here, use named params for user input!
selectClause, temporalClause, pfClause, btreeIndexHint, domain.PrevFid, domain.NextFid) // don't add user input here, use named params for user input!

bboxAsWKT, err := wkt.EncodeString(criteria.Bbox)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/ogc/features/domain/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
"strings"
)

const separator = '|'
const (
PrevFid = "prevfid"
NextFid = "nextfid"

separator = '|'
)

// Cursors holds next and previous cursor. Note that we use
// 'cursor-based pagination' as opposed to 'offset-based pagination'
Expand Down
4 changes: 2 additions & 2 deletions internal/ogc/features/domain/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ func mapColumnsToFeature(firstRow bool, feature *Feature, columns []string, valu
// Skip these columns used for bounding box and zoom filtering
continue

case "prevfid":
case PrevFid:
// Only the first row in the result set contains the previous feature id
if firstRow && columnValue != nil {
prevNextID.Prev = columnValue.(int64)
}

case "nextfid":
case NextFid:
// Only the first row in the result set contains the next feature id
if firstRow && columnValue != nil {
prevNextID.Next = columnValue.(int64)
Expand Down
2 changes: 1 addition & 1 deletion internal/ogc/features/domain/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestMapColumnsToFeature(t *testing.T) {
name: "Test prevfid and nextfid",
firstRow: true,
feature: &Feature{Properties: NewFeatureProperties(false)},
columns: []string{"prevfid", "nextfid"},
columns: []string{PrevFid, NextFid},
values: []any{int64(1), int64(2)},
expectedFeature: &Feature{Properties: NewFeatureProperties(false)},
expectedPrevNext: &PrevNextFID{Prev: int64(1), Next: int64(2)},
Expand Down

0 comments on commit b33ad9f

Please sign in to comment.