041.mysql-查询mysql元数据来格式化datax同步脚本,查询语句、拼接的json语句datax-mysql到hive

 

 

复制代码
--自动生成json数据
select
     TABLE_NAME ,
     concat (',',COLUMN_NAME) COLUMN_NAME  ,
     case when
     t.data_TYPE in('varchar','text') then 'string'
     when
     t.data_TYPE = 'decimal' then  t.COLUMN_TYPE 
     when
     t.data_TYPE = 'datetime' then 'timestamp'
     when
     t.data_TYPE = 'float' then 'double'
     else t.data_TYPE end data_TYPE
     ,
     concat('comment ''',COLUMN_COMMENT,'''') COLUMN_COMMENT ,
     concat ('{"name":"',COLUMN_NAME,'","type":"' ,
     case when
     t.data_TYPE in('varchar','text')  then 'string'
     when
     t.data_TYPE in('decimal', 'float') then 'double'
     when
     t.data_TYPE in('datetime') then 'timestamp'
     when
     t.data_TYPE in('tinyint','smallint') then 'int'
     else t.data_TYPE end ,'"},') data_TYPE  
from
    information_schema.columns  t
where
    TABLE_NAME = 'mk_event_popup_record'
    and TABLE_SCHEMA = 'cloud_cube_marketing'
;


-- 自动生成select语句
    select
         concat ('select ',group_concat(
         case when  DATA_TYPE ='datetime' 
              then  concat('date_format(',COLUMN_NAME,',''%Y-%m-%d %H:%i:%s'') ',COLUMN_NAME )
         else COLUMN_NAME end        
         order by ORDINAL_POSITION),' from ',table_name)  
    from
        information_schema.columns  t
    where
    TABLE_NAME = 'mk_event_popup_record'
    and TABLE_SCHEMA = 'cloud_cube_marketing'
复制代码

 

posted @   star521  阅读(167)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
历史上的今天:
2021-05-31 006.php-phpstudy启动、php的目录位置查看、浏览器测试
2021-05-31 000.软考-高级-信息项目管理师的总结2021.05.29
点击右上角即可分享
微信分享提示