Skip to content

Commit

Permalink
GEOMESA-3268 Partitioned PostGIS - Check for long type name errors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adeet1 authored Jan 11, 2024
1 parent fa5b239 commit 82df699
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class PartitionedPostgisDialect(store: JDBCDataStore) extends PostGISDialect(sto
}

override def postCreateTable(schemaName: String, sft: SimpleFeatureType, cx: Connection): Unit = {
// Throw an error if the sft name is longer than 31 characters
if (sft.getTypeName.length() > 31) {
val errorMsg = "Can't create schema: type name exceeds max supported length of 31 characters"
throw new IllegalArgumentException(errorMsg)
}

// note: we skip the call to `super`, which creates a spatial index (that we don't want), and which
// alters the geometry column types (which we handle in the create statement)
val info = TypeInfo(schemaName, sft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,35 @@ class PartitionedPostgisDataStoreTest extends Specification with BeforeAfterAll
}

"PartitionedPostgisDataStore" should {
"fail with a useful error message if type name is too long" in {
val ds = DataStoreFinder.getDataStore(params.asJava)
ds must not(beNull)

try {
ds must beAnInstanceOf[JDBCDataStore]

// This sft name exceeds 31 characters, so it should fail
val sft = SimpleFeatureTypes.renameSft(this.sft, "abcdefghijklmnopqrstuvwxyzabcde_____")
ds.getTypeNames.toSeq must not(contain(sft.getTypeName))
ds.createSchema(sft) must throwAn[java.io.IOException].like {
case e => e.getCause.getMessage mustEqual "Can't create schema: type name exceeds max supported length of 31 characters"
}
} finally {
ds.dispose()
}
ok
}

"work" in {
val ds = DataStoreFinder.getDataStore(params.asJava)
ds must not(beNull)

try {
ds must beAnInstanceOf[JDBCDataStore]

foreach(Seq("test", "test-dash")) { name =>
val sftNames: Seq[String] = Seq("test", "test-abcdefghijklmnopqrstuvwxyz")

foreach(sftNames) { name =>
val sft = SimpleFeatureTypes.renameSft(this.sft, name)
ds.getTypeNames.toSeq must not(contain(sft.getTypeName))
ds.createSchema(sft)
Expand Down

0 comments on commit 82df699

Please sign in to comment.