Es gibt keine Out-of-Box-Lösung für Ihr Problem, zuerst finden Sie die neueste Datei, dann laden Sie sie.
Java Beispiel:
/**
* Function to get latest file in directory
*/
public static String latestFileInDir(String dir) throws IOException, InterruptedException {
//Replace hadoop home
String command = "<HADOOP_HOME>/bin/hadoop fs -ls -R " + dir + " | awk -F\" \" '{print $6\" \"$7\" \"$8}' | sort -nr | head -1";
ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", command);
String op = null;
Process process = pb.start();
int errCode = process.waitFor();
if (errCode == 0) {
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
op = br.readLine();
}
return op;
}
Holen Sie sich aktuelle Verzeichnis und Last
rdd= sc.textfile(latestFileInDir("/home/sathya/location/"));
Wenn dies Ihre Frage beantwortet, können Sie als Antwort akzeptieren und das Thema schließen. was auch für andere hilfreich sein wird –
Es funktioniert, danke – sathiyarajan
Danke für die Annahme als Antwort :) –