4141import org .apache .paimon .types .DataType ;
4242import org .apache .paimon .types .DataTypes ;
4343
44- import java .util .HashMap ;
4544import java .util .LinkedHashMap ;
4645import java .util .List ;
4746import java .util .Map ;
@@ -170,8 +169,8 @@ private void alterTable(Identifier tablePath, List<SchemaChange> tableChanges)
170169 private void validatePaimonSchemaCapability (
171170 Identifier tablePath , Schema existingSchema , Schema newSchema ) {
172171 // Adjust options for comparison
173- Map <String , String > existingOptions = new HashMap <>( existingSchema .options () );
174- Map <String , String > newOptions = new HashMap <>( newSchema .options () );
172+ Map <String , String > existingOptions = existingSchema .options ();
173+ Map <String , String > newOptions = newSchema .options ();
175174 // `path` will be set automatically by Paimon, so we need to remove it in existing options
176175 existingOptions .remove (CoreOptions .PATH .key ());
177176 // when enable datalake with an existing table, `table.datalake.enabled` will be `false`
@@ -182,40 +181,14 @@ private void validatePaimonSchemaCapability(
182181 newOptions .remove (datalakeConfigKey );
183182 }
184183
185- // Build schemas with adjusted options for comparison
186- Schema adjustedExistingSchema = buildSchemaWithOptions (existingSchema , existingOptions );
187- Schema adjustedNewSchema = buildSchemaWithOptions (newSchema , newOptions );
188-
189- if (!adjustedExistingSchema .equals (adjustedNewSchema )) {
184+ if (!existingSchema .equals (newSchema )) {
190185 throw new TableAlreadyExistException (
191186 String .format (
192187 "The table %s already exists in Paimon catalog, but the table schema is not compatible. "
193188 + "Existing schema: %s, new schema: %s. "
194189 + "Please first drop the table in Paimon catalog or use a new table name." ,
195- tablePath .getEscapedFullName (),
196- adjustedExistingSchema ,
197- adjustedNewSchema ));
198- }
199- }
200-
201- private Schema buildSchemaWithOptions (Schema schema , Map <String , String > options ) {
202- Schema .Builder builder = Schema .newBuilder ();
203- // Copy fields
204- for (org .apache .paimon .types .DataField field : schema .fields ()) {
205- builder .column (field .name (), field .type (), field .description ());
206- }
207- // Copy primary keys
208- if (!schema .primaryKeys ().isEmpty ()) {
209- builder .primaryKey (schema .primaryKeys ());
210- }
211- // Copy partition keys
212- if (!schema .partitionKeys ().isEmpty ()) {
213- builder .partitionKeys (schema .partitionKeys ());
190+ tablePath .getEscapedFullName (), existingSchema , newSchema ));
214191 }
215- // Set adjusted options
216- builder .options (options );
217- builder .comment (schema .comment ());
218- return builder .build ();
219192 }
220193
221194 private void checkTableIsEmpty (Identifier tablePath , FileStoreTable table ) {
0 commit comments