Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class MySQLIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JDBCTest

override def supportsIndex: Boolean = true

override def supportListIndexes: Boolean = true

override def indexOptions: String = "KEY_BLOCK_SIZE=10"

testVarPop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ private[v2] trait V2JDBCTest extends SharedSparkSession with DockerIntegrationFu

def supportsIndex: Boolean = false

def supportListIndexes: Boolean = false

def indexOptions: String = ""

test("SPARK-36895: Test INDEX Using SQL") {
Expand All @@ -219,11 +221,21 @@ private[v2] trait V2JDBCTest extends SharedSparkSession with DockerIntegrationFu
s" The supported Index Types are:"))

sql(s"CREATE index i1 ON $catalogName.new_table USING BTREE (col1)")
assert(jdbcTable.indexExists("i1"))
if (supportListIndexes) {
val indexes = jdbcTable.listIndexes()
assert(indexes.size == 1)
assert(indexes.head.indexName() == "i1")
}

sql(s"CREATE index i2 ON $catalogName.new_table (col2, col3, col5)" +
s" OPTIONS ($indexOptions)")

assert(jdbcTable.indexExists("i1") == true)
assert(jdbcTable.indexExists("i2") == true)
assert(jdbcTable.indexExists("i2"))
if (supportListIndexes) {
val indexes = jdbcTable.listIndexes()
assert(indexes.size == 2)
assert(indexes.map(_.indexName()).sorted === Array("i1", "i2"))
}

// This should pass without exception
sql(s"CREATE index IF NOT EXISTS i1 ON $catalogName.new_table (col1)")
Expand All @@ -234,10 +246,18 @@ private[v2] trait V2JDBCTest extends SharedSparkSession with DockerIntegrationFu
assert(m.contains("Failed to create index i1 in new_table"))

sql(s"DROP index i1 ON $catalogName.new_table")
sql(s"DROP index i2 ON $catalogName.new_table")

assert(jdbcTable.indexExists("i1") == false)
if (supportListIndexes) {
val indexes = jdbcTable.listIndexes()
assert(indexes.size == 1)
assert(indexes.head.indexName() == "i2")
}

sql(s"DROP index i2 ON $catalogName.new_table")
assert(jdbcTable.indexExists("i2") == false)
if (supportListIndexes) {
assert(jdbcTable.listIndexes().isEmpty)
}

// This should pass without exception
sql(s"DROP index IF EXISTS i1 ON $catalogName.new_table")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
val indexName = rs.getString("key_name")
val colName = rs.getString("column_name")
val indexType = rs.getString("index_type")
val indexComment = rs.getString("Index_comment")
val indexComment = rs.getString("index_comment")
if (indexMap.contains(indexName)) {
val index = indexMap.get(indexName).get
val newIndex = new TableIndex(indexName, indexType,
Expand Down