diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java index 4fc8165200d15..25ec5d33a0ad4 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java @@ -47,7 +47,7 @@ public final class ShardingSphereTable { @Getter(AccessLevel.NONE) private final Map columns; - private final List columnNames = new ArrayList<>(); + private final List columnNames = new ArrayList<>(); private final List primaryKeyColumns = new ArrayList<>(); @@ -81,8 +81,9 @@ private Map createColumns(final Map result = new LinkedHashMap<>(columns.size(), 1F); int index = 0; for (ShardingSphereColumn each : columns) { - result.put(new ShardingSphereIdentifier(each.getName()), each); - columnNames.add(each.getName()); + ShardingSphereIdentifier columnName = new ShardingSphereIdentifier(each.getName()); + result.put(columnName, each); + columnNames.add(columnName); if (each.isPrimaryKey()) { primaryKeyColumns.add(each.getName()); } diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractor.java index 48bf68426d5cc..d62870f09d049 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractor.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractor.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; +import org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereIdentifier; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; @@ -67,7 +68,9 @@ private static List findColumnsOfParameterMarkersForInsert } private static List getColumnNamesOfInsertStatement(final InsertStatement insertStatement, final ShardingSphereTable table) { - return insertStatement.getColumns().isEmpty() ? table.getColumnNames() : insertStatement.getColumns().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()); + return insertStatement.getColumns().isEmpty() + ? table.getColumnNames().stream().map(ShardingSphereIdentifier::getValue).collect(Collectors.toList()) + : insertStatement.getColumns().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()); } private static List getParameterMarkerColumns(final InsertStatement insertStatement, final ShardingSphereTable table, final List columnNamesOfInsert) { diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java index 0a5db3094daa6..ac1ccea702cde 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java @@ -38,6 +38,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; +import org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereIdentifier; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; @@ -131,7 +132,7 @@ private void describeInsertStatementByDatabaseMetaData(final PostgreSQLServerPre } String logicTableName = insertStatement.getTable().map(optional -> optional.getTableName().getIdentifier().getValue()).orElse(""); ShardingSphereTable table = getTableFromMetaData(connectionSession.getUsedDatabaseName(), insertStatement, logicTableName); - List columnNamesOfInsert = getColumnNamesOfInsertStatement(insertStatement, table); + List columnNamesOfInsert = getColumnNamesOfInsertStatement(insertStatement, table); preparedStatement.setRowDescription(returningSegment.map(returning -> describeReturning(returning, table)).orElseGet(PostgreSQLNoDataPacket::getInstance)); int parameterMarkerIndex = 0; for (InsertValuesSegment each : insertStatement.getValues()) { @@ -144,7 +145,7 @@ private void describeInsertStatementByDatabaseMetaData(final PostgreSQLServerPre parameterMarkerIndex++; continue; } - String columnName = columnNamesOfInsert.get(i); + String columnName = columnNamesOfInsert.get(i).toString(); ShardingSpherePreconditions.checkState(table.containsColumn(columnName), () -> new ColumnNotFoundException(logicTableName, columnName)); preparedStatement.getParameterTypes().set(parameterMarkerIndex++, PostgreSQLColumnType.valueOfJDBCType(table.getColumn(columnName).getDataType())); } @@ -169,8 +170,10 @@ private ShardingSphereTable getTableFromMetaData(final String databaseName, fina return database.getSchema(schemaName).getTable(logicTableName); } - private List getColumnNamesOfInsertStatement(final InsertStatement insertStatement, final ShardingSphereTable table) { - return insertStatement.getColumns().isEmpty() ? table.getColumnNames() : insertStatement.getColumns().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()); + private List getColumnNamesOfInsertStatement(final InsertStatement insertStatement, final ShardingSphereTable table) { + return insertStatement.getColumns().isEmpty() + ? table.getColumnNames() + : insertStatement.getColumns().stream().map(each -> new ShardingSphereIdentifier(each.getIdentifier().getValue())).collect(Collectors.toList()); } private PostgreSQLRowDescriptionPacket describeReturning(final ReturningSegment returningSegment, final ShardingSphereTable table) {