You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apisix.apache.org by Zexuan Luo <sp...@apache.org> on 2020/11/25 06:58:10 UTC
[DISCUSS] Add a small DSL to support complex conditions
Currently we support a DSL to match routes with variables:
```
[
["arg_name","==","json"],
["arg_weight",">",10],
["arg_weight","!",">",15]
]
```
is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
and not ngx.var.arg_weight > 15`.
It would be better if the DSL can support `or` relation and nested
expressions.
What about a syntax like:
```
{
"or": [ <- the `or` can be other logical operators, like `and`,
`!or`, `!and`
["arg_name","==","json"],
["arg_weight",">",10],
["arg_weight","!",">",15]
]
}
```
(means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
ngx.var.arg_weight > 15` )
and
```
{
"!and": {
"and": [
["arg_name","==","yaml"]
],
"or": [
["arg_name","==","json"],
["arg_weight",">",10],
["arg_weight","!",">",15]
]
}
}
```
(means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json" or
ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by YuanSheng Wang <me...@apache.org>.
On Thu, Nov 26, 2020 at 4:17 PM Zexuan Luo <sp...@apache.org> wrote:
> What about `not or` and `not and`? We can allow space in the operator.
>
this style is better than before. seems good for me. ^_^
>
> YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:59写道:
>
> > On Thu, Nov 26, 2020 at 2:34 PM Zexuan Luo <sp...@apache.org>
> wrote:
> >
> > > I mean using `!or` to represent `not (xxx or xxx)`, and so do `!and`.
> > >
> >
> > I think it is not easy for developers understand this.
> >
> >
> >
> > >
> > > YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:15写道:
> > >
> > > > one question, do we support the operator `!or`, `!and` ?
> > > >
> > > > it is not easy to understand for me :(
> > > >
> > > > On Thu, Nov 26, 2020 at 12:28 PM Zexuan Luo <sp...@apache.org>
> > > > wrote:
> > > >
> > > > > Personally speaking, I think the SO way is more readable. Because
> the
> > > > > logical operator is the same level with the conditions, therefore
> we
> > > can
> > > > > know the conditions and the operator are in the same expression.
> > > > >
> > > > > Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
> > > > >
> > > > > > The expression in Stack Overflow is good, but the readability is
> > not
> > > > > > satifactory,
> > > > > > what about modifying it to make it more hierarchical? For
> example,
> > > > > > promoting the level of
> > > > > > logical operators.
> > > > > >
> > > > > > Chao Zhang
> > > > > > https://github.com/tokers
> > > > > >
> > > > > > On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (
> > > > membphis@apache.org)
> > > > > > wrote:
> > > > > >
> > > > > > I got this idea from Stack Overfollow[1]
> > > > > >
> > > > > > [1]
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
> > > > > >
> > > > > >
> > > > > > On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <
> > membphis@apache.org>
> > > > > > wrote:
> > > > > >
> > > > > > > I think we can mainly use `array`, I write a new style.
> > > > > > >
> > > > > > > this style can be compatible with the old rules.
> > > > > > >
> > > > > > > [
> > > > > > > "AND", -- optional
> > > > > > > ["arg_name","==","yaml"],
> > > > > > > [
> > > > > > > "OR",
> > > > > > > ["arg_name","==","json"],
> > > > > > > ["arg_weight",">",10]
> > > > > > > ]
> > > > > > > ]
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <
> > spacewander@apache.org
> > > >
> > > > > > wrote:
> > > > > > >
> > > > > > >> Currently we support a DSL to match routes with variables:
> > > > > > >>
> > > > > > >> ```
> > > > > > >> [
> > > > > > >> ["arg_name","==","json"],
> > > > > > >> ["arg_weight",">",10],
> > > > > > >> ["arg_weight","!",">",15]
> > > > > > >> ]
> > > > > > >> ```
> > > > > > >>
> > > > > > >> is evaluated to `ngx.var.arg_name == "json" and
> > > ngx.var.arg_weight >
> > > > > 10
> > > > > > >> and not ngx.var.arg_weight > 15`.
> > > > > > >>
> > > > > > >> It would be better if the DSL can support `or` relation and
> > nested
> > > > > > >> expressions.
> > > > > > >>
> > > > > > >> What about a syntax like:
> > > > > > >> ```
> > > > > > >> {
> > > > > > >> "or": [ <- the `or` can be other logical operators, like
> `and`,
> > > > > > >> `!or`, `!and`
> > > > > > >> ["arg_name","==","json"],
> > > > > > >> ["arg_weight",">",10],
> > > > > > >> ["arg_weight","!",">",15]
> > > > > > >> ]
> > > > > > >> }
> > > > > > >> ```
> > > > > > >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10
> or
> > > not
> > > > > > >> ngx.var.arg_weight > 15` )
> > > > > > >> and
> > > > > > >> ```
> > > > > > >> {
> > > > > > >> "!and": {
> > > > > > >> "and": [
> > > > > > >> ["arg_name","==","yaml"]
> > > > > > >> ],
> > > > > > >> "or": [
> > > > > > >> ["arg_name","==","json"],
> > > > > > >> ["arg_weight",">",10],
> > > > > > >> ["arg_weight","!",">",15]
> > > > > > >> ]
> > > > > > >> }
> > > > > > >> }
> > > > > > >> ```
> > > > > > >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name
> ==
> > > > > "json"
> > > > > > or
> > > > > > >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> > > > > > >>
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > *MembPhis*
> > > > > > > My GitHub: https://github.com/membphis
> > > > > > > Apache APISIX: https://github.com/apache/apisix
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > *MembPhis*
> > > > > > My GitHub: https://github.com/membphis
> > > > > > Apache APISIX: https://github.com/apache/apisix
> > > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/apisix
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/apisix
> >
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by Zexuan Luo <sp...@apache.org>.
What about `not or` and `not and`? We can allow space in the operator.
YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:59写道:
> On Thu, Nov 26, 2020 at 2:34 PM Zexuan Luo <sp...@apache.org> wrote:
>
> > I mean using `!or` to represent `not (xxx or xxx)`, and so do `!and`.
> >
>
> I think it is not easy for developers understand this.
>
>
>
> >
> > YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:15写道:
> >
> > > one question, do we support the operator `!or`, `!and` ?
> > >
> > > it is not easy to understand for me :(
> > >
> > > On Thu, Nov 26, 2020 at 12:28 PM Zexuan Luo <sp...@apache.org>
> > > wrote:
> > >
> > > > Personally speaking, I think the SO way is more readable. Because the
> > > > logical operator is the same level with the conditions, therefore we
> > can
> > > > know the conditions and the operator are in the same expression.
> > > >
> > > > Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
> > > >
> > > > > The expression in Stack Overflow is good, but the readability is
> not
> > > > > satifactory,
> > > > > what about modifying it to make it more hierarchical? For example,
> > > > > promoting the level of
> > > > > logical operators.
> > > > >
> > > > > Chao Zhang
> > > > > https://github.com/tokers
> > > > >
> > > > > On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (
> > > membphis@apache.org)
> > > > > wrote:
> > > > >
> > > > > I got this idea from Stack Overfollow[1]
> > > > >
> > > > > [1]
> > > > >
> > > > >
> > > >
> > >
> >
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
> > > > >
> > > > >
> > > > > On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <
> membphis@apache.org>
> > > > > wrote:
> > > > >
> > > > > > I think we can mainly use `array`, I write a new style.
> > > > > >
> > > > > > this style can be compatible with the old rules.
> > > > > >
> > > > > > [
> > > > > > "AND", -- optional
> > > > > > ["arg_name","==","yaml"],
> > > > > > [
> > > > > > "OR",
> > > > > > ["arg_name","==","json"],
> > > > > > ["arg_weight",">",10]
> > > > > > ]
> > > > > > ]
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <
> spacewander@apache.org
> > >
> > > > > wrote:
> > > > > >
> > > > > >> Currently we support a DSL to match routes with variables:
> > > > > >>
> > > > > >> ```
> > > > > >> [
> > > > > >> ["arg_name","==","json"],
> > > > > >> ["arg_weight",">",10],
> > > > > >> ["arg_weight","!",">",15]
> > > > > >> ]
> > > > > >> ```
> > > > > >>
> > > > > >> is evaluated to `ngx.var.arg_name == "json" and
> > ngx.var.arg_weight >
> > > > 10
> > > > > >> and not ngx.var.arg_weight > 15`.
> > > > > >>
> > > > > >> It would be better if the DSL can support `or` relation and
> nested
> > > > > >> expressions.
> > > > > >>
> > > > > >> What about a syntax like:
> > > > > >> ```
> > > > > >> {
> > > > > >> "or": [ <- the `or` can be other logical operators, like `and`,
> > > > > >> `!or`, `!and`
> > > > > >> ["arg_name","==","json"],
> > > > > >> ["arg_weight",">",10],
> > > > > >> ["arg_weight","!",">",15]
> > > > > >> ]
> > > > > >> }
> > > > > >> ```
> > > > > >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or
> > not
> > > > > >> ngx.var.arg_weight > 15` )
> > > > > >> and
> > > > > >> ```
> > > > > >> {
> > > > > >> "!and": {
> > > > > >> "and": [
> > > > > >> ["arg_name","==","yaml"]
> > > > > >> ],
> > > > > >> "or": [
> > > > > >> ["arg_name","==","json"],
> > > > > >> ["arg_weight",">",10],
> > > > > >> ["arg_weight","!",">",15]
> > > > > >> ]
> > > > > >> }
> > > > > >> }
> > > > > >> ```
> > > > > >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name ==
> > > > "json"
> > > > > or
> > > > > >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> > > > > >>
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > *MembPhis*
> > > > > > My GitHub: https://github.com/membphis
> > > > > > Apache APISIX: https://github.com/apache/apisix
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/apisix
> > > > >
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/apisix
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by YuanSheng Wang <me...@apache.org>.
On Thu, Nov 26, 2020 at 2:34 PM Zexuan Luo <sp...@apache.org> wrote:
> I mean using `!or` to represent `not (xxx or xxx)`, and so do `!and`.
>
I think it is not easy for developers understand this.
>
> YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:15写道:
>
> > one question, do we support the operator `!or`, `!and` ?
> >
> > it is not easy to understand for me :(
> >
> > On Thu, Nov 26, 2020 at 12:28 PM Zexuan Luo <sp...@apache.org>
> > wrote:
> >
> > > Personally speaking, I think the SO way is more readable. Because the
> > > logical operator is the same level with the conditions, therefore we
> can
> > > know the conditions and the operator are in the same expression.
> > >
> > > Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
> > >
> > > > The expression in Stack Overflow is good, but the readability is not
> > > > satifactory,
> > > > what about modifying it to make it more hierarchical? For example,
> > > > promoting the level of
> > > > logical operators.
> > > >
> > > > Chao Zhang
> > > > https://github.com/tokers
> > > >
> > > > On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (
> > membphis@apache.org)
> > > > wrote:
> > > >
> > > > I got this idea from Stack Overfollow[1]
> > > >
> > > > [1]
> > > >
> > > >
> > >
> >
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
> > > >
> > > >
> > > > On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org>
> > > > wrote:
> > > >
> > > > > I think we can mainly use `array`, I write a new style.
> > > > >
> > > > > this style can be compatible with the old rules.
> > > > >
> > > > > [
> > > > > "AND", -- optional
> > > > > ["arg_name","==","yaml"],
> > > > > [
> > > > > "OR",
> > > > > ["arg_name","==","json"],
> > > > > ["arg_weight",">",10]
> > > > > ]
> > > > > ]
> > > > >
> > > > >
> > > > >
> > > > > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <spacewander@apache.org
> >
> > > > wrote:
> > > > >
> > > > >> Currently we support a DSL to match routes with variables:
> > > > >>
> > > > >> ```
> > > > >> [
> > > > >> ["arg_name","==","json"],
> > > > >> ["arg_weight",">",10],
> > > > >> ["arg_weight","!",">",15]
> > > > >> ]
> > > > >> ```
> > > > >>
> > > > >> is evaluated to `ngx.var.arg_name == "json" and
> ngx.var.arg_weight >
> > > 10
> > > > >> and not ngx.var.arg_weight > 15`.
> > > > >>
> > > > >> It would be better if the DSL can support `or` relation and nested
> > > > >> expressions.
> > > > >>
> > > > >> What about a syntax like:
> > > > >> ```
> > > > >> {
> > > > >> "or": [ <- the `or` can be other logical operators, like `and`,
> > > > >> `!or`, `!and`
> > > > >> ["arg_name","==","json"],
> > > > >> ["arg_weight",">",10],
> > > > >> ["arg_weight","!",">",15]
> > > > >> ]
> > > > >> }
> > > > >> ```
> > > > >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or
> not
> > > > >> ngx.var.arg_weight > 15` )
> > > > >> and
> > > > >> ```
> > > > >> {
> > > > >> "!and": {
> > > > >> "and": [
> > > > >> ["arg_name","==","yaml"]
> > > > >> ],
> > > > >> "or": [
> > > > >> ["arg_name","==","json"],
> > > > >> ["arg_weight",">",10],
> > > > >> ["arg_weight","!",">",15]
> > > > >> ]
> > > > >> }
> > > > >> }
> > > > >> ```
> > > > >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name ==
> > > "json"
> > > > or
> > > > >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> > > > >>
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/apisix
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/apisix
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/apisix
> >
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by Zexuan Luo <sp...@apache.org>.
I mean using `!or` to represent `not (xxx or xxx)`, and so do `!and`.
YuanSheng Wang <me...@apache.org> 于2020年11月26日周四 下午2:15写道:
> one question, do we support the operator `!or`, `!and` ?
>
> it is not easy to understand for me :(
>
> On Thu, Nov 26, 2020 at 12:28 PM Zexuan Luo <sp...@apache.org>
> wrote:
>
> > Personally speaking, I think the SO way is more readable. Because the
> > logical operator is the same level with the conditions, therefore we can
> > know the conditions and the operator are in the same expression.
> >
> > Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
> >
> > > The expression in Stack Overflow is good, but the readability is not
> > > satifactory,
> > > what about modifying it to make it more hierarchical? For example,
> > > promoting the level of
> > > logical operators.
> > >
> > > Chao Zhang
> > > https://github.com/tokers
> > >
> > > On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (
> membphis@apache.org)
> > > wrote:
> > >
> > > I got this idea from Stack Overfollow[1]
> > >
> > > [1]
> > >
> > >
> >
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
> > >
> > >
> > > On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org>
> > > wrote:
> > >
> > > > I think we can mainly use `array`, I write a new style.
> > > >
> > > > this style can be compatible with the old rules.
> > > >
> > > > [
> > > > "AND", -- optional
> > > > ["arg_name","==","yaml"],
> > > > [
> > > > "OR",
> > > > ["arg_name","==","json"],
> > > > ["arg_weight",">",10]
> > > > ]
> > > > ]
> > > >
> > > >
> > > >
> > > > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org>
> > > wrote:
> > > >
> > > >> Currently we support a DSL to match routes with variables:
> > > >>
> > > >> ```
> > > >> [
> > > >> ["arg_name","==","json"],
> > > >> ["arg_weight",">",10],
> > > >> ["arg_weight","!",">",15]
> > > >> ]
> > > >> ```
> > > >>
> > > >> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight >
> > 10
> > > >> and not ngx.var.arg_weight > 15`.
> > > >>
> > > >> It would be better if the DSL can support `or` relation and nested
> > > >> expressions.
> > > >>
> > > >> What about a syntax like:
> > > >> ```
> > > >> {
> > > >> "or": [ <- the `or` can be other logical operators, like `and`,
> > > >> `!or`, `!and`
> > > >> ["arg_name","==","json"],
> > > >> ["arg_weight",">",10],
> > > >> ["arg_weight","!",">",15]
> > > >> ]
> > > >> }
> > > >> ```
> > > >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
> > > >> ngx.var.arg_weight > 15` )
> > > >> and
> > > >> ```
> > > >> {
> > > >> "!and": {
> > > >> "and": [
> > > >> ["arg_name","==","yaml"]
> > > >> ],
> > > >> "or": [
> > > >> ["arg_name","==","json"],
> > > >> ["arg_weight",">",10],
> > > >> ["arg_weight","!",">",15]
> > > >> ]
> > > >> }
> > > >> }
> > > >> ```
> > > >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name ==
> > "json"
> > > or
> > > >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> > > >>
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/apisix
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/apisix
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by YuanSheng Wang <me...@apache.org>.
one question, do we support the operator `!or`, `!and` ?
it is not easy to understand for me :(
On Thu, Nov 26, 2020 at 12:28 PM Zexuan Luo <sp...@apache.org> wrote:
> Personally speaking, I think the SO way is more readable. Because the
> logical operator is the same level with the conditions, therefore we can
> know the conditions and the operator are in the same expression.
>
> Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
>
> > The expression in Stack Overflow is good, but the readability is not
> > satifactory,
> > what about modifying it to make it more hierarchical? For example,
> > promoting the level of
> > logical operators.
> >
> > Chao Zhang
> > https://github.com/tokers
> >
> > On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (membphis@apache.org)
> > wrote:
> >
> > I got this idea from Stack Overfollow[1]
> >
> > [1]
> >
> >
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
> >
> >
> > On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org>
> > wrote:
> >
> > > I think we can mainly use `array`, I write a new style.
> > >
> > > this style can be compatible with the old rules.
> > >
> > > [
> > > "AND", -- optional
> > > ["arg_name","==","yaml"],
> > > [
> > > "OR",
> > > ["arg_name","==","json"],
> > > ["arg_weight",">",10]
> > > ]
> > > ]
> > >
> > >
> > >
> > > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org>
> > wrote:
> > >
> > >> Currently we support a DSL to match routes with variables:
> > >>
> > >> ```
> > >> [
> > >> ["arg_name","==","json"],
> > >> ["arg_weight",">",10],
> > >> ["arg_weight","!",">",15]
> > >> ]
> > >> ```
> > >>
> > >> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight >
> 10
> > >> and not ngx.var.arg_weight > 15`.
> > >>
> > >> It would be better if the DSL can support `or` relation and nested
> > >> expressions.
> > >>
> > >> What about a syntax like:
> > >> ```
> > >> {
> > >> "or": [ <- the `or` can be other logical operators, like `and`,
> > >> `!or`, `!and`
> > >> ["arg_name","==","json"],
> > >> ["arg_weight",">",10],
> > >> ["arg_weight","!",">",15]
> > >> ]
> > >> }
> > >> ```
> > >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
> > >> ngx.var.arg_weight > 15` )
> > >> and
> > >> ```
> > >> {
> > >> "!and": {
> > >> "and": [
> > >> ["arg_name","==","yaml"]
> > >> ],
> > >> "or": [
> > >> ["arg_name","==","json"],
> > >> ["arg_weight",">",10],
> > >> ["arg_weight","!",">",15]
> > >> ]
> > >> }
> > >> }
> > >> ```
> > >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name ==
> "json"
> > or
> > >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> > >>
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/apisix
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/apisix
> >
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by Zexuan Luo <sp...@apache.org>.
Personally speaking, I think the SO way is more readable. Because the
logical operator is the same level with the conditions, therefore we can
know the conditions and the operator are in the same expression.
Chao Zhang <zc...@gmail.com> 于2020年11月25日周三 下午5:36写道:
> The expression in Stack Overflow is good, but the readability is not
> satifactory,
> what about modifying it to make it more hierarchical? For example,
> promoting the level of
> logical operators.
>
> Chao Zhang
> https://github.com/tokers
>
> On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (membphis@apache.org)
> wrote:
>
> I got this idea from Stack Overfollow[1]
>
> [1]
>
> https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
>
>
> On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org>
> wrote:
>
> > I think we can mainly use `array`, I write a new style.
> >
> > this style can be compatible with the old rules.
> >
> > [
> > "AND", -- optional
> > ["arg_name","==","yaml"],
> > [
> > "OR",
> > ["arg_name","==","json"],
> > ["arg_weight",">",10]
> > ]
> > ]
> >
> >
> >
> > On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org>
> wrote:
> >
> >> Currently we support a DSL to match routes with variables:
> >>
> >> ```
> >> [
> >> ["arg_name","==","json"],
> >> ["arg_weight",">",10],
> >> ["arg_weight","!",">",15]
> >> ]
> >> ```
> >>
> >> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
> >> and not ngx.var.arg_weight > 15`.
> >>
> >> It would be better if the DSL can support `or` relation and nested
> >> expressions.
> >>
> >> What about a syntax like:
> >> ```
> >> {
> >> "or": [ <- the `or` can be other logical operators, like `and`,
> >> `!or`, `!and`
> >> ["arg_name","==","json"],
> >> ["arg_weight",">",10],
> >> ["arg_weight","!",">",15]
> >> ]
> >> }
> >> ```
> >> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
> >> ngx.var.arg_weight > 15` )
> >> and
> >> ```
> >> {
> >> "!and": {
> >> "and": [
> >> ["arg_name","==","yaml"]
> >> ],
> >> "or": [
> >> ["arg_name","==","json"],
> >> ["arg_weight",">",10],
> >> ["arg_weight","!",">",15]
> >> ]
> >> }
> >> }
> >> ```
> >> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json"
> or
> >> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> >>
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/apisix
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by Chao Zhang <zc...@gmail.com>.
The expression in Stack Overflow is good, but the readability is not
satifactory,
what about modifying it to make it more hierarchical? For example,
promoting the level of
logical operators.
Chao Zhang
https://github.com/tokers
On November 25, 2020 at 4:04:29 PM, YuanSheng Wang (membphis@apache.org)
wrote:
I got this idea from Stack Overfollow[1]
[1]
https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org> wrote:
> I think we can mainly use `array`, I write a new style.
>
> this style can be compatible with the old rules.
>
> [
> "AND", -- optional
> ["arg_name","==","yaml"],
> [
> "OR",
> ["arg_name","==","json"],
> ["arg_weight",">",10]
> ]
> ]
>
>
>
> On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org>
wrote:
>
>> Currently we support a DSL to match routes with variables:
>>
>> ```
>> [
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> ```
>>
>> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
>> and not ngx.var.arg_weight > 15`.
>>
>> It would be better if the DSL can support `or` relation and nested
>> expressions.
>>
>> What about a syntax like:
>> ```
>> {
>> "or": [ <- the `or` can be other logical operators, like `and`,
>> `!or`, `!and`
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> }
>> ```
>> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
>> ngx.var.arg_weight > 15` )
>> and
>> ```
>> {
>> "!and": {
>> "and": [
>> ["arg_name","==","yaml"]
>> ],
>> "or": [
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> }
>> }
>> ```
>> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json"
or
>> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
>>
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by YuanSheng Wang <me...@apache.org>.
I got this idea from Stack Overfollow[1]
[1]
https://stackoverflow.com/questions/20737045/representing-logic-as-data-in-json
On Wed, Nov 25, 2020 at 4:02 PM YuanSheng Wang <me...@apache.org> wrote:
> I think we can mainly use `array`, I write a new style.
>
> this style can be compatible with the old rules.
>
> [
> "AND", -- optional
> ["arg_name","==","yaml"],
> [
> "OR",
> ["arg_name","==","json"],
> ["arg_weight",">",10]
> ]
> ]
>
>
>
> On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org> wrote:
>
>> Currently we support a DSL to match routes with variables:
>>
>> ```
>> [
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> ```
>>
>> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
>> and not ngx.var.arg_weight > 15`.
>>
>> It would be better if the DSL can support `or` relation and nested
>> expressions.
>>
>> What about a syntax like:
>> ```
>> {
>> "or": [ <- the `or` can be other logical operators, like `and`,
>> `!or`, `!and`
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> }
>> ```
>> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
>> ngx.var.arg_weight > 15` )
>> and
>> ```
>> {
>> "!and": {
>> "and": [
>> ["arg_name","==","yaml"]
>> ],
>> "or": [
>> ["arg_name","==","json"],
>> ["arg_weight",">",10],
>> ["arg_weight","!",">",15]
>> ]
>> }
>> }
>> ```
>> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json" or
>> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
>>
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by Zexuan Luo <sp...@apache.org>.
So you mean
```
[
"!AND", -- optional
["arg_name","==","yaml"],
[
"!OR",
["arg_name","==","json"],
["arg_weight",">",10]
]
]
```
for the `not` logical operator?
YuanSheng Wang <me...@apache.org> 于2020年11月25日周三 下午4:03写道:
> I think we can mainly use `array`, I write a new style.
>
> this style can be compatible with the old rules.
>
> [
> "AND", -- optional
> ["arg_name","==","yaml"],
> [
> "OR",
> ["arg_name","==","json"],
> ["arg_weight",">",10]
> ]
> ]
>
>
>
> On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org> wrote:
>
> > Currently we support a DSL to match routes with variables:
> >
> > ```
> > [
> > ["arg_name","==","json"],
> > ["arg_weight",">",10],
> > ["arg_weight","!",">",15]
> > ]
> > ```
> >
> > is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
> > and not ngx.var.arg_weight > 15`.
> >
> > It would be better if the DSL can support `or` relation and nested
> > expressions.
> >
> > What about a syntax like:
> > ```
> > {
> > "or": [ <- the `or` can be other logical operators, like `and`,
> > `!or`, `!and`
> > ["arg_name","==","json"],
> > ["arg_weight",">",10],
> > ["arg_weight","!",">",15]
> > ]
> > }
> > ```
> > (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
> > ngx.var.arg_weight > 15` )
> > and
> > ```
> > {
> > "!and": {
> > "and": [
> > ["arg_name","==","yaml"]
> > ],
> > "or": [
> > ["arg_name","==","json"],
> > ["arg_weight",">",10],
> > ["arg_weight","!",">",15]
> > ]
> > }
> > }
> > ```
> > (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json"
> or
> > ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/apisix
>
Re: [DISCUSS] Add a small DSL to support complex conditions
Posted by YuanSheng Wang <me...@apache.org>.
I think we can mainly use `array`, I write a new style.
this style can be compatible with the old rules.
[
"AND", -- optional
["arg_name","==","yaml"],
[
"OR",
["arg_name","==","json"],
["arg_weight",">",10]
]
]
On Wed, Nov 25, 2020 at 2:58 PM Zexuan Luo <sp...@apache.org> wrote:
> Currently we support a DSL to match routes with variables:
>
> ```
> [
> ["arg_name","==","json"],
> ["arg_weight",">",10],
> ["arg_weight","!",">",15]
> ]
> ```
>
> is evaluated to `ngx.var.arg_name == "json" and ngx.var.arg_weight > 10
> and not ngx.var.arg_weight > 15`.
>
> It would be better if the DSL can support `or` relation and nested
> expressions.
>
> What about a syntax like:
> ```
> {
> "or": [ <- the `or` can be other logical operators, like `and`,
> `!or`, `!and`
> ["arg_name","==","json"],
> ["arg_weight",">",10],
> ["arg_weight","!",">",15]
> ]
> }
> ```
> (means `ngx.var.arg_name == "json" or ngx.var.arg_weight > 10 or not
> ngx.var.arg_weight > 15` )
> and
> ```
> {
> "!and": {
> "and": [
> ["arg_name","==","yaml"]
> ],
> "or": [
> ["arg_name","==","json"],
> ["arg_weight",">",10],
> ["arg_weight","!",">",15]
> ]
> }
> }
> ```
> (means `not (ngx.var.arg_name == "yaml" and (ngx.var.arg_name == "json" or
> ngx.var.arg_weight > 10 or not ngx.var.arg_weight > 15))` )
>
--
*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/apisix