mysql表 转 hive表 建表语句 Error while compiling statement: FAILED: ParseException in column name or prima

SELECT 'CREATE TABLE IF NOT EXISTS','你的hive表名字','(','',''
UNION ALL
SELECT CONCAT('`',column_name,'`') colname,
       CASE WHEN NUMERIC_PRECISION IS NOT NULL AND (data_type='decimal' OR data_type='numeric' OR data_type = 'money') THEN
                  'decimal(16,2)'
            WHEN data_type = 'datetime' THEN 
                'timestamp'
	    WHEN data_type = 'tinyint' THEN  
                'int'  		
            ELSE
                'string'
       END AS data_type,
       ' comment ',
        CASE
    WHEN COLUMN_COMMENT IS NULL THEN
        CONCAT('\'',COLUMN_NAME,'\'')
    ELSE
        CONCAT('\'',REPLACE(COLUMN_COMMENT,';',','),'\'')
    END AS COLUMN_COMMENT,
       ' ,' AS splitCharacter
 FROM information_schema.columns
WHERE table_name = '你的mysql表名字' AND table_schema='你的mysql表所在库db'
UNION ALL
SELECT ')','comment',CONCAT('\'',TABLE_COMMENT,'\''),'stored as orc','' FROM information_schema.tables WHERE table_name = '你的mysql表名字' AND table_schema='你的mysql表所在库db'

在mysql客户端中执行以上sql,即可得到建表语句,点击图下按钮,复制去hive中建表:
mysql表 转 hive表 建表语句 Error while compiling statement: FAILED: ParseException in column name or prima_第1张图片
mysql表 转 hive表 建表语句 Error while compiling statement: FAILED: ParseException in column name or prima_第2张图片
不删掉最后一行的,逗号就会报错:
Error while compiling statement: FAILED: ParseException line 23:0 cannot recognize input near ‘)’ ‘comment’ ‘‘进项发票表’’ in column name or primary key or foreign key
解决方法:删掉最后一个逗号即可。
mysql表 转 hive表 建表语句 Error while compiling statement: FAILED: ParseException in column name or prima_第3张图片
mysql表 转 hive表 建表语句 Error while compiling statement: FAILED: ParseException in column name or prima_第4张图片

你可能感兴趣的:(hive)