Reorder materialization and cache insertion

In case of failures during materialization the current ordering means we cannot clean up RDDs that are cached when the table creation fails.
This patch fixes the cleanup issue by ordering table creation first followed by RDD materialization.