【问题标题】:how to properly import csv data set using kite-dataset partitioned schema?如何使用风筝数据集分区模式正确导入 csv 数据集?
【发布时间】:2016-10-27 11:50:38
【问题描述】:

我正在使用来自 MovieLens 的公开可用的 csv 数据集 我为 rating.csv 创建了一个分区数据集:

kite-dataset create ratings --schema rating.avsc --partition-by year-month.json --format parquet

这是我的年月.json:

[ {
  "name" : "year",
  "source" : "timestamp",
  "type" : "year"
}, {
  "name" : "month",
  "source" : "timestamp",
  "type" : "month"
} ]

这是我的 csv 导入命令:

mkite-dataset csv-import ratings.csv ratings

导入完成后,我运行这个命令来查看年月分区是否实际创建在哪里:

hadoop fs -ls /user/hive/warehouse/ratings/

我注意到,只创建了一个年份分区,并且在其中一个单个月份分区被创建:

[cloudera@quickstart ml-20m]$ hadoop fs -ls /user/hive/warehouse/ratings/
Found 3 items
drwxr-xr-x   - cloudera supergroup          0 2016-06-12 18:49 /user/hive/warehouse/ratings/.metadata
drwxr-xr-x   - cloudera supergroup          0 2016-06-12 18:59 /user/hive/warehouse/ratings/.signals
drwxrwxrwx   - cloudera supergroup          0 2016-06-12 18:59 /user/hive/warehouse/ratings/year=1970

[cloudera@quickstart ml-20m]$ hadoop fs -ls /user/hive/warehouse/ratings/year=1970/
Found 1 items
drwxrwxrwx   - cloudera supergroup          0 2016-06-12 18:59 /user/hive/warehouse/ratings/year=1970/month=01

进行这种分区导入的正确方法是什么,这将导致创建所有年份和所有月份的分区?

【问题讨论】:

    标签: hadoop hdfs cloudera-cdh hadoop-partitioning kite-dataset


    【解决方案1】:

    在时间戳末尾添加三个零。

    使用下面的shell脚本来做

    #!/bin/bash
    
    # add the CSV header to both files
    head -n 1 ratings.csv > ratings_1.csv
    head -n 1 ratings.csv > ratings_2.csv
    
    # output the first 10,000,000 rows to ratings_1.csv
    # this includes the header, and uses tail to remove it
    head -n 10000001 ratings.csv | tail -n +2 | awk '{print "000" $1 }' >> ratings_1.csv
    
        enter code here
    
    # output the rest of the file to ratings_2.csv
    # this starts at the line after the ratings_1 file stopped
    tail -n +10000002 ratings.csv | awk '{print "000" $1 }' >> ratings_2.csv
    

    我也有这个问题,加了3个零就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 2012-05-29
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多