Skip to content

Commit

Permalink
[Improve] Improve AlterTableSchemaEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
hailin0 committed Nov 14, 2024
1 parent 16cf632 commit 841cb16
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import org.apache.seatunnel.api.table.schema.event.SchemaChangeEvent;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class AlterTableSchemaEventHandler implements TableSchemaChangeEventHandler {
private TableSchema schema;
Expand Down Expand Up @@ -117,14 +117,11 @@ private TableSchema applyAddColumn(

private TableSchema applyDropColumn(
TableSchema schema, AlterTableDropColumnEvent dropColumnEvent) {
String[] fieldNames = schema.getFieldNames();
List<Column> newColumns =
schema.getColumns().stream()
.filter(c -> !c.getName().equals(dropColumnEvent.getColumn()))
.collect(Collectors.toList());

List<Column> newColumns = new ArrayList<>(schema.getColumns());
for (int i = 0; i < fieldNames.length; i++) {
if (fieldNames[i].equals(dropColumnEvent.getColumn())) {
newColumns.remove(i);
}
}
return TableSchema.builder()
.columns(newColumns)
.primaryKey(schema.getPrimaryKey())
Expand Down

0 comments on commit 841cb16

Please sign in to comment.