Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEOMESA-3295 Partitioned PostGIS - default to using prepared statements #2993

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading