Skip to content

Commit

Permalink
GEOMESA-3299 Deprecate query planner threaded hints
Browse files Browse the repository at this point in the history
* Threaded hints are not working as intended, and usages should be replaced
  • Loading branch information
elahrvivaz committed Sep 19, 2023
1 parent bad5cf1 commit c784bb9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,6 @@ class AccumuloFeatureReaderTest extends Specification with TestWithFeatureType {
events.head.asInstanceOf[QueryEvent].hits mustEqual 100
}

"be able to count bin results in stats through geoserver" in {
val events = ArrayBuffer.empty[AuditedEvent]

val query = new Query(sftName, filter)
val collection = dataStoreWithAudit(events).getFeatureSource(sftName).getFeatures(query)

// put the hints in the request after getting the feature collection
// to mimic the bin output format workflow
val hints = Map(QueryHints.BIN_TRACK -> "name", QueryHints.BIN_BATCH_SIZE -> 10)
QueryPlanner.setPerThreadQueryHints(hints.asInstanceOf[Map[AnyRef, AnyRef]])

var count = 0
val reader = collection.features()
while (reader.hasNext) { reader.next(); count += 1 }
reader.close()

count must beLessThan(100)
events must haveLength(1)
events.head must beAnInstanceOf[QueryEvent]
events.head.asInstanceOf[QueryEvent].hits mustEqual 100
}

"be able to limit features" in {
val query = new Query(sftName, filter)
query.setMaxFeatures(10)
Expand All @@ -146,23 +124,6 @@ class AccumuloFeatureReaderTest extends Specification with TestWithFeatureType {
count mustEqual 10 * 16 // 16 bytes per bin record
}

"be able to limit features in bin results through geoserver" in {
val query = new Query(sftName, filter)
query.setMaxFeatures(10)

val collection = ds.getFeatureSource(sftName).getFeatures(query)

val hints = Map(QueryHints.BIN_TRACK -> "name", QueryHints.BIN_BATCH_SIZE -> 10)
QueryPlanner.setPerThreadQueryHints(hints.asInstanceOf[Map[AnyRef, AnyRef]])

var count = 0
val reader = collection.features()
while (reader.hasNext) { count += reader.next().getAttribute(0).asInstanceOf[Array[Byte]].length }
reader.close()

count mustEqual 10 * 16 // 16 bytes per bin record
}

"be able to limit features and collect stats" in {
val events = ArrayBuffer.empty[AuditedEvent]
val query = new Query(sftName, filter)
Expand Down Expand Up @@ -196,28 +157,5 @@ class AccumuloFeatureReaderTest extends Specification with TestWithFeatureType {
events.head must beAnInstanceOf[QueryEvent]
events.head.asInstanceOf[QueryEvent].hits must beLessThan(20L)
}

"be able to limit features in bin results and collect stats through geoserver" in {
val events = ArrayBuffer.empty[AuditedEvent]
val query = new Query(sftName, filter)
query.setMaxFeatures(10)

val collection = dataStoreWithAudit(events).getFeatureSource(sftName).getFeatures(query)

// put the hints in the request after getting the feature collection
// to mimic the bin output format workflow
val hints = Map(QueryHints.BIN_TRACK -> "name", QueryHints.BIN_BATCH_SIZE -> 10)
QueryPlanner.setPerThreadQueryHints(hints.asInstanceOf[Map[AnyRef, AnyRef]])

var count = 0
val reader = collection.features()
while (reader.hasNext) { count += reader.next().getAttribute(0).asInstanceOf[Array[Byte]].length }
reader.close()

count mustEqual 10 * 16 // 16 bytes per bin record
events must haveLength(1)
events.head must beAnInstanceOf[QueryEvent]
events.head.asInstanceOf[QueryEvent].hits mustEqual 10L
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,19 @@ object QueryPlanner extends LazyLogging {

import org.locationtech.geomesa.utils.geotools.RichSimpleFeatureType.RichSimpleFeatureType

private [planning] val threadedHints = new SoftThreadLocal[Map[AnyRef, AnyRef]]
private[planning] val threadedHints = new SoftThreadLocal[Map[AnyRef, AnyRef]]

object CostEvaluation extends Enumeration {
type CostEvaluation = Value
val Stats, Index = Value
}

// threaded hints were used as a work-around with wfs output formats, but now we use GetFeatureCallback instead
@deprecated("Deprecated with no replacement")
def setPerThreadQueryHints(hints: Map[AnyRef, AnyRef]): Unit = threadedHints.put(hints)
@deprecated("Deprecated with no replacement")
def getPerThreadQueryHints: Option[Map[AnyRef, AnyRef]] = threadedHints.get
@deprecated("Deprecated with no replacement")
def clearPerThreadQueryHints(): Unit = threadedHints.clear()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MergedQueryRunner(
val query = new Query(original)

// set the thread-local hints once, so that we have them for each data store that is being queried
// noinspection ScalaDeprecation
QueryPlanner.getPerThreadQueryHints.foreach { hints =>
hints.foreach { case (k, v) => query.getHints.put(k, v) }
// clear any configured hints so we don't process them again
Expand Down

0 comments on commit c784bb9

Please sign in to comment.