Hive中造一行或多行常量行数据
1、造一行常量数据SQL
select "col1","col2","col3"
运行结果 :
2、造多行常量数据SQL
2.1 最直接的简单写法(只最后一列加别名)
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "XXXXX") ,
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}') AS value
UNION
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "YYYYY") ,
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}') AS value
运行结果 :
2.2 最直接的简单写法(每一列加别名)
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "XXXXX") AS KEY,
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}') AS value
UNION
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "YYYYY") AS KEY,
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}') AS value
UNION
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "ZZZZZ") AS KEY,
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}') AS value
运行结果 :
2.3 最笨的写法
SELECT
*
FROM
(
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "XXXXX"),
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}')
)
aa
UNION
SELECT
*
FROM
(
SELECT
concat('AAA', ':', "BBB", '_PP', ':', "YYYYY"),
concat('{"Id":"', "12323213", '","url":"', "http://helloworld.com/hello.html", '","code":"', "hello", '"}')
)
bb
运行结果:
备注:
1、在造多行数据时,若用前两种,在最后一列经测试需要加别名,否则提示语法错误
类似:FAILED: ParseException line 7:0 missing EOF at 'SELECT' near 'UNION'