package framework.rasdaman;

import data.DataGenerator;
import framework.QueryExecutor;
import framework.context.BenchmarkContext;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import util.DomainUtil;
import util.IO;
import util.Pair;
import util.ProcessExecutor;
import util.StopWatch;

/**
 * @author George Merticariu
 */
public class RasdamanQueryExecutor extends QueryExecutor<RasdamanSystem> {

    public RasdamanQueryExecutor(RasdamanSystem systemController, BenchmarkContext benchmarkContext) {
        super(systemController, benchmarkContext);
    }

    @Override
    public long executeTimedQuery(String query, String... args) throws Exception {
        List<String> commandList = new ArrayList<>();
        commandList.add(systemController.getQueryCommand());
        commandList.add("-q");
        commandList.add(query);
        commandList.add("--user");
        commandList.add(systemController.getUser());
        commandList.add("--passwd");
        commandList.add(systemController.getPassword());
        Collections.addAll(commandList, args);

        StopWatch timer = new StopWatch();
        int status = ProcessExecutor.executeShellCommand(commandList.toArray(new String[]{}));
        long result = timer.getElapsedTime();

        if (status != 0) {
            System.out.println("failed, restarting system..,");
            systemController.restartSystem();
            timer.reset();
            status = ProcessExecutor.executeShellCommand(commandList.toArray(new String[]{}));
            result = timer.getElapsedTime();
            if (status != 0) {
                throw new Exception(String.format("Query execution failed with status %d", status));
            }
        }

        return result;
    }
    
}

@@ -1096,24 +1096,200 @@
 assword());%0A
+        if (systemController.getQueryCommand().contains(%22directql%22)) %7B%0A            commandList.add(%22-d%22);%0A            commandList.add(benchmarkContext.getDataDir());%0A        %7D%0A
         Coll

add support for directql