Skip to content

Commit 9c32078

Browse files
committed
address comments
1 parent c01a5f1 commit 9c32078

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/index/SupportsIndex.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface SupportsIndex extends Table {
4242
* @param columns the columns on which index to be created
4343
* @param columnsProperties the properties of the columns on which index to be created
4444
* @param properties the properties of the index to be created
45-
* @throws IndexAlreadyExistsException If the index already exists (optional)
45+
* @throws IndexAlreadyExistsException If the index already exists.
4646
*/
4747
void createIndex(String indexName,
4848
String indexType,
@@ -55,7 +55,7 @@ void createIndex(String indexName,
5555
* Drops the index with the given name.
5656
*
5757
* @param indexName the name of the index to be dropped.
58-
* @throws NoSuchIndexException If the index does not exist (optional)
58+
* @throws NoSuchIndexException If the index does not exist.
5959
*/
6060
void dropIndex(String indexName) throws NoSuchIndexException;
6161

sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/index/TableIndex.java

-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ public TableIndex(
6565
*/
6666
public NamedReference[] columns() { return columns; }
6767

68-
/**
69-
* set columns using the passed in param columns
70-
*/
71-
public void columns_(NamedReference[] columns) { this.columns = columns; }
72-
7368
/**
7469
* @return the map of column and column property map.
7570
*/

sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala

+26-15
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,17 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
128128
indexProperties = indexProperties + " " + s"$k $v"
129129
}
130130
}
131-
131+
val iType = if (indexType.isEmpty) {
132+
""
133+
} else {
134+
if (indexType.length > 1 && !indexType.equalsIgnoreCase("BTREE") &&
135+
!indexType.equalsIgnoreCase("HASH")) {
136+
throw new UnsupportedOperationException(s"Index Type $indexType is not supported." +
137+
" The supported Index Types are: BTREE and HASH")
138+
}
139+
s"USING $indexType"
140+
}
132141
// columnsProperties doesn't apply to MySQL so it is ignored
133-
val iType = if (indexType.isEmpty) "" else s"USING $indexType"
134142
s"CREATE INDEX ${quoteIdentifier(indexName)} $iType ON" +
135143
s" ${quoteIdentifier(tableName)} (${columnList.mkString(", ")}) $indexProperties"
136144
}
@@ -180,7 +188,10 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
180188
val indexComment = rs.getString("Index_comment")
181189
if (indexMap.contains(indexName)) {
182190
val index = indexMap.get(indexName).get
183-
index.columns_(index.columns() :+ FieldReference(colName))
191+
val newIndex = new TableIndex(indexName, indexType,
192+
index.columns() :+ FieldReference(colName),
193+
index.columnProperties, index.properties)
194+
indexMap += (indexName -> newIndex)
184195
} else {
185196
// The only property we are building here is `COMMENT` because it's the only one
186197
// we can get from `SHOW INDEXES`.
@@ -199,18 +210,18 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
199210
}
200211

201212
override def classifyException(message: String, e: Throwable): AnalysisException = {
202-
if (e.isInstanceOf[SQLException]) {
203-
// Error codes are from
204-
// https://mariadb.com/kb/en/mariadb-error-codes/#shared-mariadbmysql-error-codes
205-
e.asInstanceOf[SQLException].getErrorCode match {
206-
// ER_DUP_KEYNAME
207-
case 1061 =>
208-
throw new IndexAlreadyExistsException(message, cause = Some(e))
209-
case 1091 =>
210-
throw new NoSuchIndexException(message, cause = Some(e))
211-
case _ =>
212-
}
213+
e match {
214+
case sqlException: SQLException =>
215+
sqlException.getErrorCode match {
216+
// ER_DUP_KEYNAME
217+
case 1061 =>
218+
throw new IndexAlreadyExistsException(message, cause = Some(e))
219+
case 1091 =>
220+
throw new NoSuchIndexException(message, cause = Some(e))
221+
case _ => super.classifyException(message, e)
222+
}
223+
case unsupported: UnsupportedOperationException => throw unsupported
224+
case _ => super.classifyException(message, e)
213225
}
214-
super.classifyException(message, e)
215226
}
216227
}

0 commit comments

Comments
 (0)