From 67d58bc17fcbba532764091dec0a68a4c9dbb180 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Mon, 20 Feb 2017 19:13:02 -0500 Subject: [PATCH] Added engine options to disable input/output data conversion 'yaql.convertInputData' and 'yaql.convertOutputData' engine options were added. By setting them to false one can suppress input or output data conversion. For the input data this will prevent yaql from converting mutable data structures (lists, dicts, sets) to their immutable versions, which will break some of the constructs that require hashable structures (for example set of lists, or list as a dictionary key), for the output it will not expand produced iterators and not convert tuples to lists. However this can greatly improve performance in some cases Change-Id: I240ce6646fe7dbc9522624739600b6c364bb9618 --- yaql/__init__.py | 4 +++- yaql/language/expressions.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/yaql/__init__.py b/yaql/__init__.py index b0e90c7..5284ebf 100644 --- a/yaql/__init__.py +++ b/yaql/__init__.py @@ -67,7 +67,9 @@ def _setup_context(data, context, finalizer, convention): @specs.inject('engine', yaqltypes.Engine()) @specs.name('#finalize') def finalize(obj, limiter, engine): - return utils.convert_output_data(obj, limiter, engine) + if engine.options.get('yaql.convertOutputData', True): + return utils.convert_output_data(obj, limiter, engine) + return obj context.register_function(limit) context.register_function(finalize) diff --git a/yaql/language/expressions.py b/yaql/language/expressions.py index 90a7063..64f3c46 100644 --- a/yaql/language/expressions.py +++ b/yaql/language/expressions.py @@ -161,7 +161,10 @@ class Statement(Function): if context is None or context is utils.NO_VALUE: context = yaql.create_context() if data is not utils.NO_VALUE: - context['$'] = utils.convert_input_data(data) + if self.engine.options.get('yaql.convertInputData', True): + context['$'] = utils.convert_input_data(data) + else: + context['$'] = data return self(utils.NO_VALUE, context, self.engine) def __str__(self):