package test.hive;

import bean.Column;
import java.util.ArrayList;
import java.util.Map;

public class InsertTest {
   public static String insert_1 = "insert into users_1  values(1,'test','sssss')";
   public static String insert_2 = "insert into users_1  PARTITION (datestamp = '2014-09-23') values(1,'test','sssss'),(2,'test','sssss')";
   public static String insert_3 = "insert into users  PARTITION (datestamp = '2014-09-23',dd = 'sss') values(1,'test','sssss'),(2,'test','sssss')";
   public static String insert_select_1 = "insert into table users_1 SELECT * FROM users_1";
   public static String insert_select_2 = "Insert into table users_2 (id,username) select id,username from users;";
   public static String insert_over_1 = "insert into table users_1 select * from users_1;";
   public static String insert_over_2 = "insert overwrite table users_2 values(1,'a','b');";
   public static String insert_over_3 = "insert overwrite table users_2 IF NOT EXISTS values(1,\"a\",\"b\");";
   public static String insert_over_4 = "INSERT INTO table users_2(id,username)  SELECT users.id AS id,username as username FROM users;";
   public static String insert_dir_1 = "INSERT OVERWRITE  DIRECTORY '/conf'  select * from  users;";
   public static String insert_dir_2 = "INSERT OVERWRITE LOCAL  DIRECTORY '/conf'  select * from  users;";
   public static String update_1 = "UPDATE users_2 SET username = \"asd\" where id=1;";
   public static String delete_1 = "DELETE FROM users_1 WHERE id = 1;";
   public static String merge_1 = "MERGE INTO users_1 A  using users_2 B  ON ( A.id = b.id )  WHEN matched THEN UPDATE SET A.username = B.username  INSERT (id, username, password) VALUES (B.id,  B.username,  B.password);";
   public static String trans_1 = "begin transaction";
   public static String load_1 = "LOAD DATA LOCAL INPATH '/config' INTO TABLE users_1";

   public static void main(String[] args) {
      ExecTest p = new ExecTest();
      Map<String, Object> res = p.execSqlPrase(insert_1);
      print(res);
   }

   public static void print(Map<String, Object> res) {
      System.out.println("\n\n====sql====");
      System.out.println(res.get("sql"));
      System.out.println("\n\n====schemaMap====");
      Map<String, Object> schemaMap = (Map)res.get("schemaMap");
      if (schemaMap != null && !schemaMap.isEmpty()) {
         for(Map.Entry<String, Object> item : schemaMap.entrySet()) {
            System.out.println((String)item.getKey() + "\t" + item.getValue());
         }
      }

      System.out.println("\n\n====tableMap====");
      Map<String, Object> tableMap = (Map)res.get("tableMap");
      if (tableMap != null && !tableMap.isEmpty()) {
         for(Map.Entry<String, Object> item : tableMap.entrySet()) {
            System.out.println((String)item.getKey() + "\t" + item.getValue());
         }
      }

      System.out.println("\n\n====columnList====");
      ArrayList<Column> columnList = (ArrayList)res.get("columnList");
      String[] var10000 = new String[]{"columnName", "columnAlisa", "fullName", "nowName", "dataType", "schema", "table", "value", "expr"};

      for(int i = 0; i < columnList.size(); ++i) {
         System.out.println(((Column)columnList.get(i)).getColumnName());
      }

      System.out.println("\n\n====whereList====");
      ArrayList<Map<String, Object>> whereList = (ArrayList)res.get("whereList");
      if (whereList != null && !whereList.isEmpty()) {
         for(Map<String, Object> where : whereList) {
            for(Map.Entry<String, Object> item : where.entrySet()) {
               System.out.println((String)item.getKey() + "\t" + item.getValue());
            }
         }
      }

   }
}
