package test.hive;

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

public class SelectTest {
   public static String ry4 = "select sessionId, login_name, dept_name, ipaddr, login_location, browser, os, status, start_timestamp, last_access_time, expire_time from sys_user_online o WHERE o.last_access_time <= '2023-08-31 09:16:55' ORDER BY o.last_access_time ASC";
   public static String ry3 = "SELECT *  FROM  sys_user u LEFT JOIN sys_dept d ON u.dept_id = d.dept_id WHERE u.del_flag = '0' AND u.email ='2362395777@qq.com'";
   public static String ry2 = "SELECT * FROM  sys_user u LEFT JOIN sys_dept d ON u.dept_id = d.dept_id WHERE u.del_flag = '0' AND u.phonenumber = '15710503534'";
   public static String ry = "select u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_time, u.remark, d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status from sys_user u left join sys_dept d on u.dept_id = d.dept_id left join sys_user_role ur on u.user_id = ur.user_id left join sys_role r on r.role_id = ur.role_id where u.user_id = 1693310056433";
   public static String rouyi_1 = "select u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_time, u.remark, d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status from sys_user u left join sys_dept d on u.dept_id = d.dept_id left join sys_user_role ur on u.user_id = ur.user_id left join sys_role r on r.role_id = ur.role_id where u.user_id = 1693202279732";
   public static String with_1 = "WITH t1 AS (SELECT *FROM users_4 where id=1), t2 AS (SELECT * FROM users_2)SELECT * FROM t1, t2";
   public static String select_1 = "select * from users_1 where id = 1";
   public static String insert_2 = "insert into users  PARTITION (datestamp = '2014-09-23') values(1,'test','sssss'),(2,'test','sssss')";
   public static String select_union_1 = "select *from users_1 union select *from users_2;";
   public static String select_union_2 = "select *from users union distinct select *from users_2;";
   public static String select_union_3 = "select *from users union all select *from users_2;";
   public static String select_INTERSECT_1 = " select *from users INTERSECT select *from users_2;";
   public static String select_EXCEPT_1 = " select *from users_1 EXCEPT  select *from users_2;";
   public static String select_clause_1 = "select *from users where id = 1;";
   public static String select_clause_2 = "select *from users where id > 1 and id < 10;";
   public static String select_clause_3 = "select *from users where id > 1 and id < 10 LIMIT 10;";
   public static String select_clause_4 = "select *from users where id > 1 and id < 10 LIMIT 10 ORDER BY id desc;";
   public static String select_clause_5 = "select COUNT(*) from users where id > 1 and id < 10 LIMIT 10 ORDER BY id desc;";
   public static String select_clause_6 = "select * from users   GROUP BY id;";
   public static String select_clause_7 = "SELECT `(ds|hr)?+.+` FROM users;";
   public static String select_clause_8 = "select * from users_1 sort BY id desc";
   public static String select_clause_9 = "select * from users_1 Cluster BY id ";
   public static String select_clause_10 = "select * from users_1 Cluster BY id ";
   public static String select_clause_11 = "SELECT users_1.id from users_1  group by users_1.id HAVING users_1.id >=1;";
   public static String select_TABLESAMPLE_1 = "SELECT * FROM users_1 TABLESAMPLE(10 ROWS);";
   public static String select_TABLESAMPLE_2 = "SELECT * FROM users_1 TABLESAMPLE(100M) ;";
   public static String select_TABLESAMPLE_3 = "SELECT * FROM users_1 TABLESAMPLE(BUCKET 3 OUT OF 64 ON id);";
   public static String select_func_1 = "SELECT IF(true,'id','username') AS result FROM users_1 LIMIT 1;";
   public static String select_xpath_1 = "select xpath('<a><b>b1</b><b>b2</b></a>','a/*') from users_1 limit 1;;";
   public static String select_join_1 = "select * FROM users_1 left join users_2 on (users_1.id = users_2.id)  where users_1.id > 0;";
   public static String select_join_2 = "select * FROM users_1 as u1 join users_2 as u2 on (u_1.id = u_2.id)  where u1.id > 0;";
   public static String select_sub_1 = "SELECT id FROM users_1 WHERE id NOT IN (SELECT id FROM users_2);";
   public static String select_sub_2 = "SELECT id FROM users_1 WHERE 1 > (SELECT id FROM users_1);";
   public static String select_sub_3 = "SELECT id FROM users_1 WHERE EXISTS (SELECT id  FROM users_2);";
   public static String select_opt_1 = "SELECT (SELECT id + 5 FROM users_1) FROM users_2;;";
   public static String select_Virtual_1 = "select id,username,INPUT__FILE__NAME from users_1;";

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

      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)).getTable());
         System.out.println(((Column)columnList.get(i)).getColumnAlisa());
         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());
            }
         }
      }

   }
}
