" select a.id, a.original_url from "+ImpalaConnector.databaseName+".assignment a\n"+
" select a.id, a.original_url from "+ImpalaConnector.databaseName+".assignment a\n"+
" union all\n"+
" union all\n"+
" select pl.id, pl.original_url from "+ImpalaConnector.databaseName+".payload pl) as existing on existing.id=p.id and existing.original_url=pu.url\n"+
" select pl.id, pl.original_url from "+ImpalaConnector.databaseName+".payload pl) as existing on existing.id=p.id and existing.original_url=pu.url\n"+
"where d.allow_harvest=true and existing.id is null and coalesce(attempts.counts, 0) <= "+ControllerConstants.MAX_ATTEMPTS_PER_RECORD+" and not exists (select 1 from "+ImpalaConnector.databaseName+".attempt a where a.id=p.id and a.error_class = 'noRetry')\n" +
"where d.allow_harvest=true and existing.id is null and coalesce(attempts.counts, 0) <= "+ControllerConstants.MAX_ATTEMPTS_PER_RECORD+" and not exists (select 1 from "+ImpalaConnector.databaseName+".attempt a where a.id=p.id and a.error_class = 'noRetry' limit 1)\n" +
"limit "+(assignmentsLimit*10)+") as non_distinct_results\n"+
"limit "+(assignmentsLimit*10)+") as non_distinct_results\n"+
"order by coalesce(attempt_count, 0), reverse(pubid), url\n"+
"order by coalesce(attempt_count, 0), reverse(pubid), url\n"+
"limit "+assignmentsLimit+") as findAssignmentsQuery";
"limit "+assignmentsLimit+") as findAssignmentsQuery";