Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
import pandas as pd
import mysql.connector

cnx = mysql.connector.connect(user='tibtcare_ppm_st2', password='tibtcare_ppm_st2',
                              host='10.16.16.128',port='3308')
cursor = cnx.cursor()

primary_query = "SELECT * FROM tibtcare_ppm_st2.etl_ppm_replication_master"
cursor.execute(primary_query)

rows = cursor.fetchall()
columns = [desc[0] for desc in cursor.description]
df = pd.DataFrame(rows, columns=columns)

filtered_df = df[df['eprm_catalog'].isin(['PC']) & (df['eprm_enabled_flg'] == 'Y')]

for _, row in filtered_df.iterrows():
    eprm_table_name = row['eprm_table_name']
    eprm_join_cols_entity = row['eprm_join_cols_entity']
    eprm_join_cols_reim = row['eprm_join_cols_reim']
    eprm_table_alias=row['eprm_table_alias']

    eprm_join_cols_entity = eprm_join_cols_entity.replace(" ", "")
    tmp2 = ["=" + eprm_table_alias + "." + v for v in eprm_join_cols_entity.split(",")]
    tst1 = eprm_join_cols_reim.replace(" AND", "").replace(" ", "").replace(" =", "=").replace("= ", "=")
    str1 = tst1
    for v in tmp2:
        str1 = str1.replace(v, "").replace("reim.", "")
    str1 = str1.replace(" ", ",")
    print(str1)
    secondary_query = f"SELECT COUNT(*) FROM tibtcare_ppm_st2.{eprm_table_name} WHERE ({str1}) IN (SELECT {tmp2} FROM tibtcare_ppm_st2.release_entity_inst_map)"
    print(secondary_query)
    cursor.execute(secondary_query)
    result = cursor.fetchone()
    print(f"Count for {eprm_table_name}: {result[0]}")

cursor.close()
cnx.close()