Skip to content

Commit

Permalink
Rename ShardingSphereSchema.getVisibleColumnNamesAndIndexes() (#33788)
Browse files Browse the repository at this point in the history
* Remove useless ShardingSphereTable.putColumn

* Rename ShardingSphereSchema.getVisibleColumnNamesAndIndexes()

* Rename ShardingSphereSchema.getVisibleColumnNamesAndIndexes()
  • Loading branch information
terrymanu authored Nov 24, 2024
1 parent fb882f2 commit 9a46cb5
Show file tree
Hide file tree
Showing 35 changed files with 67 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void assertNextForDistinctShorthandResultSetsEmpty() throws SQLException {
ShardingSphereTable table = mock(ShardingSphereTable.class);
when(schema.getTable("t_order")).thenReturn(table);
when(schema.containsTable("t_order")).thenReturn(true);
when(table.getColumnValues()).thenReturn(Collections.emptyList());
when(table.getAllColumns()).thenReturn(Collections.emptyList());
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
when(database.getSchemas()).thenReturn(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Optional<String> findGenerateKeyColumn(final String tableName) {
if (!schema.containsTable(tableName)) {
return Optional.empty();
}
for (ShardingSphereColumn each : schema.getTable(tableName).getColumnValues()) {
for (ShardingSphereColumn each : schema.getTable(tableName).getAllColumns()) {
if (each.isGenerated()) {
return Optional.of(each.getName());
}
Expand Down Expand Up @@ -111,7 +111,6 @@ private GeneratedKeyContext findGeneratedKey(final Map<String, Integer> insertCo

private int findGenerateKeyIndex(final Map<String, Integer> insertColumnNamesAndIndexes, final String generateKeyColumnName) {
String tableName = insertStatement.getTable().map(optional -> optional.getTableName().getIdentifier().getValue()).orElse("");
return insertColumnNamesAndIndexes.isEmpty() ? schema.getVisibleColumnNamesAndIndexes(tableName).get(generateKeyColumnName)
: insertColumnNamesAndIndexes.get(generateKeyColumnName);
return insertColumnNamesAndIndexes.isEmpty() ? schema.getVisibleColumnAndIndexMap(tableName).get(generateKeyColumnName) : insertColumnNamesAndIndexes.get(generateKeyColumnName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static SimpleTableSegmentBinderContext createSimpleTableSegmentBinderCon
final SQLStatementBinderContext binderContext, final IdentifierValue tableName) {
Collection<ProjectionSegment> projectionSegments = new LinkedList<>();
QuoteCharacter quoteCharacter = new DatabaseTypeRegistry(binderContext.getDatabaseType()).getDialectDatabaseMetaData().getQuoteCharacter();
for (ShardingSphereColumn each : schema.getTable(tableName.getValue()).getColumnValues()) {
for (ShardingSphereColumn each : schema.getTable(tableName.getValue()).getAllColumns()) {
ColumnProjectionSegment columnProjectionSegment = new ColumnProjectionSegment(createColumnSegment(segment, databaseName, schemaName, each, quoteCharacter, tableName));
columnProjectionSegment.setVisible(each.isVisible());
projectionSegments.add(columnProjectionSegment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void assertBind() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ private JoinTableSegment mockLeftJoinSegment() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
when(schema.getTable("t_order_item").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order_item").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("item_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("order_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ void assertBindTableNotExists() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
when(schema.getTable("pg_database").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("pg_database").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("datname", Types.VARCHAR, false, false, false, true, false, false),
new ShardingSphereColumn("datdba", Types.VARCHAR, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void assertBindWithoutSubqueryTableAlias() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void assertBind() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private static void assertInsertSelect(final InsertStatement actual) {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static WhereSegment mockWhereSegment() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void assertBind() {

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
when(schema.getTable("t_order").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false),
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ public List<String> getVisibleColumnNames(final String tableName) {
}

/**
* Get visible column names and indexes via table.
* Get visible column name and indexe map.
*
* @param tableName table name
* @return visible column names and indexes
* @return visible column name and index map
*/
public Map<String, Integer> getVisibleColumnNamesAndIndexes(final String tableName) {
return containsTable(tableName) ? getTable(tableName).getVisibleColumnsAndIndexMap() : Collections.emptyMap();
public Map<String, Integer> getVisibleColumnAndIndexMap(final String tableName) {
return containsTable(tableName) ? getTable(tableName).getVisibleColumnAndIndexMap() : Collections.emptyMap();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public final class ShardingSphereTable {
@Getter(AccessLevel.NONE)
private final Map<ShardingSphereMetaDataIdentifier, ShardingSphereColumn> columns;

private final Map<String, ShardingSphereIndex> indexes;

private final Map<String, ShardingSphereConstraint> constraints;

private final List<String> columnNames = new ArrayList<>();

private final List<String> primaryKeyColumns = new ArrayList<>();

private final List<String> visibleColumns = new ArrayList<>();

private final Map<String, Integer> visibleColumnsAndIndexMap = new CaseInsensitiveMap<>();
private final Map<String, Integer> visibleColumnAndIndexMap = new CaseInsensitiveMap<>();

private final List<String> primaryKeyColumns = new ArrayList<>();
private final Map<String, ShardingSphereIndex> indexes;

private final Map<String, ShardingSphereConstraint> constraints;

private final TableType type;

Expand Down Expand Up @@ -87,7 +87,7 @@ private Map<ShardingSphereMetaDataIdentifier, ShardingSphereColumn> createColumn
}
if (each.isVisible()) {
visibleColumns.add(each.getName());
visibleColumnsAndIndexMap.put(each.getName(), index++);
visibleColumnAndIndexMap.put(each.getName(), index++);
}
}
return result;
Expand All @@ -110,21 +110,21 @@ private Map<String, ShardingSphereConstraint> createConstraints(final Collection
}

/**
* Get column meta data via column name.
* Get column.
*
* @param columnName column name
* @return column meta data
* @return column
*/
public ShardingSphereColumn getColumn(final String columnName) {
return columns.get(new ShardingSphereMetaDataIdentifier(columnName));
}

/**
* Get column meta data list.
* Get all columns.
*
* @return column meta data list
* @return columns
*/
public Collection<ShardingSphereColumn> getColumnValues() {
public Collection<ShardingSphereColumn> getAllColumns() {
return columns.values();
}

Expand All @@ -139,16 +139,16 @@ public boolean containsColumn(final String columnName) {
}

/**
* Put index meta data.
* Put index.
*
* @param index index meta data
* @param index index
*/
public void putIndex(final ShardingSphereIndex index) {
indexes.put(index.getName(), index);
}

/**
* Remove index meta data via index name.
* Remove index.
*
* @param indexName index name
*/
Expand All @@ -157,38 +157,38 @@ public void removeIndex(final String indexName) {
}

/**
* Get index meta data via index name.
* Get index.
*
* @param indexName index name
* @return index meta data
* @return index
*/
public ShardingSphereIndex getIndex(final String indexName) {
return indexes.get(indexName);
}

/**
* Get index meta data collection.
* Get indexes.
*
* @return index meta data collection
* @return indexes
*/
public Collection<ShardingSphereIndex> getIndexValues() {
return indexes.values();
}

/**
* Judge whether contains index or not.
* Judge whether contains index.
*
* @param indexName index name
* @return whether contains index or not
* @return contains index or not
*/
public boolean containsIndex(final String indexName) {
return null != indexName && indexes.containsKey(indexName);
}

/**
* Get constraint meta data collection.
* Get constraint.
*
* @return constraint meta data collection
* @return constraint
*/
public Collection<ShardingSphereConstraint> getConstraintValues() {
return constraints.values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class ShardingSphereTableDataCollectorUtils {
*/
public static List<Object> createRowValue(final Map<String, Object> columnValues, final ShardingSphereTable table) {
List<Object> result = new LinkedList<>();
for (ShardingSphereColumn each : table.getColumnValues()) {
for (ShardingSphereColumn each : table.getAllColumns()) {
result.add(columnValues.getOrDefault(each.getName(), mockValue(each.getDataType())));
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class YamlTableSwapper implements YamlConfigurationSwapper<YamlShar
public YamlShardingSphereTable swapToYamlConfiguration(final ShardingSphereTable table) {
YamlShardingSphereTable result = new YamlShardingSphereTable();
result.setName(table.getName());
result.setColumns(swapToYamlColumns(table.getColumnValues()));
result.setColumns(swapToYamlColumns(table.getAllColumns()));
result.setIndexes(swapToYamlIndexes(table.getIndexValues()));
result.setConstraints(swapToYamlConstraints(table.getConstraintValues()));
result.setType(table.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Map<String, SchemaMetaData> createSchemaMetaDataMap(final Collection<Str

private void assertTables(final Map<String, ShardingSphereTable> actual) {
assertThat(actual.size(), is(2));
assertTrue(actual.get("data_node_routed_table1").getColumnValues().isEmpty());
assertTrue(actual.get("data_node_routed_table2").getColumnValues().isEmpty());
assertTrue(actual.get("data_node_routed_table1").getAllColumns().isEmpty());
assertTrue(actual.get("data_node_routed_table2").getAllColumns().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ void assertGetColumn() {
}

@Test
void assertGetColumnValues() {
void assertGetAllColumns() {
ShardingSphereColumn column1 = new ShardingSphereColumn("foo_col_1", Types.INTEGER, true, true, false, true, false, false);
ShardingSphereColumn column2 = new ShardingSphereColumn("foo_col_2", Types.INTEGER, false, true, false, true, false, false);
ShardingSphereTable shardingSphereTable = new ShardingSphereTable("foo_tbl", Arrays.asList(column1, column2), Collections.emptyList(), Collections.emptyList());
assertThat(shardingSphereTable.getColumnValues(), hasItems(column1, column2));
assertThat(shardingSphereTable.getColumnValues(), hasSize(2));
assertThat(shardingSphereTable.getAllColumns(), hasItems(column1, column2));
assertThat(shardingSphereTable.getAllColumns(), hasSize(2));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void persistSchema(final String databaseName, final String schemaName) {
private void persistTableData(final ShardingSphereDatabase database, final String schemaName, final ShardingSphereSchemaData schemaData) {
schemaData.getTableData().values().forEach(each -> {
YamlShardingSphereRowDataSwapper swapper =
new YamlShardingSphereRowDataSwapper(new ArrayList<>(database.getSchema(schemaName).getTable(each.getName()).getColumnValues()));
new YamlShardingSphereRowDataSwapper(new ArrayList<>(database.getSchema(schemaName).getTable(each.getName()).getAllColumns()));
persistTableData(database.getName(), schemaName, each.getName(), each.getRows().stream().map(swapper::swapToYamlConfiguration).collect(Collectors.toList()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void delete(final String databaseName, final String schemaName, final Str
*/
public ShardingSphereTableData load(final String databaseName, final String schemaName, final String tableName, final ShardingSphereTable table) {
ShardingSphereTableData result = new ShardingSphereTableData(tableName);
YamlShardingSphereRowDataSwapper swapper = new YamlShardingSphereRowDataSwapper(new ArrayList<>(table.getColumnValues()));
YamlShardingSphereRowDataSwapper swapper = new YamlShardingSphereRowDataSwapper(new ArrayList<>(table.getAllColumns()));
for (String each : repository.getChildrenKeys(ShardingSphereDataNode.getTablePath(databaseName, schemaName, tableName))) {
String yamlRow = repository.query(ShardingSphereDataNode.getTableRowPath(databaseName, schemaName, tableName, each));
if (!Strings.isNullOrEmpty(yamlRow)) {
Expand Down
Loading

0 comments on commit 9a46cb5

Please sign in to comment.