Skip to content

Commit

Permalink
[apache#1707] feat(mysql): Support mysql index.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clearvive authored and Clearvive committed Jan 26, 2024
1 parent d44ab8b commit cf892cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void initialize(
* @param comment The comment of the table.
* @param properties The properties of the table.
* @param partitioning The partitioning of the table.
* @param indexes
* @param indexes The indexes of the table.
*/
void create(
String databaseName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.rel.Column;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.indexes.Indexes;
import com.datastrato.gravitino.rel.types.Type;
import com.datastrato.gravitino.rel.types.Types;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void testOperationTable() {
Assertions.assertDoesNotThrow(
() ->
JDBC_TABLE_OPERATIONS.create(
DATABASE_NAME, table1, jdbcColumns, null, properties, null, indexes));
DATABASE_NAME, table1, jdbcColumns, null, properties, null, Indexes.EMPTY_INDEXES));

// list table.
List<String> allTables = JDBC_TABLE_OPERATIONS.listTables(DATABASE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public JdbcTable load(String databaseName, String tableName) throws NoSuchTableE
while (indexInfo.next()) {
String indexName = indexInfo.getString("INDEX_NAME");
if (!indexInfo.getBoolean("NON_UNIQUE")
&& !Indexes.DEFAULT_MYSQL_PRIMARY_KEY_NAME.equals(indexName)) {
&& !StringUtils.equalsIgnoreCase(Indexes.DEFAULT_MYSQL_PRIMARY_KEY_NAME, indexName)) {
String columnName = indexInfo.getString("COLUMN_NAME");
indexGroupByName.compute(
indexName,
Expand Down Expand Up @@ -258,10 +258,10 @@ protected String generateCreateTableSql(
case PRIMARY_KEY:
if (index.fieldNames().length != 1 || index.fieldNames()[0].length != 1) {
throw new IllegalArgumentException(
"Primary key does not support complex fields in Mysql");
"Primary key does not support complex fields in MySQL");
}
if (!"PRIMARY".equals(index.name().toUpperCase(Locale.ROOT))) {
throw new IllegalArgumentException("Primary key name must be PRIMARY in Mysql");
throw new IllegalArgumentException("Primary key name must be PRIMARY in MySQL");
}
sqlBuilder
.append("CONSTRAINT ")
Expand All @@ -272,7 +272,7 @@ protected String generateCreateTableSql(
case UNIQUE_KEY:
if (index.fieldNames().length != 1) {
throw new IllegalArgumentException(
"Unique key does not support complex fields in Mysql");
"Unique key does not support complex fields in MySQL");
}

String fields = String.join(", ", index.fieldNames()[0]);
Expand All @@ -285,7 +285,7 @@ protected String generateCreateTableSql(
break;
default:
throw new UnsupportedOperationException(
"Currently we do not support index in mysql, index type: " + index.type());
"Currently we do not support index in MySQL, index type: " + index.type());
}
}
}
Expand Down

0 comments on commit cf892cd

Please sign in to comment.