Index: hcatalog/src/test/e2e/templeton/tests/jobstatus.conf =================================================================== --- hcatalog/src/test/e2e/templeton/tests/jobstatus.conf (revision 1535585) +++ hcatalog/src/test/e2e/templeton/tests/jobstatus.conf (working copy) @@ -152,6 +152,37 @@ 'json_path' => {'$[-1:]' => 'job_.*'}, 'status_code' => 200, }, + { + # GET jobs?user.name=UNAME_OTHER&fields=*, get all the details of the oldest 2 jobs whose + # start time is 201*, ie. year starts with 201* + 'num' => 9, + 'depends_on' => 'JOBS_1,JOBS_2,JOBS_3', + 'method' => 'GET', + 'url' => ':TEMPLETON_URL:/templeton/v1/jobs?user.name=:UNAME_OTHER:&fields=*&numrecords=2&starttime=201', + 'format_header' => 'Content-Type: application/json', + 'json_path' => {'$[-1:].id' => 'job_.*', + '$[-1:].detail.status.jobId' => 'job_.*', + '$[-1:].detail.status.runState' => '\\d+', + '$[-1:].detail.status.jobId' => 'job_.*', + '$[-1:].detail.status.jobComplete' => 'true', + '$[-1:].detail.profile.user' => ':UNAME_OTHER:', + '$[-1:].detail.profile.jobFile' => '^.+$', + '$[-1:].detail.profile.url' => '^.+$', + '$[-1:].detail.profile.queueName' => '^.+$', + '$[-1:].detail.profile.jobName' => 'loadstore\.pig', + '$[-1:].detail.profile.jobID.id' => '\\d+', + '$[-1:].detail.profile.jobID.jtIdentifier' => '\\d+', + '$[-1:].detail.profile.jobId' => 'job_.*', + '$[-1:].detail.id' => 'job_.*', + '$[-1:].detail.parentId' => 'job_.*', + '$[-1:].detail.percentComplete' => '100%', + '$[-1:].detail.exitValue' => '0', + '$[-1:].detail.user' => ':UNAME_OTHER:', + '$[-1:].detail.callback' => '^.+$', + '$[-1:].detail.completed' => 'done', + }, + 'status_code' => 200, + }, ] } Index: hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java =================================================================== --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java (revision 1535585) +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java (working copy) @@ -861,7 +861,9 @@ @Path("jobs") @Produces({MediaType.APPLICATION_JSON}) public List showJobList(@QueryParam("fields") String fields, - @QueryParam("showall") boolean showall) + @QueryParam("showall") boolean showall, + @QueryParam("starttime") String starttime, + @QueryParam("numrecords") String numrecords) throws NotAuthorizedException, BadParam, IOException, InterruptedException { verifyUser(); @@ -877,7 +879,25 @@ ListDelegator ld = new ListDelegator(appConf); List list = ld.run(getDoAsUser(), showall); List detailList = new ArrayList(); + int currRecord = 0; + int numRecords = numrecords == null ? -1 : Integer.parseInt(numrecords); + numRecords = numRecords >= 0 ? numRecords : -1; + + // Sort the list by starttime to get the top numRecords + Collections.sort(list); + for (String job : list) { + // If numRecords = -1, fetch all records since the starttime. + // Hence skip all the below checks when numRecords = -1. + // If currRecord >= numRecords, we have fetched the top #numRecords + // for the given starttime + if (numRecords != -1 && currRecord >= numRecords) { + break; + } + // If the current record needs to be returned, increment the counter + else if (numRecords != -1 && starttime != null && job.startsWith("job_"+starttime)) { + currRecord++; + } JobItemBean jobItem = new JobItemBean(); jobItem.id = job; if (showDetails) {