-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass of a Date Range Query Interceptor.
Signed-off-by: Jim Hughes <[email protected]>
- Loading branch information
Showing
4 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...i/src/main/scala/org/locationtech/geomesa/index/planning/DateRangerQueryInterceptor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*********************************************************************** | ||
* Copyright (c) 2013-2020 Commonwealth Computer Research, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Apache License, Version 2.0 | ||
* which accompanies this distribution and is available at | ||
* http://www.opensource.org/licenses/apache2.0.php. | ||
***********************************************************************/ | ||
|
||
package org.locationtech.geomesa.index.planning | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.temporal.ChronoUnit | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import org.geotools.data.{DataStore, Query} | ||
import org.locationtech.geomesa.filter.{Bounds, FilterHelper, FilterValues} | ||
import org.locationtech.geomesa.index.conf.QueryHints | ||
import org.opengis.feature.simple.SimpleFeatureType | ||
import org.geotools.data.{DataStore, Query} | ||
import org.locationtech.geomesa.index.api.GeoMesaFeatureIndex | ||
import org.locationtech.geomesa.index.geotools.GeoMesaDataStore | ||
import org.locationtech.geomesa.index.index.z2.{XZ2Index, Z2Index} | ||
import org.locationtech.geomesa.index.index.z3.{XZ3Index, Z3Index} | ||
import org.locationtech.geomesa.index.strategies.SpatioTemporalFilterStrategy | ||
import org.opengis.feature.simple.SimpleFeatureType | ||
|
||
class DateRangerQueryInterceptor extends QueryInterceptor with LazyLogging { | ||
private var ds: DataStore = _ | ||
private var sft: SimpleFeatureType = _ | ||
/** | ||
* Called exactly once after the interceptor is instantiated | ||
* | ||
* @param ds data store | ||
* @param sft simple feature type | ||
*/ | ||
override def init(ds: DataStore, sft: SimpleFeatureType): Unit = { | ||
this.ds = ds | ||
this.sft = sft | ||
} | ||
|
||
/** | ||
* Modifies the query in place | ||
* | ||
* @param query query | ||
*/ | ||
override def rewrite(query: Query): Unit = { | ||
QueryInterceptor.skipExecution.set(true) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
val plan = ds.asInstanceOf[GeoMesaDataStore[_]].getQueryPlan(query) | ||
This comment has been minimized.
Sorry, something went wrong.
elahrvivaz
Contributor
|
||
QueryInterceptor.skipExecution.set(false) | ||
val index: GeoMesaFeatureIndex[_, _] = plan.head.filter.index | ||
|
||
index match { | ||
case _ : Z2Index | _ : XZ2Index |_ : Z3Index | _ : XZ3Index => | ||
val length = calculateDateRange(query) | ||
println(s"Length for query ${query.getFilter} is $length days") | ||
if (length >= 10) { | ||
throw new IllegalArgumentException("Date ranges need to be shorter than 10 days!") | ||
} else { | ||
logger.debug("Didn't update query") | ||
} | ||
case _ => | ||
println("Got another index") | ||
} | ||
} | ||
|
||
private def calculateDateRange(query: Query): Long = { | ||
var length: Long = 0 | ||
val temporalRange: FilterValues[Bounds[ZonedDateTime]] = FilterHelper.extractIntervals(query.getFilter, "dtg") | ||
|
||
logger.debug(s"Got ranges $temporalRange") | ||
temporalRange.foreach { bounds => | ||
val upper: ZonedDateTime = bounds.upper.value.get | ||
val lower = bounds.lower.value.get | ||
length += Math.abs(ChronoUnit.DAYS.between(upper, lower)) | ||
} | ||
logger.debug(s"Time range for dtg detected to be $length days.") | ||
length | ||
} | ||
|
||
override def close(): Unit = { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instead of a thread local here, you could maybe use set a query hint