From 5d2658b519c82a35b40f032a2a850e6abc1ba47c Mon Sep 17 00:00:00 2001 From: Pace2Car Date: Thu, 12 Oct 2023 19:29:32 +0800 Subject: [PATCH] Add duplicate column check for add column to encrypt table --- .../token/generator/EncryptAlterTableTokenGenerator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java index 6fa11e1e4ecc2..22312b69d9c9a 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java @@ -121,7 +121,10 @@ private Optional getAddColumnPositionToken(final EncryptTable encryptT if (columnPositionSegment.isPresent()) { String columnName = columnPositionSegment.get().getColumnName().getIdentifier().getValue(); if (encryptTable.isEncryptColumn(columnName)) { - return Optional.of(getPositionColumnToken(encryptTable.getEncryptColumn(columnName), segment.getColumnPosition().get())); + EncryptColumn encryptColumn = encryptTable.getEncryptColumn(columnName); + ShardingSpherePreconditions.checkState(encryptColumn.getName().equals(encryptColumn.getCipher().getName()), + () -> new UnsupportedOperationException(String.format("Column %s is already exists", columnName))); + return Optional.of(getPositionColumnToken(encryptColumn, segment.getColumnPosition().get())); } } return Optional.empty();