package test.hive;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import util.JdbcUtil;
import util.SqlUtil;

public class ExecTest {
   public static void main(String[] args) {
      conn();
   }

   private static void conn() {
      String content = "{\n      \"ip_port\": \"10.11.120.15:10000\",\n      \"url\": \"jdbc:hive2://10.11.120.15:10000/bym\",\n      \"username\": \"admin\",\n      \"password\": \"admin\",\n      \"dbType\": \"hive\",\n      \"isIgnorecase\":\"1\",\n      \"includeSchema\": [\"bym\",\"rouyi\"]\n    }";
      JdbcUtil.initData(content);
   }

   public Map<String, Object> execSqlPrase(String sql) {
      conn();
      Map<String, String> params = new HashMap();
      params.put("sql", sql);
      params.put("dbType", "hive");
      params.put("schema", "rouyi");
      params.put("url", "jdbc:hive2://10.11.120.15:10000/rouyi");
      System.out.println(sql);
      System.out.println("---------------------/source sql    ------------------------------------------------");
      SqlUtil sqlUtil = new SqlUtil();
      Map<String, Object> res = sqlUtil.parseSqlStructure(params);
      return res;
   }

   public String execSqlPraseAndReplace(String sql, List<Map> replaceList) {
      conn();
      Map<String, String> params = new HashMap();
      params.put("sql", sql);
      params.put("dbType", "hive");
      params.put("schema", "bym");
      params.put("url", "jdbc:hive2://10.11.120.15:10000/bym");
      System.out.println(sql);
      System.out.println("---------------------/source sql    ------------------------------------------------");
      params.put("replaceColumn", "name");
      SqlUtil sqlUtil = new SqlUtil();

      try {
         String res = sqlUtil.pareSqlReplaceValue2(params, replaceList);
         return res;
      } catch (Exception e) {
         throw new RuntimeException(e);
      }
   }
}
