Use DAS sort_rows instead of python set to preserve the order of records, fix #3967
Add sort_rows function and associated unit test