Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.4 kB
1
Indexable
Never
elif eprm_table_type == 'MASTER-CHILD':
                qry = f"select * from {schema_tar}.etl_ppm_replication_master WHERE eprm_table_name=" + "'" + eprm_parent_table_name + "'"
                cursor_tar.execute(qry)
                rows = cursor_tar.fetchall()
                columns = [desc[0] for desc in cursor_tar.description]
                df_child = pd.DataFrame(rows, columns=columns)
                filtered_df_child = df_child[
                    df_child['eprm_catalog'].isin(['PC']) & (df_child['eprm_enabled_flg'] == 'Y') & df_child[
                        'eprm_table_type'].isin(
                        ['MASTER'])]
                for _, row in filtered_df_child.iterrows():
                    eprm_table_name_child = row['eprm_table_name']
                    eprm_join_cols_entity_child = row['eprm_join_cols_entity']
                    eprm_join_cols_reim_child = row['eprm_join_cols_reim']
                    eprm_table_type_child = row['eprm_table_type']
                    if eprm_table_type_child == 'MASTER':
                        print(eprm_join_cols_reim)
                        split_conditions_reim = eprm_join_cols_reim.split('AND')
                        where_clause_reim = []
                        for condition in split_conditions_reim:
                            condition = condition.split('=')[1]
                            condition = condition.split('.')[1]
                            where_clause_reim.append(condition.strip())
                        where_clause_reim = ','.join(where_clause_reim)

                        print(where_clause_reim)

                        values_child = eprm_join_cols_entity_child.split('=')
                        column_names_child = [value.split('.')[-1].strip() for value in values_child]
                        where_clause_child = ', '.join(column_names_child)

                        split_conditions = eprm_join_cols_reim_child.split(' AND ')
                        result = [condition.split('=')[0].split('.')[-1] for condition in split_conditions]

                        where_clause = ', '.join(result)

                        final_query = f"SELECT COUNT(*) FROM {schema_tar}.{eprm_table_name} WHERE ({where_clause_reim}) IN (select {where_clause_reim} from {schema_tar}.{eprm_table_name_child} where ({where_clause_child}) IN (select " + where_clause + f" FROM {schema_tar}.RELEASE_ENTITY_INST_MAP WHERE release_id='" + releaseId + "' AND op_id='" + opId + "' AND bu_id='" + buId + "'))"
                        print(final_query)
                        try:
                            cursor_tar.execute(final_query)
                            logging.info(f"processing - {eprm_table_type}")
                            result = cursor_tar.fetchone()
                            query_info = f"-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STATUS|{replicationTarget}| TABLE| {eprm_table_name}\n"
                            query_info += f"-- #Query: Result:{result[0]}\n"
                            query_count += 1
                            query_info += final_query + ";\n"
                            write_sql(query_info)
                            logging.info(f"Count for {eprm_table_name}: {result[0]}")
                            print(
                                f"Count for {eprm_table_name}: {result[0]}" + " ---------------------MASTER-AUDIT------------------")
                        except mysql.connector.Error as err:
                            print(f"Error occurred while executing the query:{final_query}: {err}")
                            logging.info(f"Error occurred while executing the query:{final_query}: {err}")



can you modify above code like i want to execute the below thing in above code directly using pandas

qry = f"select * from {schema_tar}.etl_ppm_replication_master WHERE eprm_table_name=" + "'" + eprm_parent_table_name + "'"
                cursor_tar.execute(qry)
                rows = cursor_tar.fetchall()
                columns = [desc[0] for desc in cursor_tar.description]
                df_child = pd.DataFrame(rows, columns=columns)
                filtered_df_child = df_child[
                    df_child['eprm_catalog'].isin(['PC']) & (df_child['eprm_enabled_flg'] == 'Y') & df_child[
                        'eprm_table_type'].isin(
                        ['MASTER'])]