基表是日期分区,如何创建月分区增量物化视图

Viewed 7

需要对日期基表进行汇总,这样创建好之后分区是按月的,但是groupby的还是日期
CREATE MATERIALIZED VIEW dws_sc_pd_mes_test_record_mi_v
(report_date,factory_name,product_name,stations_name,sn_cnt)
BUILD IMMEDIATE REFRESH AUTO ON SCHEDULE EVERY 1 DAY STARTS '2025-06-28 00:30:00'
DUPLICATE KEY(report_date, factory_name, product_name, stations_name)
PARTITION BY (DATE_TRUNC(report_date, 'MONTH'))
DISTRIBUTED BY HASH(report_date, factory_name, product_name, stations_name) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 3",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"storage_medium" = "hdd",
"storage_format" = "V2",
"inverted_index_storage_format" = "V1",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false",
"group_commit_interval_ms" = "10000",
"group_commit_data_bytes" = "134217728",
"partition_sync_limit" = "15",
"partition_sync_time_unit" = "MONTH"
)
as
SELECT
report_date
,factory_name
,product_name
,stations_name
,count(distinct sn) as sn_cnt
FROM
ef_dws.dws_sc_pd_mes_test_record_v
where test_status_id != 3
group by
report_date
,factory_name
,product_name
,stations_name;

0 Answers