# Path: bamboo/lib/utils.py
# def combine_dicts(*dicts):
#     """Combine dicts with keys in later dicts taking precedence."""
#     return dict(chain(*[_dict.iteritems() for _dict in dicts]))
# 
# def replace_keys(original, mapping):
#     """Recursively replace any keys in original with their values in mappnig.
# 
#     :param original: The dictionary to replace keys in.
#     :param mapping: A dict mapping keys to new keys.
# 
#     :returns: Original with keys replaced via mapping.
#     """
#     return original if not type(original) in (dict, list) else {
#         mapping.get(k, k): {
#             dict: lambda: replace_keys(v, mapping),
#             list: lambda: [replace_keys(vi, mapping) for vi in v]
#         }.get(type(v), lambda: v)() for k, v in original.iteritems()}


from dateutil import parser
from time import mktime
from bamboo.lib.utils import combine_dicts, replace_keys
    def __init__(self, query=None, select=None, distinct=None, limit=0,
                 order_by=None, dataset=None):
        """A holder for query arguments.

        :param query: An optional query.
        :param select: An optional select to limit the fields in the dframe.
        :param distinct: Return distinct entries for this field.
        :param limit: Limit on the number of rows in the returned dframe.
        :param order_by: Sort resulting rows according to a column value and
            sign indicating ascending or descending.

        Example of `order_by`:

          - ``order_by='mycolumn'``
          - ``order_by='-mycolumn'``
        """
        self.query = parse_dates_from_query(query, dataset)
        self.select = select
        self.distinct = distinct
        self.limit = limit
        self.order_by = parse_order_by(order_by)

    def encode(self, encoding, query):
        """Encode query, order_by, and select given an encoding.

        The query will be combined with the existing query.

        :param encoding: A dict to encode the QueryArgs fields with.
        :param query: An additional dict to combine with the existing query.
        """

# Path: bamboo/lib/utils.py
# def combine_dicts(*dicts):
#     """Combine dicts with keys in later dicts taking precedence."""
#     return dict(chain(*[_dict.iteritems() for _dict in dicts]))
# 
# def replace_keys(original, mapping):
#     """Recursively replace any keys in original with their values in mappnig.
# 
#     :param original: The dictionary to replace keys in.
#     :param mapping: A dict mapping keys to new keys.
# 
#     :returns: Original with keys replaced via mapping.
#     """
#     return original if not type(original) in (dict, list) else {
#         mapping.get(k, k): {
#             dict: lambda: replace_keys(v, mapping),
#             list: lambda: [replace_keys(vi, mapping) for vi in v]
#         }.get(type(v), lambda: v)() for k, v in original.iteritems()}


# Path: bamboo/lib/query_args.py
from dateutil import parser
from time import mktime
from bamboo.lib.utils import combine_dicts, replace_keys

    def __init__(self, query=None, select=None, distinct=None, limit=0,
                 order_by=None, dataset=None):
        """A holder for query arguments.

        :param query: An optional query.
        :param select: An optional select to limit the fields in the dframe.
        :param distinct: Return distinct entries for this field.
        :param limit: Limit on the number of rows in the returned dframe.
        :param order_by: Sort resulting rows according to a column value and
            sign indicating ascending or descending.

        Example of `order_by`:

          - ``order_by='mycolumn'``
          - ``order_by='-mycolumn'``
        """
        self.query = parse_dates_from_query(query, dataset)
        self.select = select
        self.distinct = distinct
        self.limit = limit
        self.order_by = parse_order_by(order_by)

    def encode(self, encoding, query):
        """Encode query, order_by, and select given an encoding.

        The query will be combined with the existing query.

        :param encoding: A dict to encode the QueryArgs fields with.
        :param query: An additional dict to combine with the existing query.
        """

        self.query = replace_keys(combine_dicts(self.query, query), encoding)