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 29, 2024
1 parent 48e5b43 commit 92a41a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ public JdbcTable load(String databaseName, String tableName) throws NoSuchTableE
List<JdbcColumn> jdbcColumns = new ArrayList<>();
ResultSet columns = getColumns(connection, databaseName, tableName);
while (columns.next()) {
JdbcColumn.Builder columnBuilder = createJdbcColumnBuilder(columns);
extractJdbcColumnFromResultSet(columns, columnBuilder);
JdbcColumn.Builder columnBuilder = getBasicJdbcColumnInfo(columns);
boolean autoIncrement = getAutoIncrementInfo(columns);
columnBuilder.withAutoIncrement(autoIncrement);
jdbcColumns.add(columnBuilder.build());
}

JdbcTable.Builder jdbcTableBuilder = createJdbcTableBuilder(table);
extractJdbcTableFromResultSet(table, jdbcTableBuilder);

// 3.Get table properties
// 3.The underlying implementation class customizes the extension of table information.
extractJdbcTable(connection, tableName, jdbcTableBuilder);

return jdbcTableBuilder.withColumns(jdbcColumns.toArray(new JdbcColumn[0])).build();
Expand All @@ -130,6 +130,8 @@ public JdbcTable load(String databaseName, String tableName) throws NoSuchTableE
}
}

protected abstract boolean getAutoIncrementInfo(ResultSet columns) throws SQLException;

@Override
public void rename(String databaseName, String oldTableName, String newTableName)
throws NoSuchTableException {
Expand Down Expand Up @@ -195,15 +197,11 @@ protected ResultSet getColumns(Connection connection, String databaseName, Strin
return metaData.getColumns(connection.getCatalog(), connection.getSchema(), tableName, null);
}

protected abstract void extractJdbcColumnFromResultSet(
ResultSet column, JdbcColumn.Builder columnBuilder) throws SQLException;

protected abstract void extractJdbcTableFromResultSet(
ResultSet column, JdbcTable.Builder columnBuilder) throws SQLException;

protected abstract void extractJdbcTable(
protected void extractJdbcTable(
Connection connection, String tableName, JdbcTable.Builder jdbcTableBuilder)
throws SQLException;
throws SQLException {
// nothing to do
}

protected abstract String generateCreateTableSql(
String tableName,
Expand Down Expand Up @@ -235,7 +233,7 @@ protected JdbcTable.Builder createJdbcTableBuilder(ResultSet table) throws SQLEx
.withProperties(Collections.emptyMap());
}

protected JdbcColumn.Builder createJdbcColumnBuilder(ResultSet column) throws SQLException {
protected JdbcColumn.Builder getBasicJdbcColumnInfo(ResultSet column) throws SQLException {
JdbcTypeConverter.JdbcTypeBean typeBean =
new JdbcTypeConverter.JdbcTypeBean(column.getString("TYPE_NAME"));
typeBean.setColumnSize(column.getString("COLUMN_SIZE"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
package com.datastrato.gravitino.catalog.jdbc.operation;

import com.datastrato.gravitino.catalog.jdbc.JdbcColumn;
import com.datastrato.gravitino.catalog.jdbc.JdbcTable;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.expressions.transforms.Transform;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

public class SqliteTableOperations extends JdbcTableOperations {
Expand Down Expand Up @@ -76,15 +73,7 @@ protected String generateAlterTableSql(
}

@Override
protected void extractJdbcColumnFromResultSet(ResultSet column, JdbcColumn.Builder columnBuilder)
throws SQLException {}

@Override
protected void extractJdbcTableFromResultSet(ResultSet column, JdbcTable.Builder columnBuilder)
throws SQLException {}

@Override
protected void extractJdbcTable(
Connection connection, String tableName, JdbcTable.Builder jdbcTableBuilder)
throws SQLException {}
protected boolean getAutoIncrementInfo(ResultSet columns) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,10 @@ protected String generateCreateTableSql(
}

@Override
protected void extractJdbcColumnFromResultSet(
ResultSet resultSet, JdbcColumn.Builder columnBuilder) throws SQLException {
columnBuilder.withAutoIncrement(
"YES".equalsIgnoreCase(resultSet.getString("IS_AUTOINCREMENT")));
protected boolean getAutoIncrementInfo(ResultSet resultSet) throws SQLException {
return "YES".equalsIgnoreCase(resultSet.getString("IS_AUTOINCREMENT"));
}

@Override
protected void extractJdbcTableFromResultSet(ResultSet column, JdbcTable.Builder columnBuilder)
throws SQLException {}

@Override
protected void extractJdbcTable(
Connection connection, String tableName, JdbcTable.Builder tableBuilder) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,10 @@ private String updateColumnCommentFieldDefinition(
}

@Override
protected void extractJdbcColumnFromResultSet(
ResultSet resultSet, JdbcColumn.Builder columnBuilder) throws SQLException {
columnBuilder.withAutoIncrement(resultSet.getBoolean("IS_AUTOINCREMENT"));
protected boolean getAutoIncrementInfo(ResultSet resultSet) throws SQLException {
return resultSet.getBoolean("IS_AUTOINCREMENT");
}

@Override
protected void extractJdbcTableFromResultSet(ResultSet column, JdbcTable.Builder columnBuilder)
throws SQLException {}

@Override
protected void extractJdbcTable(
Connection connection, String tableName, JdbcTable.Builder jdbcTableBuilder)
throws SQLException {}

@Override
protected Connection getConnection(String schema) throws SQLException {
Connection connection = dataSource.getConnection();
Expand Down

0 comments on commit 92a41a6

Please sign in to comment.