Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
selectQueryItr set fromNext for pagination, simplify pagination logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Harish Butani committed Sep 9, 2016
1 parent 021aa66 commit ed5b133
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ private class DruidSelectResultIterator(val useSmile : Boolean,
val pagingIdentifiersJV: JsonAST.JValue = jValDeser.deserialize(jp, ctxt)
nextPagingIdentifiers = pagingIdentifiersJV.extract[Map[String, Int]]

// nextPagingIdentifiers = nextPagingIdentifiers.map {
// case (s,i) if !selectSpec.descending => (s, i + 1)
// case (s,i) if selectSpec.descending => (s, i - 1)
// }


// 1.2.2 events events field
t = jp.nextToken // FIELD_NAME, jp.getCurrentName == events
t = jp.nextToken // START_ARRAY
Expand All @@ -118,21 +124,8 @@ private class DruidSelectResultIterator(val useSmile : Boolean,
val o: JsonAST.JValue = jValDeser.deserialize(jp, ctxt)
val r = o.extract[SelectResultRow]
t = jp.nextToken()
if (!thisRoundHadData) {
// if this the first row in this round,
// check that it's offset is greater
// than the nextPagingIdentifiers value
val nextOffset = nextPagingIdentifiers(r.segmentId)
if (r.offset >= nextOffset) {
finished = true
null
} else {
thisRoundHadData = true
r
}
} else {
r
}
thisRoundHadData = true
r
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/scala/org/sparklinedata/druid/DruidQuerySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ case class SearchQuerySpecWithSegIntervals(
}

case class PagingSpec(pagingIdentifiers : Map[String, Int],
threshold : Int)
threshold : Int,
fromNext : Option[Boolean] = None)

abstract class SelectSpec extends QuerySpec {
self : Product =>
Expand Down Expand Up @@ -956,6 +957,8 @@ abstract class SelectSpec extends QuerySpec {
case dc => dc.name
}

def descending : Boolean

}

case class SelectSpecWithIntervals(queryType: String,
Expand Down Expand Up @@ -984,7 +987,7 @@ case class SelectSpecWithIntervals(queryType: String,
)

def withPagingIdentifier(ps : Map[String, Int]) = {
copy(pagingSpec = pagingSpec.copy(pagingIdentifiers = ps))
copy(pagingSpec = pagingSpec.copy(pagingIdentifiers = ps, fromNext = Some(true)))
}

override def setIntervals(ins : List[Interval]) = this.copy(intervals = ins.map(_.toString))
Expand Down Expand Up @@ -1021,7 +1024,7 @@ case class SelectSpecWithSegmentIntervals(queryType: String,
extends SelectSpec {

def withPagingIdentifier(ps : Map[String, Int]) = {
copy(pagingSpec = pagingSpec.copy(pagingIdentifiers = ps))
copy(pagingSpec = pagingSpec.copy(pagingIdentifiers = ps, fromNext = Some(true)))
}

override def setSegIntervals(segInAssignments: List[(DruidSegmentInfo, Interval)]): QuerySpec = {
Expand Down

0 comments on commit ed5b133

Please sign in to comment.