def build_clause(query, attributes):
    class_ = type(query) if not isinstance(query, type) else query
    fn = CLAUSE_MAP.get(class_)
    if fn is not None:
        return fn(query, attributes)
    elif issubclass(class_, Query):
        return build_clause(query.parsed, attributes)
    else:
        raise ValueError('Unable to translate query node %s' % str(query))

# def build_clause(query, attributes):
#     # Iterate through each query segment.
#     clause = None
#     last = None
#     for seg in query.segments:
#         # Get the attribute in question.
#         attribute = attributes[seg.path[0]]

#         # Replace the initial path segment with the expanded
#         # attribute path.
#         seg.path[0:1] = attribute.path.split('.')

#         # Boolean's should use `exact` rather than `iexact`.
#         if attribute.type is bool:
#             op = '__exact'
#         else:
#             op = OPERATOR_MAP[seg.operator]

#         # Build the path from the segment.
#         path = '__'.join(seg.path) + op

#         # Construct a Q-object from the segment.
#         q = reduce(operator.or_,
#                    map(lambda x: Q((path, x)),
#                        map(attribute.try_clean, seg.values)))

#         # Combine the segment with the last.
#         clause = last.combinator(clause, q) if last is not None else q
#         last = seg

#     # Return the constructed clause.
#     return clause
dataset/ETHPy150Open armet/python-armet/armet/connectors/django/resources.py/build_clause/original