Skip to content

Commit

Permalink
GEOMESA-3295 Partitioned PostGIS - default to using prepared statemen…
Browse files Browse the repository at this point in the history
…ts (#2993)
  • Loading branch information
elahrvivaz authored Sep 18, 2023
1 parent e2a2469 commit 008807b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/user/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ The following classes have been deprecated and will be removed in a future versi

* org.locationtech.geomesa.kafka.confluent.SchemaParser.GeoMesaAvroDeserializableEnumProperty

Partitioned PostGIS Prepared Statements
---------------------------------------

If not specified, prepared statements now default to ``true`` in the partitioned PostGIS data store. Prepared
statements are generally faster on insert, and some attribute types (such as list-type attributes) are only
supported through prepared statements.

Version 4.0.0 Upgrade Guide
+++++++++++++++++++++++++++

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.locationtech.geomesa.gt.partition.postgis.dialect.{PartitionedPostgis

class PartitionedPostgisDataStoreFactory extends PostgisNGDataStoreFactory with LazyLogging {

import PartitionedPostgisDataStoreParams.{DbType, IdleInTransactionTimeout}
import PartitionedPostgisDataStoreParams.{DbType, IdleInTransactionTimeout, PreparedStatements}

override def getDisplayName: String = "PostGIS (partitioned)"

Expand All @@ -26,7 +26,7 @@ class PartitionedPostgisDataStoreFactory extends PostgisNGDataStoreFactory with

override protected def setupParameters(parameters: java.util.Map[String, AnyRef]): Unit = {
super.setupParameters(parameters)
Seq(DbType, IdleInTransactionTimeout)
Seq(DbType, IdleInTransactionTimeout, PreparedStatements)
.foreach(p => parameters.put(p.key, p))
}

Expand All @@ -44,8 +44,12 @@ class PartitionedPostgisDataStoreFactory extends PostgisNGDataStoreFactory with
source
}

override protected def createDataStoreInternal(store: JDBCDataStore, params: java.util.Map[String, _]): JDBCDataStore = {

override protected def createDataStoreInternal(store: JDBCDataStore, baseParams: java.util.Map[String, _]): JDBCDataStore = {
val params = new java.util.HashMap[String, Any](baseParams)
// default to using prepared statements, if not specified
if (!params.containsKey(PreparedStatements.key)) {
params.put(PreparedStatements.key, java.lang.Boolean.TRUE)
}
val ds = super.createDataStoreInternal(store, params)
val dialect = new PartitionedPostgisDialect(ds)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ object PartitionedPostgisDataStoreParams {
Collections.singletonMap(Parameter.LEVEL, "program")
)

val PreparedStatements =
new Param(
"preparedStatements",
classOf[java.lang.Boolean],
"Use prepared statements",
false,
java.lang.Boolean.FALSE
)

val IdleInTransactionTimeout =
new Param(
"idle_in_transaction_session_timeout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.junit.runner.RunWith
import org.locationtech.geomesa.filter.FilterHelper
import org.locationtech.geomesa.gt.partition.postgis.dialect.procedures.{DropAgedOffPartitions, PartitionMaintenance, RollWriteAheadLog}
import org.locationtech.geomesa.gt.partition.postgis.dialect.tables.UserDataTable
import org.locationtech.geomesa.gt.partition.postgis.dialect.{PartitionedPostgisDialect, TableConfig, TypeInfo}
import org.locationtech.geomesa.gt.partition.postgis.dialect.{PartitionedPostgisDialect, PartitionedPostgisPsDialect, TableConfig, TypeInfo}
import org.locationtech.geomesa.utils.collection.SelfClosingIterator
import org.locationtech.geomesa.utils.geotools.{FeatureUtils, SimpleFeatureTypes}
import org.locationtech.geomesa.utils.io.WithClose
Expand Down Expand Up @@ -407,6 +407,29 @@ class PartitionedPostgisDataStoreTest extends Specification with BeforeAfterAll
}
}

"default to using prepared statements" in {
foreach(Seq(params, params + ("preparedStatements" -> "true"), params - "preparedStatements")) { params =>
val ds = DataStoreFinder.getDataStore(params.asJava)
ds must not(beNull)
try {
ds must beAnInstanceOf[JDBCDataStore]
ds.asInstanceOf[JDBCDataStore].getSQLDialect must beAnInstanceOf[PartitionedPostgisPsDialect]
} finally {
ds.dispose()
}
}
foreach(Seq(params + ("preparedStatements" -> "false"))) { params =>
val ds = DataStoreFinder.getDataStore(params.asJava)
ds must not(beNull)
try {
ds must beAnInstanceOf[JDBCDataStore]
ds.asInstanceOf[JDBCDataStore].getSQLDialect must beAnInstanceOf[PartitionedPostgisDialect] // not partitioned
} finally {
ds.dispose()
}
}
}

"support idle_in_transaction_session_timeout" in {
val sft = SimpleFeatureTypes.renameSft(this.sft, "timeout")

Expand Down

0 comments on commit 008807b

Please sign in to comment.