Skip to content

Commit

Permalink
GEOMESA-3337 Merged view - support unquoted configuration keys
Browse files Browse the repository at this point in the history
  • Loading branch information
elahrvivaz committed Mar 18, 2024
1 parent 51a8845 commit 8d045fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MergedDataStoreViewTest extends TestWithFeatureType {
ECQL.toFilter("bbox(the_geom,44,52,46,59) and dtg DURING 2018-01-02T12:00:00.000Z/2018-01-06T12:00:00.000Z")

val accumuloParams = dsParams.asJava

var shpParams: java.util.Map[String, String] = _

var path: Path = _
Expand Down Expand Up @@ -152,6 +152,31 @@ class MergedDataStoreViewTest extends TestWithFeatureType {
testParams(ConfigFactory.empty().withValue("stores", ConfigValueFactory.fromIterable(Seq(shpConfig).asJava)))
}

"handle unquoted store keys" in {
def unquotedConfig(params: Map[String, String]): Config = {
params.foldLeft(ConfigFactory.empty()) { case (conf, (k, v)) =>
conf.withValue(k, ConfigValueFactory.fromAnyRef(v))
}
}
val shpConfig = unquotedConfig(shpParams.asScala.toMap).root()
val accumuloConfig = unquotedConfig(accumuloParams.asScala.toMap).root()
val config =
ConfigFactory.empty().withValue("stores", ConfigValueFactory.fromIterable(Seq(accumuloConfig, shpConfig).asJava))

val params = Map(
MergedDataStoreViewFactory.ConfigParam.key -> config.root.render(ConfigRenderOptions.concise())
)

val ds = DataStoreFinder.getDataStore(params.asJava)
ds must not(beNull)
try {
ds must beAnInstanceOf[MergedDataStoreView]
ds.asInstanceOf[MergedDataStoreView].stores must haveLength(2)
} finally {
ds.dispose()
}
}

"query multiple data stores" in {
val results = SelfClosingIterator(mergedDs.getFeatureReader(new Query(sftName), Transaction.AUTO_COMMIT)).toList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import scala.util.{Failure, Success, Try}
class MergedDataStoreViewFactory extends DataStoreFactorySpi {

import MergedDataStoreViewFactory._
import org.locationtech.geomesa.utils.conf.ConfConversions.RichConfig

import scala.collection.JavaConverters._

Expand Down Expand Up @@ -60,13 +61,15 @@ class MergedDataStoreViewFactory extends DataStoreFactorySpi {

try {
configs.foreach { config =>
lazy val error = new IllegalArgumentException(s"Could not load store using configuration:\n" +
config.root().render(ConfigRenderOptions.concise().setFormatted(true)))
lazy val error =
new IllegalArgumentException(s"Could not load store using configuration:\n" +
config.root().render(ConfigRenderOptions.concise().setFormatted(true)))
// inject the namespace into the underlying stores
val storeParams = nsConfig.map(config.withValue(NamespaceParam.key, _)).getOrElse(config).root().unwrapped()
val filter = try {
StoreFilterParam.lookupOpt(storeParams.asInstanceOf[java.util.Map[String, Serializable]]).map(ECQL.toFilter)
} catch {
val paramConf = nsConfig.map(config.withValue(NamespaceParam.key, _)).getOrElse(config)
val storeParams = new java.util.HashMap[String, AnyRef](paramConf.root().unwrapped())
// allow for unquoted keys
storeParams.putAll(paramConf.toStringMap().asJava)
val filter = try { StoreFilterParam.lookupOpt(storeParams).map(ECQL.toFilter) } catch {
case NonFatal(e) =>
throw new IllegalArgumentException(s"Invalid store filter '${storeParams.get(StoreFilterParam.key)}'", e)
}
Expand Down

0 comments on commit 8d045fd

Please sign in to comment.