可以做
create table <mytable> as select <query statement>
使用
row format delimited fields terminated by '|';
或做
create table <mytable> like <other_table> row format delimited fields terminated by '|';
语言手册似乎没有表明..但是我过去曾做过的东西。
创建表作为select(ctas)是可能的。
您可以在下面尝试:
CREATE TABLE new_test
row format delimited
fields terminated by '|'
STORED AS RCFile
AS select * from source where col=1
- 目标无法分区表。
- 目标不能是外部表。
- 它复制结构和数据
创建表,也可以在Hive中。
- 它只是复制源表定义。
假设我们有一个称为 employee
hive> SHOW CREATE TABLE employee;
OK
CREATE EXTERNAL TABLE employee(
id string,
fname string,
lname string,
salary double)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'colelction.delim'=':',
'field.delim'=',',
'line.delim'='n',
'serialization.format'=',')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'maprfs:/user/hadoop/data/employee'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='false',
'numFiles'='0',
'numRows'='-1',
'rawDataSize'='-1',
'totalSize'='0',
'transient_lastDdlTime'='1487884795')
创建一个
person
表,例如employee
CREATE TABLE person LIKE employee;
创建一个
person
外部表,例如employee
CREATE TABLE person LIKE employee LOCATION 'maprfs:/user/hadoop/data/person';
然后使用
DESC person;
要查看新创建的表模式。
上面提供的两个答案正常工作。
- 创建表人作为select * from雇员; select *
- 创建像员工这样的桌子人;