def run_remove_hive(conf: ConfigData, the_date: str, delta_day=0):
    f_date_str = StrTool.get_the_date_str(the_date, delta_day)  # "20181101"
    # "/user/hive/warehouse/rds_posflow.db/t1_trxrecprd_v2/t1_trxrecord_20181204_V2*.csv"

    del_table = conf.get_table_name(
    )  # hive_table="rds_posflow.t1_trxrecprd_v2"

    if the_conf.m_project_id == 1:
        del_file = conf.get_file_name(f_date_str).replace('.', '*.')
        MyHdfsFile.delete_hive_ssh(conf.get_data("cdh_ip"),
                                   table=del_table,
                                   p_name=del_file,
                                   username=conf.get_data("cdh_user"),
                                   password=conf.get_data("cdh_pass"))

    if the_conf.m_project_id == 2:
        conn = connect(host=conf.hive_ip(),
                       port=conf.hive_port(),
                       auth_mechanism=conf.hive_auth(),
                       user=conf.hive_user())
        cur = conn.cursor()

        # "ALTER TABLE rds_posflow.t1_trxrecprd_v2_tmp DROP IF EXISTS PARTITION(p_date=20190208) "
        sql = "ALTER TABLE {} DROP IF EXISTS PARTITION( p_date={} )".format(
            del_table, the_date)
        print(sql)
        cur.execute(sql)

        cur.close()
        conn.close()
def run_remove_hive(conf: ConfigData, the_date: str, delta_day=0):
    f_date_str = StrTool.get_the_date_str(the_date, delta_day)  # "20181101"

    del_table = conf.get_table_name(
    )  # "hive_table" + str(conf.the_id) # "rds_posflow.loginfo_rsp_bl"
    del_file = conf.get_file_name(f_date_str).replace(
        '.', '*.')  # "file_ext" + str(conf.the_id)

    MyHdfsFile.delete_hive_ssh(conf.get_data("cdh_ip"),
                               table=del_table,
                               p_name=del_file,
                               username=conf.get_data("cdh_user"),
                               password=conf.get_data("cdh_pass"))
def run_remove_hive(configData: ConfigData):
    f_date_str = configData.get_f_date()  # "20181101"
    p_date_str = configData.get_p_date()  # "2018-11-01"

    del_table = configData.get_table_name()   # "hive_table" + str(configData.the_id) # "rds_posflow.loginfo_rsp_bl"
    print(configData.cdh_ip()+del_table+f_date_str+configData.get_file_name(f_date_str)+configData.hive_ip())
    if not configData.get_has_partition():
        del_file = configData.get_file_name(f_date_str).replace('.', '*.')  # "file_ext" + str(configData.the_id)
        MyHdfsFile.delete_hive_ssh(configData.cdh_ip(), table=del_table, p_name=del_file, username=configData.cdh_user(), password=configData.cdh_pass())

    else:
        conn = connect(host=configData.hive_ip(), port=configData.hive_port(), auth_mechanism=configData.hive_auth(), user=configData.hive_user())
        cur = conn.cursor()

        # "ALTER TABLE rds_posflow.t1_trxrecprd_v2_tmp DROP IF EXISTS PARTITION(p_date='2019-02-08') "
        sql = "ALTER TABLE {} DROP IF EXISTS PARTITION( p_date='{}' )".format(del_table, p_date_str)
        print(sql)
        cur.execute(sql)

        cur.close()
        conn.close()
Beispiel #4
0
def run_remove_hive(configData: ConfigData):
    f_date_str = configData.get_f_date()  # "20181101"
    p_date_str = configData.get_p_date()  # "2018-11-01"
    # "/user/hive/warehouse/rds_posflow.db/t1_trxrecprd_v2/t1_trxrecord_20181204_V2*.csv"

    del_table = configData.get_table_name()   # hive_table="rds_posflow.t1_trxrecprd_v2"

    if not configData.get_has_partition():
        del_file = configData.get_file_name(f_date_str).replace('.', '*.')
        MyHdfsFile.delete_hive_ssh(configData.cdh_ip(), table=del_table, p_name=del_file, username=configData.cdh_user(), password=configData.cdh_pass())

    else:
        conn = connect(host=configData.hive_ip(), port=configData.hive_port(), auth_mechanism=configData.hive_auth(), user=configData.hive_user())
        cur = conn.cursor()

        # "ALTER TABLE rds_posflow.t1_trxrecprd_v2_tmp DROP IF EXISTS PARTITION(p_date=2019-02-08) "
        sql = "ALTER TABLE {} DROP IF EXISTS PARTITION( p_date='{}' )".format(del_table, p_date_str)
        print(sql)
        cur.execute(sql)

        cur.close()
        conn.close()