这段 SQL 语句没有语法错误,但需要在运行前将 '$ {yyyyMMdd,-1d}' 替换为具体的日期值。同时,需要确保对应的表和视图已经创建,并且表中的字段名和数据类型与查询语句中的一致。

insert overwrite table dwd_mt_hive_dbs_df partition(ds=${yyyyMMdd,-1d})
select 
    dbs.db_id
    , 'desc'
    , db_location_uri
    , name
    , owner_name
    , owner_type
    , create_time
    , project.project_id as project_id
    , project.project_name as project_name
from (
    select *
    from ods_hivemeta_dbs_df
    where ds = ${yyyyMMdd,-1d}
) dbs
left join (
    -- 关联simba_project维表
    select 
        db_id
        , project_id 
        , project_name
    from (
        -- 存在1个db被多个project使用的场景,进行去重
        select 
            ROW_NUMBER() over (partition by db_id order by project_id desc) as row_num
            , db_id
            , project_id  
            , name as project_name
        from dim_pub_simba_project where ds = ${yyyyMMdd,-1d} and db_id is not null and deleted = 0
    )a where row_num = 1
) project on dbs.db_id=project.db_id

该 SQL 语句的功能如下:

  • 从 ods_hivemeta_dbs_df 表中获取当天(ds=${yyyyMMdd,-1d})的数据。
  • 将 'desc' 字段映射到 dwd_mt_hive_dbs_df 表的 'desc' 字段。
  • 左连接 dim_pub_simba_project 表,获取对应数据库的项目信息,并处理多个项目关联同一个数据库的情况。
  • 将数据插入到 dwd_mt_hive_dbs_df 表中,并分区到指定日期(ds=${yyyyMMdd,-1d})。
Hive SQL 语句解析:dwd_mt_hive_dbs_df 表数据加载

原文地址: https://www.cveoy.top/t/topic/oGxQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录