我有一套Hive表,不是在兽人的格式,也没有扣。我想把它们的格式改成兽人的,也要把它们扣起来。在网上找不到具体的答案。任何回答或指导都将不胜感激。配置单元版本是2.3.5或者是否有可能在spark(pyspark或scala)中完成?最简单的解决方案是创建一个新表,该表采用orc格式,然后从旧表插入。寻找就地解决方案。
zpgglvta1#
创建bucketed表并使用insert overwrite将数据加载到其中:
CREATE TABLE table_bucketed(col1 string, col2 string)CLUSTERED BY(col1) INTO 10 BUCKETSSTORED AS ORC;INSERT OVERWRITE TABLE table_bucketedselect ... from table_not_bucketed
CREATE TABLE table_bucketed(col1 string, col2 string)
CLUSTERED BY(col1) INTO 10 BUCKETS
STORED AS ORC;
INSERT OVERWRITE TABLE table_bucketed
select ...
from table_not_bucketed
另请参见分类的带扣表。
ehxuflar2#
配置单元:使用暂存表读取未绑定的数据(假设 TEXTFILE 格式)使用以下命令:
TEXTFILE
CREATE TABLE staging_table( col1 colType, col2 colType, ... coln colType)STORED AS TEXTFILELOCATION '/path/of/input/data';CREATE TABLE target_table( col1 colType, col2 colType, ... coln colType)CLUSTERED BY(col1) INTO 10 BUCKETSSTORED AS ORC;INSERT OVERWRITE TABLE table_bucketedSELECT col1, col2, ..., colnFROM staging_table;
CREATE TABLE staging_table(
col1 colType,
col2 colType, ...
coln colType
)
STORED AS
LOCATION
'/path/of/input/data';
CREATE TABLE target_table(
SELECT
col1, col2, ..., coln
FROM
staging_table;
同样的方法也可以在 **Spark**DataFrame APIs (假设 CSV 格式)如下:
**Spark**DataFrame APIs
CSV
df = spark.read.format("csv") .option("inferSchema", "true") .option("header", "true") .option("delimiter", ",") .option("path", "/path/of/input/data/") .load()df.write.format("orc") .option("path", "/path/of/output/data/") .save()
df = spark.read.format("csv")
.option("inferSchema", "true")
.option("header", "true")
.option("delimiter", ",")
.option("path", "/path/of/input/data/")
.load()
df.write.format("orc")
.option("path", "/path/of/output/data/")
.save()
2条答案
按热度按时间zpgglvta1#
创建bucketed表并使用insert overwrite将数据加载到其中:
另请参见分类的带扣表。
ehxuflar2#
配置单元:使用暂存表读取未绑定的数据(假设
TEXTFILE
格式)使用以下命令:同样的方法也可以在
**Spark**DataFrame APIs
(假设CSV
格式)如下: