使用"as select"或"like"创建配置单元表,并指定分隔符



可以做

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
  1. 目标无法分区表。
  2. 目标不能是外部表。
  3. 它复制结构和数据

创建表,也可以在Hive中。

  1. 它只是复制源表定义。

假设我们有一个称为 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')
  1. 创建一个person表,例如employee

    CREATE TABLE person LIKE employee;

  2. 创建一个person外部表,例如employee

    CREATE TABLE person LIKE employee LOCATION 'maprfs:/user/hadoop/data/person';

  3. 然后使用 DESC person;要查看新创建的表模式。

上面提供的两个答案正常工作。

  1. 创建表人作为select * from雇员;
  2. select *
  3. 创建像员工这样的桌子人;

最新更新