mysql表結構轉hive表結構,字段映射腳本


按照以下腳本執行,導出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'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM