按照以下脚本执行,导出txt文件即可得到相应的hive字段映射。

select concat('`', column_name, '`') colname,
       case
         when NUMERIC_PRECISION is not null and
              (data_type = 'decimal' or data_type = 'numeric') then
          concat('decimal(', NUMERIC_PRECISION, ',', NUMERIC_SCALE, ')')
         when (CHARACTER_MAXIMUM_LENGTH is not null or
              data_type = 'uniqueidentifier') and
              data_type not like '%text%' then
          'string'
         when data_type = 'datetime' then
          'timestamp'
         when data_type = 'money' then
          'decimal(9,2)'
         when data_type = 'tinyint' then
          'int'
         else
          data_type
       end as data_type,
       concat('comment', ' \'',COLUMN_COMMENT,' '') as comment,
       ' ,' as splitCharacter
  from information_schema.columns
 where table_name = 'xxxxxxxxxx'

 

相关文章:

  • 2021-05-25
  • 2021-06-15
  • 2022-01-18
  • 2021-09-26
  • 2021-08-17
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2021-12-09
  • 2022-02-19
  • 2022-02-17
相关资源
相似解决方案