diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexBuilder.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexBuilder.scala index 106df276d..f1039b169 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexBuilder.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexBuilder.scala @@ -95,6 +95,12 @@ abstract class FlintSparkIndexBuilder(flint: FlintSpark) { * the index or exception occurred if validation failed */ protected def validateIndex(index: FlintSparkIndex): FlintSparkIndex = { + // Pre-validate Flint index name length + require( + index.name().length <= 255, + "Flint index name exceeds the maximum allowed length of 255 characters") + + // Pre-validate index refresh options FlintSparkIndexRefresh .create(index.name(), index) // TODO: remove first argument? .validate(flint.spark) diff --git a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala index cddda3122..1fb0514ae 100644 --- a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala +++ b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala @@ -15,7 +15,7 @@ import org.json4s.native.Serialization import org.opensearch.flint.core.FlintOptions import org.opensearch.flint.core.storage.FlintOpenSearchClient import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex.getSkippingIndexName -import org.scalatest.matchers.must.Matchers.defined +import org.scalatest.matchers.must.Matchers.{defined, have} import org.scalatest.matchers.should.Matchers.{convertToAnyShouldWrapper, the} import org.apache.spark.sql.Row @@ -249,6 +249,18 @@ class FlintSparkSkippingIndexSqlITSuite extends FlintSparkSuite { } } + test("should fail if table name is too long") { + val testTableLong = "x" * 255 + withTable(testTableLong) { + sql(s"CREATE TABLE $testTableLong (name STRING) USING JSON") + + the[IllegalArgumentException] thrownBy { + sql(s"CREATE SKIPPING INDEX ON $testTableLong (name VALUE_SET)") + } should have message + "requirement failed: Flint index name exceeds the maximum allowed length of 255 characters" + } + } + test("create skipping index if not exists") { sql(s""" | CREATE SKIPPING INDEX