@@ -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