Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sql-check): a specific sql will lead to npe (#3611) #3617

Open
wants to merge 1 commit into
base: dev/4.3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public List<CheckViolation> check(@NonNull Statement statement, @NonNull SqlChec
violations.addAll(dropPartition(statement, action));
violations.addAll(truncatePartition(statement, action));
return violations.stream();
}).collect(Collectors.toList());
}).filter(Objects::nonNull).collect(Collectors.toList());
} else if (statement instanceof TruncateTable) {
return Collections.singletonList(SqlCheckUtil.buildViolation(statement.getText(),
statement, getType(), new Object[] {"TRUNCATE TABLE"}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.jdbc.core.JdbcOperations;
Expand Down Expand Up @@ -72,7 +73,7 @@ public List<CheckViolation> check(@NonNull Statement statement, @NonNull SqlChec
violations.addAll(dropPartition(statement, action));
violations.addAll(truncatePartition(statement, action));
return violations.stream();
}).collect(Collectors.toList());
}).filter(Objects::nonNull).collect(Collectors.toList());
} else if (statement instanceof TruncateTable) {
return Collections.singletonList(SqlCheckUtil.buildViolation(statement.getText(),
statement, getType(), new Object[] {"TRUNCATE TABLE"}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,9 @@ public void check_offlineDdl_violationGenerated() {
"create table abcd(id varchar(64))",
"alter table abcd modify id int AUTO_INCREMENT",
"alter table abcd modify id varchar(64)",
"alter table abcd add column a int after a"
"alter table abcd add column a int after a",
"ALTER TABLE `xes_qiwei_teacher_relation` CHANGE `bind_time` "
+ "`bind_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '绑定时间';"
};
JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);
Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.any(RowMapper.class)))
Expand Down