如何基于主键模型的表,自动聚合生成新表

Viewed 28

我有一张旧表,如下:

-- demo.collision_component definition

CREATE TABLE `collision_component` (
  `cve` VARCHAR(255) NULL,
  `component_name` VARCHAR(255) NULL,
  `component_version` VARCHAR(255) NULL,
  `timestamp` BIGINT NULL,
  `component_vendor` VARCHAR(255) NULL,
  `intelligence_id` VARCHAR(255) NULL,
  `create_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=OLAP
UNIQUE KEY(`cve`, `component_name`, `component_version`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`cve`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);

基于这张表我想要再次聚合生成一张更加详细的表,方便查询,生成的新表逻辑如下,有什么方案可以类似物化视图一样自动更新吗?

SELECT
    CONCAT(`internal`.`demo`.`collision_component`.`component_name`, ':', `internal`.`demo`.`collision_component`.`component_version`) AS `component_info`,
    max(`internal`.`demo`.`collision_component`.`timestamp`) AS `refreshtime`,
    GROUP_CONCAT(`internal`.`demo`.`collision_component`.`cve`) AS `cve`
FROM
    `internal`.`demo`.`collision_component`
GROUP BY
    `internal`.`demo`.`collision_component`.`component_name`,
    `internal`.`demo`.`collision_component`.`component_version`;
1 Answers