触发图表跳转报错 Illegal mix of collations 的解决方法


飞致云 发布于 2024-12-30 / 29 阅读 / 0 评论 /
1 报错现象 打开 DataEase 仪表板或大屏,触发跳转事件,或编辑图表开启跳转时,会弹出报错,如下图所示: 完整报错信息如下: Request processing failed: org.springframework.jdbc.UncategorizedSQLException: ###

1 报错现象

打开 DataEase 仪表板或大屏,触发跳转事件,或编辑图表开启跳转时,会弹出报错,如下图所示:

完整报错信息如下:

Request processing failed: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause:
java.sql.SQLException: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '=' ###
 The error may exist in class path resource [mybatis/ExtVisualizationLinkJumpMapper.xml]
### The error may involve defaultParameterMap ### The error occurred while setting parameters ###
SQL: SELECT core_dataset_table_field.id AS source_field_id, core_dataset_table_field.de_type AS source_de_type,
core_dataset_table_field.NAME AS source_field_name, visualization_link_jump_info.id, visualization_link_jump_info.link_jump_id,
visualization_link_jump_info.link_type, visualization_link_jump_info.jump_type, visualization_link_jump_info.window_size,
visualization_link_jump_info.target_dv_id, visualization_link_jump_info.content, xpack_share.uuid AS publicJumpId, ifnull(
visualization_link_jump_info.checked, 0 ) AS checked, ifnull( visualization_link_jump_info.attach_params, 0 ) AS attach_params,
visualization_link_jump_target_view_info.target_id, visualization_link_jump_target_view_info.target_view_id,
visualization_link_jump_target_view_info.target_field_id, visualization_link_jump_target_view_info.target_type,
visualization_link_jump_target_view_info.source_field_active_id, visualization_outer_params_info.param_name as outer_params_name
FROM core_chart_view LEFT JOIN core_dataset_table_field ON core_chart_view.table_id = core_dataset_table_field.dataset_group_id
LEFT JOIN visualization_link_jump ON core_chart_view.id = visualization_link_jump.source_view_id AND visualization_link_jump.id = ?
LEFT JOIN visualization_link_jump_info ON visualization_link_jump.id = visualization_link_jump_info.link_jump_id AND core_dataset_table_field.id = visualization_link_jump_info.source_field_id
LEFT JOIN visualization_link_jump_target_view_info ON visualization_link_jump_info.id = visualization_link_jump_target_view_info.link_jump_info_id
LEFT JOIN xpack_share ON xpack_share.creator = ? AND visualization_link_jump_info.target_dv_id = xpack_share.resource_id left join visualization_outer_params_info on visualization_outer_params_info.params_info_id = visualization_link_jump_target_view_info.target_view_id WHERE core_chart_view.id = ? AND core_chart_view.type != 'VQuery' ORDER BY CONVERT ( core_dataset_table_field.NAME USING gbk)
### Cause: java.sql.SQLException: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '=' ; uncategorized SQLException; SQL state [HY000];
error code [1267]; Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='

造成报错的原因是,跳转需要的几个表,其中的排序规则发生了变化,导致报错。

2 解决方法

从报错中可以找到涉及到的数据表有以下几个:

 core_chart_view 
 core_dataset_table_field 
 visualization_link_jump
 visualization_link_jump_info
 visualization_link_jump_target_view_info
 xpack_share
 visualization_outer_params_info 

查询相关表的排序规则:

SELECT
    TABLE_NAME,
    COLUMN_NAME,
    CHARACTER_SET_NAME,
    COLLATION_NAME
FROM
    information_schema.COLUMNS
WHERE
    TABLE_SCHEMA = 'dataease' AND
    (TABLE_NAME IN ('xpack_share', 'visualization_link_jump_target_view_info', 'visualization_link_jump_info','core_chart_view', 'core_dataset_table_field','visualization_link_jump','visualization_outer_params_info'))
ORDER BY COLUMN_NAME;

输出的结果中可以发现,有几个字段的排序规则是 utf8mb4_general_ci;

+------------------------------------------+------------------------+--------------------+--------------------+
| TABLE_NAME                               | COLUMN_NAME            | CHARACTER_SET_NAME | COLLATION_NAME     |
+------------------------------------------+------------------------+--------------------+--------------------+
| visualization_link_jump_info             | content                | utf8mb4            | utf8mb4_general_ci |  
| visualization_link_jump_info             | jump_type              | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump                  | link_jump_info         | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump_info             | link_type              | utf8mb4            | utf8mb4_general_ci |
| xpack_share                              | pwd                    | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump_target_view_info | target_field_id        | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump_target_view_info | target_type            | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump_target_view_info | target_view_id         | utf8mb4            | utf8mb4_general_ci |
| xpack_share                              | uuid                   | utf8mb4            | utf8mb4_general_ci |
| visualization_link_jump_info             | window_size            | utf8mb4            | utf8mb4_general_ci |

正常的环境中,所有的排序规则都是 utf8mb4_0900_ai_ci,将 utf8mb4_general_ci 改为 utf8mb4_0900_ai_ci 即可解决:

-- 修改 visualization_link_jump_info 表中的 content 列
ALTER TABLE visualization_link_jump_info
MODIFY COLUMN content VARCHAR(4000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_info 表中的 jump_type 列
ALTER TABLE visualization_link_jump_info
MODIFY COLUMN jump_type VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump 表中的 link_jump_info 列
ALTER TABLE visualization_link_jump
MODIFY COLUMN link_jump_info VARCHAR(4000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_info 表中的 link_type 列
ALTER TABLE visualization_link_jump_info
MODIFY COLUMN link_type VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 xpack_share 表中的 pwd 列
ALTER TABLE xpack_share
MODIFY COLUMN pwd VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_target_view_info 表中的 target_field_id 列
ALTER TABLE visualization_link_jump_target_view_info
MODIFY COLUMN target_field_id VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_target_view_info 表中的 target_type 列
ALTER TABLE visualization_link_jump_target_view_info
MODIFY COLUMN target_type VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_target_view_info 表中的 target_view_id 列
ALTER TABLE visualization_link_jump_target_view_info
MODIFY COLUMN target_view_id VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 xpack_share 表中的 uuid 列
ALTER TABLE xpack_share
MODIFY COLUMN uuid VARCHAR(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
 
-- 修改 visualization_link_jump_info 表中的 window_size 列
ALTER TABLE visualization_link_jump_info
MODIFY COLUMN window_size VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

执行完后,不需要重启服务,验证功能没有报错,问题解决。



是否对你有帮助?