# Path: py_stringsimjoin/utils/generic_helper.py
# def find_output_attribute_indices(original_columns, output_attributes):
#     output_attribute_indices = []
#     if output_attributes is not None:
#         for attr in output_attributes:
#             output_attribute_indices.append(original_columns.index(attr))
#     return output_attribute_indices
# 
# def get_output_header_from_tables(l_key_attr, r_key_attr,
#                                   l_out_attrs, r_out_attrs,
#                                   l_out_prefix, r_out_prefix):
#     output_header = []
# 
#     output_header.append(l_out_prefix + l_key_attr)
# 
#     output_header.append(r_out_prefix + r_key_attr)
# 
#     if l_out_attrs:
#         for l_attr in l_out_attrs:
#             output_header.append(l_out_prefix + l_attr)
# 
#     if r_out_attrs:
#         for r_attr in r_out_attrs:
#             output_header.append(r_out_prefix + r_attr)
# 
#     return output_header
# 
# def get_output_row_from_tables(l_row, r_row,
#                                l_key_attr_index, r_key_attr_index, 
#                                l_out_attrs_indices=None,
#                                r_out_attrs_indices=None):
#     output_row = []
#     
#     # add ltable id attr
#     output_row.append(l_row[l_key_attr_index])
# 
#     # add rtable id attr
#     output_row.append(r_row[r_key_attr_index])
# 
#     # add ltable output attributes
#     if l_out_attrs_indices:
#         for l_attr_index in l_out_attrs_indices:
#             output_row.append(l_row[l_attr_index])
# 
#     # add rtable output attributes
#     if r_out_attrs_indices:
#         for r_attr_index in r_out_attrs_indices:
#             output_row.append(r_row[r_attr_index])
# 
#     return output_row


import numpy as np
import pandas as pd
import pyprind
import os
from py_stringsimjoin.utils.generic_helper import \
    find_output_attribute_indices, get_output_header_from_tables, \
    get_output_row_from_tables



def get_pairs_with_missing_value_disk(ltable, rtable,
                                      l_key_attr, r_key_attr,
                                      l_join_attr, r_join_attr,
                                      temp_dir, data_limit_per_core,
                                      missing_pairs_file_name, l_out_attrs=None,
                                      r_out_attrs=None, l_out_prefix='l_',
                                      r_out_prefix='r_', out_sim_score=False,
                                      show_progress=True):

    # find column indices of key attr, join attr and output attrs in ltable
    l_columns = list(ltable.columns.values)
    l_key_attr_index = l_columns.index(l_key_attr)
    l_join_attr_index = l_columns.index(l_join_attr)
    l_out_attrs_indices = find_output_attribute_indices(l_columns, l_out_attrs)

    # find column indices of key attr, join attr and output attrs in rtable
    r_columns = list(rtable.columns.values)
    r_key_attr_index = r_columns.index(r_key_attr)
    r_join_attr_index = r_columns.index(r_join_attr)

# Path: py_stringsimjoin/utils/generic_helper.py
# def find_output_attribute_indices(original_columns, output_attributes):
#     output_attribute_indices = []
#     if output_attributes is not None:
#         for attr in output_attributes:
#             output_attribute_indices.append(original_columns.index(attr))
#     return output_attribute_indices
# 
# def get_output_header_from_tables(l_key_attr, r_key_attr,
#                                   l_out_attrs, r_out_attrs,
#                                   l_out_prefix, r_out_prefix):
#     output_header = []
# 
#     output_header.append(l_out_prefix + l_key_attr)
# 
#     output_header.append(r_out_prefix + r_key_attr)
# 
#     if l_out_attrs:
#         for l_attr in l_out_attrs:
#             output_header.append(l_out_prefix + l_attr)
# 
#     if r_out_attrs:
#         for r_attr in r_out_attrs:
#             output_header.append(r_out_prefix + r_attr)
# 
#     return output_header
# 
# def get_output_row_from_tables(l_row, r_row,
#                                l_key_attr_index, r_key_attr_index, 
#                                l_out_attrs_indices=None,
#                                r_out_attrs_indices=None):
#     output_row = []
#     
#     # add ltable id attr
#     output_row.append(l_row[l_key_attr_index])
# 
#     # add rtable id attr
#     output_row.append(r_row[r_key_attr_index])
# 
#     # add ltable output attributes
#     if l_out_attrs_indices:
#         for l_attr_index in l_out_attrs_indices:
#             output_row.append(l_row[l_attr_index])
# 
#     # add rtable output attributes
#     if r_out_attrs_indices:
#         for r_attr_index in r_out_attrs_indices:
#             output_row.append(r_row[r_attr_index])
# 
#     return output_row


# Path: py_stringsimjoin/utils/missing_value_handler_disk.py
import numpy as np
import pandas as pd
import pyprind
import os
from py_stringsimjoin.utils.generic_helper import \
    find_output_attribute_indices, get_output_header_from_tables, \
    get_output_row_from_tables




def get_pairs_with_missing_value_disk(ltable, rtable,
                                      l_key_attr, r_key_attr,
                                      l_join_attr, r_join_attr,
                                      temp_dir, data_limit_per_core,
                                      missing_pairs_file_name, l_out_attrs=None,
                                      r_out_attrs=None, l_out_prefix='l_',
                                      r_out_prefix='r_', out_sim_score=False,
                                      show_progress=True):

    # find column indices of key attr, join attr and output attrs in ltable
    l_columns = list(ltable.columns.values)
    l_key_attr_index = l_columns.index(l_key_attr)
    l_join_attr_index = l_columns.index(l_join_attr)
    l_out_attrs_indices = find_output_attribute_indices(l_columns, l_out_attrs)

    # find column indices of key attr, join attr and output attrs in rtable
    r_columns = list(rtable.columns.values)
    r_key_attr_index = r_columns.index(r_key_attr)
    r_join_attr_index = r_columns.index(r_join_attr)

    r_out_attrs_indices = find_output_attribute_indices(r_columns, r_out_attrs)