[英]Create table in HIVE with same columns as another table?
I want to create table from some metadata of another table in hive. 我想从配置单元中另一个表的一些元数据创建表。 I'm using hive. 我正在使用蜂巢。
I know from this question that the metatdata can be retrieved from the table by INFORMATION_SCHEMA.COLUMNS
in sql: 我从这个问题知道,元数据可以通过sql中的INFORMATION_SCHEMA.COLUMNS
从表中检索:
Does HIVE
have a similar access to metadata of a table to allow me to create a table using the columns of another table? HIVE
是否具有对表元数据的类似访问权限,以允许我使用另一个表的列创建表? Essentially, I'm copying a table without all of the tuples. 本质上,我要复制一个没有所有元组的表。
This is the best thing I have so far: 到目前为止,这是我最好的事情:
create table <table_name>( (select <table_name> from INFORMATION_SCHEMA.COLUMNS)) row format delimited fields by '|';
You can use LIKE
so the new table gets the structure but not the data. 您可以使用LIKE
以便新表获得结构而不是数据。
CREATE TABLE yourtable
LIKE table2;
You can try CTAS
syntax: 您可以尝试CTAS
语法:
CREATE TABLE new_table_name
AS
SELECT *
FROM old_table_name
WHERE 1 = 2;
I believe this will do the trick: 我相信这可以解决问题:
DROP TABLE IF EXISTS schema.New_Table;
CREATE TABLE New_Table
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\034' LINES TERMINATED BY '\012'
STORED AS TEXTFILE location '/IC/New_Table'
AS
select *
from Old_Table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.