@@ -128,9 +128,17 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
128
128
indexProperties = indexProperties + " " + s " $k $v"
129
129
}
130
130
}
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
+ }
132
141
// columnsProperties doesn't apply to MySQL so it is ignored
133
- val iType = if (indexType.isEmpty) " " else s " USING $indexType"
134
142
s " CREATE INDEX ${quoteIdentifier(indexName)} $iType ON " +
135
143
s " ${quoteIdentifier(tableName)} ( ${columnList.mkString(" , " )}) $indexProperties"
136
144
}
@@ -180,7 +188,10 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
180
188
val indexComment = rs.getString(" Index_comment" )
181
189
if (indexMap.contains(indexName)) {
182
190
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)
184
195
} else {
185
196
// The only property we are building here is `COMMENT` because it's the only one
186
197
// we can get from `SHOW INDEXES`.
@@ -199,18 +210,18 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper {
199
210
}
200
211
201
212
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)
213
225
}
214
- super .classifyException(message, e)
215
226
}
216
227
}
0 commit comments