1

Ich bin mit der öffentlich verfügbaren csv-Datensatz von Movielens Arbeits ich einen partitionierten Datensatz für den ratings.csv erstellt habe:Wie CSV-Datensatz mit Kite-Dataset partitionierten Schema ordnungsgemäß importieren?

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

Hier ist meine Jahr-month.json:

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

Hier ist mein cSV-Import-Befehl:

mkite-dataset csv-import ratings.csv ratings 

Nachdem der Import abgeschlossen, ich diesen Befehl ausgeführt wird, ob Jahr und Monat Partitionen zu sehen wo in der Tat erstellt:

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

Was habe ich bemerkt, dass nur Partition ein einziges Jahr erstellt wurde, und in der es eine eine einzige Monat Partition erstellt wurde:

[[email protected] 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 

[[email protected] 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 

Was ist der richtige Art, einen solchen partitionierten Import durchzuführen, was dazu führen würde, dass alle Jahre und alle Monats-Partitionen erstellt würden?

Antwort

0

Fügen Sie drei Nullen am Ende für den Zeitstempel hinzu.

den unten stehenden Shell-Skript verwenden, um es zu tun

#!/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 

Auch ich hatte dieses Problem, und es wurde beschlossen, nach 3 Nullen hinzugefügt.

Verwandte Themen