Add "convert_input_data" config property for YAQL expressions
Closes-Bug: #1822060 Change-Id: I521ad62c3311a2e4de714af4c31463bdff7dbd59
This commit is contained in:
parent
97f4fc2776
commit
5e0133c83e
@ -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,
|
||||
|
@ -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')
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user