def emit_code_from_multiple_match_queries(match_queries):
    """Return a MATCH query string from a list of MatchQuery namedtuples."""
    optional_variable_base_name = '$optional__'
    union_variable_name = '$result'
    query_data = deque([u'SELECT EXPAND(', union_variable_name, u')', u' LET '])

    optional_variables = []
    sub_queries = [emit_code_from_single_match_query(match_query)
                   for match_query in match_queries]
    for (i, sub_query) in enumerate(sub_queries):
        variable_name = optional_variable_base_name + str(i)
        variable_assignment = variable_name + u' = ('
        sub_query_end = u'),'
        query_data.append(variable_assignment)
        query_data.append(sub_query)
        query_data.append(sub_query_end)
        optional_variables.append(variable_name)

    query_data.append(union_variable_name)
    query_data.append(u' = UNIONALL(')
    query_data.append(u', '.join(optional_variables))
    query_data.append(u')')

    return u' '.join(query_data)
def emit_code_from_multiple_match_queries ( match_queries ) : optional_variable_base_name = '$optional__' union_variable_name = '$result' query_data = deque ( [ u'SELECT EXPAND(' , union_variable_name , u')' , u' LET ' ] ) optional_variables = [ ] sub_queries = [ emit_code_from_single_match_query ( match_query ) for match_query in match_queries ] for ( i , sub_query ) in enumerate ( sub_queries ) : variable_name = optional_variable_base_name + str ( i ) variable_assignment = variable_name + u' = (' sub_query_end = u'),' query_data . append ( variable_assignment ) query_data . append ( sub_query ) query_data . append ( sub_query_end ) optional_variables . append ( variable_name ) query_data . append ( union_variable_name ) query_data . append ( u' = UNIONALL(' ) query_data . append ( u', ' . join ( optional_variables ) ) query_data . append ( u')' ) return u' ' . join ( query_data )
Return a MATCH query string from a list of MatchQuery namedtuples.