Adding Spark SQL in ES and refactoring