Return an Expression that is True if and only if each simple optional filter is True.

    Construct filters for each simple optional, that are True if and only if `edge_field` does
    not exist in the `simple_optional_root_location` OR the `inner_location` is not defined.
    Return an Expression that evaluates to True if and only if *all* of the aforementioned filters
    evaluate to True (conjunction).

    Args:
        query_metadata_table: QueryMetadataTable object containing all metadata collected during
                              query processing, including location metadata (e.g. which locations
                              are folded or optional).
        simple_optional_root_info: dict mapping from simple_optional_root_location -> dict
                                   containing keys
                                   - 'inner_location_name': Location object correspoding to the
                                                            unique MarkLocation present within a
                                                            simple @optional (one that does not
                                                            expands vertex fields) scope
                                   - 'edge_field': string representing the optional edge being
                                                   traversed
                                   where simple_optional_root_to_inner_location is the location
                                   preceding the @optional scope
    Returns:
        a new Expression object

def construct_where_filter_predicate(query_metadata_table, simple_optional_root_info):
    """Return an Expression that is True if and only if each simple optional filter is True.

    Construct filters for each simple optional, that are True if and only if `edge_field` does
    not exist in the `simple_optional_root_location` OR the `inner_location` is not defined.
    Return an Expression that evaluates to True if and only if *all* of the aforementioned filters
    evaluate to True (conjunction).

    Args:
        query_metadata_table: QueryMetadataTable object containing all metadata collected during
                              query processing, including location metadata (e.g. which locations
                              are folded or optional).
        simple_optional_root_info: dict mapping from simple_optional_root_location -> dict
                                   containing keys
                                   - 'inner_location_name': Location object correspoding to the
                                                            unique MarkLocation present within a
                                                            simple @optional (one that does not
                                                            expands vertex fields) scope
                                   - 'edge_field': string representing the optional edge being
                                                   traversed
                                   where simple_optional_root_to_inner_location is the location
                                   preceding the @optional scope
    Returns:
        a new Expression object
    """
    inner_location_name_to_where_filter = {}
    for root_location, root_info_dict in six.iteritems(simple_optional_root_info):
        inner_location_name = root_info_dict['inner_location_name']
        edge_field = root_info_dict['edge_field']

        optional_edge_location = root_location.navigate_to_field(edge_field)
        optional_edge_where_filter = _filter_orientdb_simple_optional_edge(
            query_metadata_table, optional_edge_location, inner_location_name)
        inner_location_name_to_where_filter[inner_location_name] = optional_edge_where_filter

    # Sort expressions by inner_location_name to obtain deterministic order
    where_filter_expressions = [
        inner_location_name_to_where_filter[key]
        for key in sorted(inner_location_name_to_where_filter.keys())
    ]

    return expression_list_to_conjunction(where_filter_expressions)