package test.hive;

import java.util.Map;

public class DCLTest {
   public static String create_role = "CREATE ROLE role_1";
   public static String drop_role = "drop ROLE role_1";
   public static String GRANT_1 = "grant role admin,role ad to user bym,user admin";
   public static String GRANT_1_1 = "grant role sys,role admin to user admin,USER bym";
   public static String GRANT_2 = "grant select,insert on table user_1 to user bym";
   public static String GRANT_3 = "grant select on table user_1 to role bym";
   public static String GRANT_7 = "grant SHOW VIEW on database user_1 to role bym ,USER bym";
   public static String GRANT_8 = "grant SHOW COLUMNS on database user_1 to role bym ,USER bym";
   public static String GRANT_9 = "grant SHOW TABLE STATUS on database user_1 to role bym ,USER bym";
   public static String GRANT_10 = "grant SHOW create TABLE on database user_1 to role bym ,USER bym";
   public static String GRANT_11 = "grant create table as select on database user_1 to role bym ,USER bym";
   public static String GRANT_12 = "grant drop view PROPERTIES on database user_1 to role bym ,USER bym";
   public static String GRANT_13 = "grant ALTER PARTITION LOCATION on database user_1 to role bym ,USER bym";
   public static String GRANT_4 = "  grant select,insert on table user_1 to user bym,user zhangsan";
   public static String GRANT_5 = "  grant select,insert on table user_1 to user bym,role zhangsan";
   public static String REVOKE_1 = "REVOKE select  on table user_1 from user bym";
   public static String REVOKE_2 = "REVOKE select  on database user_1 from user bym,role lisi";
   public static String REVOKE_5 = "REVOKE role admin,role ad from user bym,user admin";
   public static String GRANT_6 = "grant ALL PRIVILEGES on table user_1 to user bym ";
   public static String REVOKE_4 = "REVOKE  ALL PRIVILEGES  on database user_1 from user bym,role lisi";
   public static String SHOW_databse_1 = "SHOW databases ";
   public static String SHOW_databse_2 = "SHOW databases like 'a%'";
   public static String SHOW_table_1 = "SHOW tables like 'a%'";
   public static String SHOW_table_2 = "SHOW tables in myhives like 'a%'";
   public static String SHOW_view_1 = "Show Views like 'a%'";
   public static String SHOW_view_2 = "Show Views from database_1 like 'a%'";
   public static String SHOW_view_3 = "Show Views like 'a|aaa'";
   public static String SHOW_view_4 = "Show Views '*_test'";
   public static String SHOW_MATERIALIZED_1 = "Show Materialized Views";
   public static String SHOW_MATERIALIZED_2 = "Show Materialized Views like 'a%'";
   public static String SHOW_Partitions = "SHOW PARTITIONS default.test PARTITION(ds='2010-03-03')  ";
   public static String SHOW_Partitions_2 = "SHOW TABLE EXTENDED IN default like 'test' PARTITION(ds='2010-03-03')";
   public static String SHOW_1 = "SHOW TBLPROPERTIES tblname('foo')";
   public static String SHOW_index_1 = "Show FORMATTED indexes on test in default";
   public static String SHOW_index_2 = "Show   indexes on test in default";
   public static String SHOW_columns_1 = "SHOW COLUMNS FROM foo LIKE 'col1|cola' ;  ";
   public static String SHOW_columns_2 = "SHOW COLUMNS FROM foo FROM test_db LIKE 'col*'; ";
   public static String SHOW_columns_3 = "SHOW COLUMNS in foo in test_db LIKE 'col*'; ";
   public static String SHOW_columns_4 = "SHOW COLUMNS in foo from test_db LIKE 'col*'; ";
   public static String SHOW_FUNCTIONS = "SHOW FUNCTIONS LIKE 'col*'; ";
   public static String SHOW_Conf = "SHOW CONF 'conf_1'; ";
   public static String SHOW_Create = "SHOW create table tblname";
   public static String SHOW_6 = "Show create table user_1";
   public static String SHOW_Transactions = "Show Transactions";
   public static String SHOW_PRINCIPALS = "Show PRINCIPALS users";
   public static String SHOW_CURRENT_ROLES = "show current ROLES;";
   public static String SHOW_ROLES = "show  ROLES;";
   public static String SHOW_ROLE_grant = "SHOW ROLE GRANT ROLE admin;";
   public static String SHOW_GRANT_1 = "show grant user admin on table test;";
   public static String SHOW_GRANT_2 = "show grant user admin on all;";
   public static String SHOW_COMPACTIONS = "SHOW compactions DATABASE db1";
   public static String alter_1 = "alter database myhive set DBPROPERTIES (\"ss\"=\"ss\"); ";
   public static String alter_2 = "alter database myhive set COMMENT 'sss';";
   public static String desc_1 = "DESCRIBE EXTENDED rouyi.gen_table;";
   public static String desc_2 = "DESCRIBE FORMATTED rouyi.gen_table table_id;";
   public static String desc_3 = "Abort Transactions;";
   public static String desc_4 = "DESCRIBE FORMATTED default.src_table PARTITION (part_col = 100) columnA;";
   public static String desc_5 = " DESCRIBE FORMATTED rouyi.gen_table lintString.$elem$.myint;";
   public static String alter_table_1 = "ALTER TABLE log_messages RENAME TO logmsgs;";
   public static String alter_table_2 = "ALTER TABLE logmsgs ADD IF NOT EXISTS PARTITION (year=2019, month=5, day=1) LOCATION '/data/logmsgs/year=2019/month=5/day=1'";

   public static void main(String[] args) {
      ExecTest p = new ExecTest();
      Map<String, Object> res = p.execSqlPrase(alter_table_2);
      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====type====");
      System.out.println(res.get("type"));
      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());
         }
      }

   }
}
