diff --git a/yaql/language/utils.py b/yaql/language/utils.py index e738659..6732394 100644 --- a/yaql/language/utils.py +++ b/yaql/language/utils.py @@ -181,20 +181,19 @@ def get_memory_quota(engine): def limit_iterable(iterable, limit_or_engine): if isinstance(limit_or_engine, int): - count = limit_or_engine + max_count = limit_or_engine else: - count = get_max_collection_size(limit_or_engine) + max_count = get_max_collection_size(limit_or_engine) - if count >= 0 and isinstance(iterable, - (SequenceType, MappingType, SetType)): - if len(iterable) > count: - raise exceptions.CollectionTooLargeException(count) + if isinstance(iterable, (SequenceType, MappingType, SetType)): + if 0 <= max_count < len(iterable): + raise exceptions.CollectionTooLargeException(max_count) return iterable def limiting_iterator(): for i, t in enumerate(iterable): - if 0 <= count <= i: - raise exceptions.CollectionTooLargeException(count) + if 0 <= max_count <= i: + raise exceptions.CollectionTooLargeException(max_count) yield t return limiting_iterator() diff --git a/yaql/standard_library/queries.py b/yaql/standard_library/queries.py index 1c16f80..c140a4a 100644 --- a/yaql/standard_library/queries.py +++ b/yaql/standard_library/queries.py @@ -371,7 +371,8 @@ def zip_longest(*collections, **kwargs): @specs.parameter('collection2', yaqltypes.Iterable()) @specs.parameter('predicate', yaqltypes.Lambda()) @specs.parameter('selector', yaqltypes.Lambda()) -def join(collection1, collection2, predicate, selector): +def join(engine, collection1, collection2, predicate, selector): + collection2 = utils.memorize(collection2, engine) for self_item in collection1: for other_item in collection2: if predicate(self_item, other_item):