Create Table As Select in Impala with NULL column

Create Table As Select in Impala with NULL column

上下文

我 select 来自 table 的一些数据并为与 NULL 的连接初始化一个虚拟列。

SELECT
    col_a as a,
    NULL  as b
FROM dummy_table;

-- Output
+---+----+
| a | b  |
+---+----+
| 1 |NULL|
|...|NULL|
+---+----+

这有效并产生了正确的输出。

问题

我想将该输出存储在 table 中以进行进一步处理。

CREATE TABLE IF NOT EXISTS temp_table STORED AS parquet AS
    SELECT
        col_a as a,
        NULL  as b
    FROM dummy_table;

当第一个查询运行时,第二个查询没有运行并失败并出现以下错误:

AnalysisException: Unsupported type 'null_type' in column 'b' of table 'temp_table' CAUSED BY: TableLoadingException: Unsupported type 'null_type' in column 'b' of table 'temp_table'

为什么 table 创建失败,而 select 部分实际上在工作?

由于您仅提供 NULL 作为值,因此您的数据库无法确定新 table 列所需的数据类型。

只需将 NULL 值转换为您想要的类型即可。