From 42254e8c0b83662e9030a3fdd435b47d9a0b5898 Mon Sep 17 00:00:00 2001 From: Liang Guo Date: Fri, 19 Sep 2014 12:13:46 -0700 Subject: [PATCH] Fix vtgate_cursor with missing func --- py/vtdb/vtgate_cursor.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/py/vtdb/vtgate_cursor.py b/py/vtdb/vtgate_cursor.py index f571b5bd00..4f9a1b215d 100644 --- a/py/vtdb/vtgate_cursor.py +++ b/py/vtdb/vtgate_cursor.py @@ -300,3 +300,15 @@ class StreamVTGateCursor(VTGateCursor): if val is None: raise StopIteration return val + + +# assumes the leading columns are used for sorting +def sort_row_list_by_columns(row_list, sort_columns=(), desc_columns=()): + for column_index, column_name in reversed([x for x in enumerate(sort_columns)]): + og = operator.itemgetter(column_index) + if type(row_list) != list: + row_list = sorted( + row_list, key=og, reverse=bool(column_name in desc_columns)) + else: + row_list.sort(key=og, reverse=bool(column_name in desc_columns)) + return row_list