Translation of Array-based Loop Programs to Optimized SQL-based Distributed Programs