Arithmetic Expressions #25
-
I think the spec should support simple arithmetic operations in the way of the A few things to keep in mind:
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 34 replies
-
If we support arithmetic operators, do we need to support JSON numbers ?
Do we want to be able to write:
Without back ticks? |
Beta Was this translation helpful? Give feedback.
-
If we are adding these operators to the grammar we may as well define them for non-numbers as well: Arrays: Objects (think of the key as if it were the subscript of the vector, or the object as a set of tuples): A modulo operator or function should also be included for numbers. |
Beta Was this translation helpful? Give feedback.
-
FWIW you may consider taking these from us at Kyverno as we've implemented all the basic ones: https://kyverno.io/docs/writing-policies/jmespath/#custom-filters |
Beta Was this translation helpful? Give feedback.
-
Arithmetic Expressions
AbstractThis JEP proposes a new MotivationJMESPath supports querying JSON documents that may return numbers at various stages, but lacks the capability to operate on them using simple arithmetic operations. The only support for arithmetic is currently brought by the SpecificationTo support arithmetic operations, we need to introduce the following operators:
Proper mathematical operators also exist in Unicode and SHOULD be supported:
Syntax changesIn addition to the following grammar changes, we introduce the usual operator precedence, from lowest to highest:
In the absence of parentheses, operators of the same level of precedence are evaluated from left to right. Arithmetic operators have higher precedence than comparison operators and lower precedence than the expression =/ arithmetic-expression
arithmetic-expression =/ "+" expression ; + %x43
arithmetic-expression =/ ( "-" / "–" ) expression ; - %x45 – %x2212
arithmetic-expression = expression "%" expression ; % %x37
arithmetic-expression =/ expression ( "*" / "×" ) expression ; * %x42 × %xD7
arithmetic-expression =/ expression "+" expression ; + %x43
arithmetic-expression =/ expression ( "-" / "–" ) expression ; - %x45 – %x2212
arithmetic-expression =/ expression ( "/" / "÷" ) expression ; / %x47 ÷ %xF7
arithmetic-expression = expression "//" expression ; // %47 %47
Examples
Since
Compliance TestsAn
This error type would be raised at run time when dividing by zero or when overflow occurs, for instance. History
|
Beta Was this translation helpful? Give feedback.
-
It is at least available in python:
https://python-reference.readthedocs.io/en/latest/docs/operators/floor_division.html
…On Fri, Jul 29, 2022, 1:07 AM Maxime Labelle ***@***.***> wrote:
Why not 🤔. I was not aware of this symbol. Is this standardized and
widely recognized ?
—
Reply to this email directly, view it on GitHub
<#25 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANP25ABCUOLKCDUHWQ2VHTVWOGLXANCNFSM5P3RDYFQ>
.
You are receiving this because you commented.Message ID:
<jmespath-community/jmespath.spec/repo-discussions/25/comments/3278286@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
Hi!
I'm not sure I understand this... Given the input |
Beta Was this translation helpful? Give feedback.
-
I am concern that this seem to not work with PEMDAS. |
Beta Was this translation helpful? Give feedback.
Arithmetic Expressions
Abstract
This JEP proposes a new
arithmetic-expression
rule in the grammar to support simple arithmetic operations.Motivation
JMESPath supports querying JSON documents that may return numbers at various stages, but lacks the capability to operate on them using simple arithmetic operations. The only support for arithmetic is currently brought by the
sum()
function.Specification
To support arithmetic operations, we need to introduce the following operators:
+
addition operator-
subtraction operator*
multiplication operator/
division operator%
…