Commit b5333e02 authored by 段英荣's avatar 段英荣

modify topic transfer

parent 8c9bc355
......@@ -149,38 +149,43 @@ class TableSlicerChunk(ITableChunk):
class TableSlicer(object):
def __init__(self, queryset, chunk_size=None, chunk_count=None, sep_list=None):
logging.info("duan add,before assert queryset")
assert isinstance(queryset, models.QuerySet)
logging.info("duan add,before assert chunk_size")
assert chunk_size is None or isinstance(chunk_size, six.integer_types)
logging.info("duan add,before assert chunk_count")
assert chunk_count is None or isinstance(chunk_count, six.integer_types)
logging.info("duan add,before assert sep_list")
assert sep_list is None or isinstance(sep_list, list)
logging.info("duan add,before assert chunk_size")
assert (chunk_size is not None) + (chunk_count is not None) + (sep_list is not None) == 1
logging.info("duan add,after assert chunk_size")
if sep_list is not None:
sep_list = list(sep_list)
else:
count = queryset.count()
if chunk_size is None:
chunk_size = count / chunk_count
index_list = list(range(0, count, chunk_size))
sep_list = [
queryset.order_by('pk').values_list('pk', flat=True)[index]
for index in index_list
]
logging.info("duan add,queryset count:%d" % count)
self._model = queryset.model
self._query = queryset.query
self._sep_list = [None] + sep_list + [None]
try:
logging.info("duan add,before assert queryset")
assert isinstance(queryset, models.QuerySet)
logging.info("duan add,before assert chunk_size")
assert chunk_size is None or isinstance(chunk_size, six.integer_types)
logging.info("duan add,before assert chunk_count")
assert chunk_count is None or isinstance(chunk_count, six.integer_types)
logging.info("duan add,before assert sep_list")
assert sep_list is None or isinstance(sep_list, list)
logging.info("duan add,before assert chunk_size")
assert (chunk_size is not None) + (chunk_count is not None) + (sep_list is not None) == 1
logging.info("duan add,after assert chunk_size")
logging.info("duan add,sep_list:%s" % str(sep_list))
if sep_list is not None:
sep_list = list(sep_list)
else:
count = queryset.count()
if chunk_size is None:
chunk_size = count / chunk_count
index_list = list(range(0, count, chunk_size))
sep_list = [
queryset.order_by('pk').values_list('pk', flat=True)[index]
for index in index_list
]
logging.info("duan add,queryset count:%d" % count)
self._model = queryset.model
self._query = queryset.query
self._sep_list = [None] + sep_list + [None]
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
def chunks(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment