从另一表插入数据后,按列分区的HIVE变为全0

时间:2018-09-16 23:37:13

标签: hadoop hive hdfs hortonworks-sandbox

我正在使用Hortonworks在HIVE中创建分区表,并使用HIVE中的另一个表将数据插入其中。问题是,将数据插入创建的表后,即使原始表中的任何值都不为0,结果表中分区列(passenger_count)中的所有值仍显示为0。

以下是我创建分区表并将数据插入其中的步骤:

  1. 运行以下查询以创建名为“ date_partitioned”的表:

    create table date_partitioned
    (tpep_dropoff_datetime string, trip_distance double)
    partitioned by (passenger_count int);
    
  2. 运行以下查询,以将数据从另一个现有表插入到“ date_partitioned”表中:

    INSERT INTO TABLE date_partitioned
    PARTITION (passenger_count)
    SELECT tpep_dropoff_datetime, trip_distance, passenger_count
    FROM trips_raw;
    

“ trips_raw”的列类型和样本值显示在以下屏幕截图中: enter image description here enter image description here

如您所见,“ passenger_count”列为int类型,并且包含非零值。但是,当我查看“ date_partitioned”表的结果时,“ passenger_count”列的值都显示为0。该表还创建了一个重复的“ passenger_count”(因此它有2个“ passenger_count”列,其中一列为空)。您可以从下面的屏幕截图中看到:

enter image description here enter image description here

任何建议将不胜感激。我很好奇为什么原始列不为0时'passenger_count'在结果表中显示0,以及为什么结果表中还有一个额外的'passenger_count'列。

1 个答案:

答案 0 :(得分:2)

您确定为passenger_count加载的所有行均为0吗?您可以在两个表上执行COUNT和GROUP BY passenger_count吗?也许您只是采样所有零?