in ambari-infra-solr-client/src/main/python/solrDataManager.py [0:0]
def create_block(tmp_file_path, solr_kinit_command, curl_prefix, solr_query_url_prefix, filter_field, id_field, range_end,
write_block_size, prev_lot_end_value, prev_lot_end_id, json_file, exclude_field_list, skip_date_usage):
if os.path.exists(tmp_file_path):
os.remove(tmp_file_path)
tmp_file = open(tmp_file_path, 'w')
logger.debug("Created tmp file %s", tmp_file_path)
init_file(tmp_file, json_file)
records = 0
done = False
while records < write_block_size:
if skip_date_usage:
if prev_lot_end_id:
fq = "({0}:{{\"{1}\"+TO+*])".format(id_field, prev_lot_end_id)
url = "{0}&fq={1}".format(solr_query_url_prefix, quote(fq, safe="/+\"*"))
else:
url = "{0}".format(solr_query_url_prefix)
else:
if prev_lot_end_value:
fq_prev_end_rest = "({0}:\"{1}\"+AND+{2}:{{\"{3}\"+TO+*])".format(filter_field, prev_lot_end_value, id_field,
prev_lot_end_id)
fq_new = "{0}:{{\"{1}\"+TO+\"{2}\"]".format(filter_field, prev_lot_end_value, range_end)
fq = "{0}+OR+{1}".format(fq_prev_end_rest, fq_new)
else:
fq = "{0}:[*+TO+\"{1}\"]".format(filter_field, range_end)
url = "{0}&fq={1}".format(solr_query_url_prefix, quote(fq, safe="/+\"*"))
curl_command = "{0} {1}".format(curl_prefix, url)
rsp = query_solr(solr_kinit_command, url, curl_command, "Obtaining")
if rsp['response']['numFound'] == 0:
done = True
break
for doc in rsp['response']['docs']:
last_doc = doc
add_line(tmp_file, doc, json_file, records, exclude_field_list)
records += 1
if records == write_block_size:
break
prev_lot_end_value = last_doc[filter_field] if not skip_date_usage else prev_lot_end_value
prev_lot_end_id = last_doc[id_field]
sys.stdout.write("\r{0} records are written".format(records))
sys.stdout.flush()
if verbose and records < write_block_size:
print()
logger.debug("Collecting next lot of data")
finish_file(tmp_file, json_file)
sys.stdout.write("\n")
logger.debug("Finished data collection")
return [done, records, prev_lot_end_value, prev_lot_end_id]