Merge "Add "convert_input_data" config property for YAQL expressions"

This commit is contained in:
Zuul 2019-04-04 18:36:53 +00:00 committed by Gerrit Code Review
commit 8b2fe42beb
3 changed files with 34 additions and 1 deletions

View File

@ -560,6 +560,23 @@ yaql_opts = [
help=_('The memory usage quota (in bytes) for all data produced by '
'the expression (or any part of it). -1 means no limitation.')
),
cfg.BoolOpt(
'convert_input_data',
default=True,
help=_('Enables input data conversion for YAQL expressions. If set '
'to True then YAQL will convert mutable data structures '
'(lists, dicts, sets) into their immutable versions. That '
'will allow them to work with some constructs that require '
'hashable types even if elements are not hashable. For '
'example, it will be possible to put dicts into a set. '
'Although it conflicts with the base principles of such '
'collections (e.g. we cannot put a non-hashable type into '
'a set just because otherwise it will not work correctly) the '
'YAQL library itself allows this. '
'Disabling input data conversion may give significant '
'performance boost if the input data for an expression is '
'large.')
),
cfg.BoolOpt(
'convert_tuples_to_lists',
default=True,

View File

@ -25,6 +25,7 @@ import yaql
from yaql.language import utils as yaql_utils
from mistral.config import cfg
from mistral.db.v2 import api as db_api
from mistral import utils
@ -48,7 +49,11 @@ def get_yaql_context(data_context):
_register_yaql_functions(ROOT_YAQL_CONTEXT)
new_ctx = ROOT_YAQL_CONTEXT.create_child_context()
new_ctx['$'] = yaql_utils.convert_input_data(data_context)
new_ctx['$'] = (
data_context if not cfg.CONF.yaql.convert_input_data
else yaql_utils.convert_input_data(data_context)
)
if isinstance(data_context, dict):
new_ctx['__env'] = data_context.get('__env')

View File

@ -0,0 +1,11 @@
---
fixes:
- |
Added the "convert_input_data" config property under the "yaql" group.
By default it's set to True which preserves the current behavior so
there's no risk with compatibility. If set to False, it disables the
additional data conversion that was initially added to support some
tricky cases like working with sets of dicts (although dict is not a
hashable type and can't be put into a set). Disabling it give a
significant performance boost in cases when data contexts are very
large.