getl.transform.SorterDatasetDriver.groovy Maven / Gradle / Ivy
package getl.transform
import getl.data.*
import getl.driver.VirtualDatasetDriver
import getl.exception.ExceptionGETL
import getl.utils.GenerationUtils
import groovy.transform.InheritConstructors
/**
* Sorted driver class
* @author Alexsey Konstantinov
*
*/
@InheritConstructors
class SorterDatasetDriver extends VirtualDatasetDriver {
static private List getFieldOrderBy(Dataset dataset) {
def res = dataset.params.fieldOrderBy as List
if (res == null) throw new ExceptionGETL("Required parameter \"fieldOrderBy\" in dataset")
return res
}
@Override
void openWrite(Dataset dataset, Map params, Closure prepareCode) {
Dataset ds = getDestination(dataset)
def fieldOrderBy = getFieldOrderBy(dataset)
ds.openWrite(params)
if (prepareCode != null) prepareCode.call(dataset.field)
dataset._driver_params.sorter_code = generateSortCode(fieldOrderBy)
dataset._driver_params.sorter_data = new LinkedList