gpt4 book ai didi

hadoop - 在 Hive 表中分区

转载 作者:可可西里 更新时间:2023-11-01 16:32:14 26 4
gpt4 key购买 nike

在博客中,在 Hive 的 PARTITIONING FUNCTIONS 主题中,他们在以下模式中创建了一个表。

    CREATE TABLE sales (
sales_order_id BIGINT,
order_amount FLOAT,
order_date STRING,
due_date STRING,
customer_id BIGINT
)
PARTITIONED BY (country STRING, year INT, month INT, day INT) ;

并将分区数据插入到销售表中,如下所示。

INSERT INTO sales
PARTITION (country = 'US', year = 2012, month = 12, day = 22)
SELECT sales_order_id,
order_amount,
due_date,
customer_id,
cntry,
yr,
mo,
d
FROM source_view
WHERE cntry = 'US'
AND yr = 2012
AND mo = 12
AND d = 22 ;

我的疑问在这里出现了。由于在创建表架构中没有像 cntry or yr or mo or d 这样的字段,他们如何在插入查询中提到 cntry or yr or mo or d。怎么可能?。作者在查询中是否犯了任何错误,或者是否有任何可用的选项,如别名。

最佳答案

虽然分区字段没有明确创建为列,但它们是(伪)列并且可以查询。

来自 Hive's docs :

the partition you create makes a pseudocolumn on which you can query

另外(来自 Insert documentation ):

Inserts can be done to a table or a partition. If the table is partitioned, then one must specify a specific partition of the table by specifying values for all of the partitioning columns.

关于hadoop - 在 Hive 表中分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25376419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com