Beispiel #1
0
 def __create_selectivity_matrix_for_nested_operators(
         pattern: Pattern, statistics: Dict):
     """
     This function creates a selectivity matrix that fits the root operator (kind of flattening the selectivity
     of the nested operators, if exists).
     """
     selectivity_matrix = statistics[StatisticsTypes.SELECTIVITY_MATRIX]
     if pattern.count_primitive_events(
             positive_only=True) != len(selectivity_matrix):
         raise Exception("size mismatch")
     nested_selectivity_matrix = []
     primitive_sons_list = []
     # event_names are all the events in this pattern (including those under nested operators)
     event_names = [
         name for name in pattern.positive_structure.get_all_event_names()
     ]
     for arg in pattern.get_top_level_structure_args(positive_only=True):
         # This is a list with size of the number of args, where each entry in the list is the events' name of the
         # primitive events under this arg.
         primitive_sons_list.append(
             [name for name in arg.get_all_event_names()])
     for i, row_entry in enumerate(primitive_sons_list):
         nested_selectivity_matrix.append([])
         for col_entry in primitive_sons_list:
             # Building the new matrix, which is (#args x #args), where each entry is calculated based on the events
             # under the specific args respectively
             nested_selectivity = TreePlanBuilder.__calculate_nested_selectivity(
                 event_names, selectivity_matrix, row_entry, col_entry)
             nested_selectivity_matrix[i].append(nested_selectivity)
     return nested_selectivity_matrix
Beispiel #2
0
 def __chop_matrix(pattern: Pattern, arg: PatternStructure,
                   selectivity_matrix: List[List[float]]):
     """
     Chop the matrix and returns only the rows and columns that are relevant to this arg (assuming this arg is in
     pattern's operators), based on the nested events' name in this arg.
     """
     if pattern.count_primitive_events(
             positive_only=True) != len(selectivity_matrix):
         raise Exception("size mismatch")
     event_names = [
         name for name in pattern.positive_structure.get_all_event_names()
     ]
     primitive_sons = [name for name in arg.get_all_event_names()]
     chop_start = event_names.index(primitive_sons[0])
     chop_end = event_names.index(primitive_sons[-1])
     return TreePlanBuilder.__chop_matrix_aux(selectivity_matrix,
                                              chop_start, chop_end)