MySqlUpdateParser extends MySqlSqlParser { protected void checkUpdateColumn(){ MySqlUpdateStatement update = (MySqlUpdateStatement)statement; String tableName = StringUtil.removeBackquote(update.getTableName().getSimpleName()); List<SQLUpdateSetItem> updateSetItem = update.getItems(); String[] partitionColumns = BaymaxContext.getPartitionColumns(tableName); if(partitionColumns != null && partitionColumns.length > 0 && updateSetItem != null && updateSetItem.size() > 0) { for(SQLUpdateSetItem item : updateSetItem) { String column = StringUtil.removeBackquote(item.getColumn().toString()); if (StringUtil.contains(partitionColumns, column)){ throw new BayMaxException("分区表的分区键不能被更新:" + tableName + "." + column); } } } }  @Override void changeSql(ParseResult result, ExecutePlan plan);  }
@Test public void testCheckUpdateColumn() throws Exception { testCheckUpdateColumn(UpdateTestSql.u1); testCheckUpdateColumn("update table1 set a='1' where (a = 1 or b = 2) and c = 3"); }