版本: Doris - 2.0.5 -rc02
建表语句
参考知乎文章
Apache Doris 行列转换可以这样玩
CREATE TABLE cdp.tb_score_01
(
id INT(11) NOT NULL,
userid VARCHAR(20) NOT NULL COMMENT '用户id',
subject VARCHAR(20) COMMENT '科目',
score DOUBLE COMMENT '成绩'
) DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false"
);
执行数据插入语句:
INSERT INTO tb_score_01
VALUES (1, '001', '语文', 90);
INSERT INTO tb_score_01
VALUES (2, '001', '数学', 92);
INSERT INTO tb_score_01
VALUES (3, '001', '英语', 80);
INSERT INTO tb_score_01
VALUES (4, '002', '语文', 88);
INSERT INTO tb_score_01
VALUES (5, '002', '数学', 90);
INSERT INTO tb_score_01
VALUES (6, '002', '英语', 75.5);
INSERT INTO tb_score_01
VALUES (7, '003', '语文', 70);
INSERT INTO tb_score_01
VALUES (8, '003', '数学', 85);
INSERT INTO tb_score_01
VALUES (9, '003', '英语', 90);
INSERT INTO tb_score_01
VALUES (10, '003', '政治', 82);
执行以下查询时提示报错:
WITH t1 AS ( -- 子查询使用map_agg函数得到mapArrs字段
SELECT userid AS map_agg_user_id, map_agg(subject, score) AS mapArrs FROM tb_score_01 GROUP BY 1
)
, t2 AS (
SELECT id,
userid,
subject,
score
FROM tb_score_01
LEFT JOIN t1
ON tb_score_01.userid = t1.map_agg_user_id
)
SELECT *
FROM t2;
报错信息:
[HY000][1105] errCode = 2, detailMessage = Unexpected exception: org.apache.doris.common.AnalysisException: errCode = 2, detailMessage = No matching function with signature: if(boolean, null_type, MAP<varchar(20),double>).
报错信息截图: