package cn.edu.ruc.iir.rainbow.layout.cmd;

import cn.edu.ruc.iir.rainbow.common.cmd.Command;
import cn.edu.ruc.iir.rainbow.common.cmd.Receiver;

import java.util.Properties;

public class CmdGenerateQuery implements Command
{
    private Receiver receiver = null;

    @Override
    public void setReceiver(Receiver receiver)
    {
        this.receiver = receiver;
    }

    /**
     * params should contain the following settings:
     * <ol>
     *   <li>table.type, ordered, dupped, origin</li>
     *   <li>file.format, orc, parquet, text</li>
     *   <li>schema.file</li>
     *   <li>ddl.file</li>
     * </ol>
     *
     * this method will pass the following results to receiver:
     * <ol>
     *   <li>ddl.file</li>
     * </ol>
     * @param params
     */
    @Override
    public void execute(Properties params)
    {
        String algoName = params.getProperty("algorithm.name");
        String schemaFilePath = params.getProperty("schema.file.path");
        String workloadFilePath = params.getProperty("workload.file.path");
        String duppedSchemaFilePath = params.getProperty("dupped.schema.file.path");
        String duppedWorkloadFilePath = params.getProperty("dupped.workload.file.path");

        Properties results = new Properties();
        //try
        //{

        results.setProperty("dupped.schema.file.path", duppedSchemaFilePath);
        results.setProperty("dupped.workload.file.path", duppedWorkloadFilePath);
        //}
        /* catch (IOException e)
        {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "I/O error, check the file paths", e);
        } catch (InterruptedException e)
        {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "interrupted while waiting for algorithm execution", e);
        } catch (ColumnNotFoundException e)
        {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "column not fount when building workload", e);
        } catch (ClassNotFoundException e)
        {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "algorithm class not fount", e);
        } catch (AlgoException e)
        {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "algorithm initialization error", e);
        }*/

        if (this.receiver == null)
        {
            receiver.action(results);
        }
    }
}

@@ -138,16 +138,299 @@
 ceiver;%0A
+import cn.edu.ruc.iir.rainbow.common.exception.ColumnNotFoundException;%0Aimport cn.edu.ruc.iir.rainbow.common.exception.ExceptionHandler;%0Aimport cn.edu.ruc.iir.rainbow.common.exception.ExceptionType;%0Aimport cn.edu.ruc.iir.rainbow.layout.sql.GenerateQuery;%0A%0Aimport java.io.IOException;
 %0Aimport 
@@ -746,87 +746,138 @@
 ble.
-type, ordered, dupped, origin%3C/li%3E%0A     *   %3Cli%3Efile.format, orc, parquet, text
+name%3C/li%3E%0A     *   %3Cli%3Eordered.table.name%3C/li%3E%0A     *   %3Cli%3Ehostname%3C/li%3E%0A     *   %3Cli%3Eschema.file%3C/li%3E%0A     *   %3Cli%3Eworkload.file
 %3C/li
@@ -884,37 +884,42 @@
 %3E%0A     *   %3Cli%3Es
-chema
+park.query
 .file%3C/li%3E%0A     
@@ -918,35 +918,42 @@
 i%3E%0A     *   %3Cli%3E
-ddl
+hive.query
 .file%3C/li%3E%0A     
@@ -1060,11 +1060,53 @@
 %3Cli%3E
-ddl
+spark.query.file%3C/li%3E%0A     *   %3Cli%3Ehive.query
 .fil
@@ -1236,49 +1236,180 @@
 ing 
-algoName = params.getProperty(%22algorithm.
+tableName = params.getProperty(%22table.name%22);%0A        String orderedTableName = params.getProperty(%22ordered.table.name%22);%0A        String hostname = params.getProperty(%22host
 name
@@ -1467,37 +1467,32 @@
 rty(%22schema.file
-.path
 %22);%0A        Stri
@@ -1542,29 +1542,24 @@
 orkload.file
-.path
 %22);%0A        
@@ -1565,28 +1565,26 @@
  String 
-duppedSchema
+sparkQuery
 FilePath
@@ -1606,39 +1606,32 @@
 operty(%22
-dupped.schema.file.path
+spark.query.file
 %22);%0A    
@@ -1641,30 +1641,25 @@
  String 
-duppedWorkload
+hiveQuery
 FilePath
@@ -1685,33 +1685,23 @@
 ty(%22
-dupped.workload.file.path
+hive.query.file
 %22);%0A
@@ -1756,18 +1756,16 @@
         
-//
 try%0A    
@@ -1772,21 +1772,22 @@
     
-//%7B%0A%0A
+%7B%0A    
         
 resu
@@ -1786,67 +1786,128 @@
     
-results.setProperty(%22dupped.
+GenerateQuery.Gen(tableName, orderedTableName, hostname, 
 schema
-.file.p
+FileP
 ath
-%22
 , 
-duppedSchema
+workloadFilePath, sparkQueryFilePath, hiveQuery
 File
@@ -1921,16 +1921,20 @@
         
+    
 results.
@@ -1950,217 +1950,116 @@
 ty(%22
-dupped.workload.file.path%22, duppedWorkloadFilePath);%0A        //%7D%0A        /* catch (IOException e)%0A        %7B%0A            ExceptionHandler.Instance().log(ExceptionType.ERROR, %22I/O error, check the file p
+spark.query.file%22, sparkQueryFilePath);%0A            results.setProperty(%22hive.query.file%22, hiveQueryFileP
 ath
-s%22, e
 );%0A 
@@ -2075,26 +2075,17 @@
 catch (I
-nterrupted
+O
 Exceptio
@@ -2169,57 +2169,39 @@
 R, %22
-interrupted while waiting for algorithm execution
+I/O error, check the file paths
 %22, e
@@ -2349,323 +2349,26 @@
 hen 
-building workload%22, e);%0A        %7D catch (ClassNotFoundException e)%0A        %7B%0A            ExceptionHandler.Instance().log(ExceptionType.ERROR, %22algorithm class not fount%22, e);%0A        %7D catch (AlgoException e)%0A        %7B%0A            ExceptionHandler.Instance().log(ExceptionType.ERROR, %22algorithm initialization error
+generating queries
 %22, e
@@ -2379,18 +2379,16 @@
        %7D
-*/
 %0A%0A      

fix issue #7