Untitled
unknown
plain_text
2 years ago
2.3 kB
3
Indexable
# ... 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'] # Check if the number of fields in eprm_join_cols_entity and eprm_join_cols_reim are the same entity_fields = len(eprm_join_cols_entity.split(',')) reim_fields = len(eprm_join_cols_reim.split(',')) if entity_fields != reim_fields: # Concatenate the missing fields in their respective columns if entity_fields > reim_fields: diff = entity_fields - reim_fields for i in range(diff): eprm_join_cols_reim += ',' else: diff = reim_fields - entity_fields for i in range(diff): eprm_join_cols_entity += ',NULL' # Replace 'AND' with ',' in eprm_join_cols_reim eprm_join_cols_reim = eprm_join_cols_reim.replace('AND', ',') # Split the string by ',' to get individual column assignments columns_reim = eprm_join_cols_reim.split(',') # Construct the modified assignment string assignment_string = '' for col_reim in columns_reim: # Extract the column name after '=' col_name = col_reim.split('=')[0].strip() # Append the modified assignment to the string assignment_string += f"{col_reim.replace(col_name, eprm_table_alias + '.' + col_name)}, " # Remove the trailing comma and whitespace assignment_string = assignment_string.rstrip(', ') assignment_string = assignment_string.replace("AND", ",") eprm_join_reim = assignment_string # Construct the secondary query column_names = [col.split('=')[1].split('.')[-1].strip() for col in columns_reim] column_names_string = ', '.join(column_names) secondary_query = f"SELECT COUNT(*) FROM tibtcare_ppm_st2.{eprm_table_name} WHERE ({eprm_join_cols_entity}) IN (SELECT {eprm_join_reim} FROM tibtcare_ppm_st2.release_entity_inst_map WHERE release_id='{releaseId}' AND op_id='{opId}' AND bu_id='{buId}')" secondary_query = secondary_query.replace(assignment_string, column_names_string) print(secondary_query) cursor.execute(secondary_query) result = cursor.fetchone() print(f"Count for {eprm_table_name}: {result[0]}") # ...
Editor is loading...