Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
235e56b6
Commit
235e56b6
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Patches
Plain Diff
Добавлена проверка на тип array для функции len
parent
964cf101
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/expr/mongo.go
+10
-9
10 additions, 9 deletions
pkg/expr/mongo.go
pkg/expr/mongo_test.go
+3
-3
3 additions, 3 deletions
pkg/expr/mongo_test.go
with
13 additions
and
12 deletions
pkg/expr/mongo.go
+
10
−
9
View file @
235e56b6
...
@@ -673,27 +673,28 @@ func (c *compiler) handleLenNode(node *ast.BinaryNode) bson.M {
...
@@ -673,27 +673,28 @@ func (c *compiler) handleLenNode(node *ast.BinaryNode) bson.M {
panic
(
"len() can only be compared with non-negative number"
)
panic
(
"len() can only be compared with non-negative number"
)
}
}
field
:=
c
.
identifier
(
lenNode
.
Arguments
[
0
])
switch
op
:=
node
.
Operator
;
{
switch
op
:=
node
.
Operator
;
{
case
(
op
==
"=="
||
op
==
"<="
)
&&
length
==
0
:
case
(
op
==
"=="
||
op
==
"<="
)
&&
length
==
0
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}}
return
bson
.
M
{
field
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}}
case
(
op
==
"!="
||
op
==
">"
)
&&
length
==
0
:
case
(
op
==
"!="
||
op
==
">"
)
&&
length
==
0
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}}
return
bson
.
M
{
field
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}}
case
op
==
">="
&&
length
==
0
:
case
op
==
">="
&&
length
==
0
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}}
return
bson
.
M
{
field
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}}
case
op
==
"<"
&&
length
==
0
:
case
op
==
"<"
&&
length
==
0
:
panic
(
"invalid comparison: len() cannot be less than 0"
)
panic
(
"invalid comparison: len() cannot be less than 0"
)
case
op
==
"=="
:
case
op
==
"=="
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
:
bson
.
M
{
"$size"
:
length
}}
return
bson
.
M
{
field
:
bson
.
M
{
"$size"
:
length
}}
case
op
==
"!="
:
case
op
==
"!="
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
length
}}}
return
bson
.
M
{
field
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
length
}
,
"$type"
:
"array"
}}
case
op
==
">"
:
case
op
==
">"
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
+
"."
+
strconv
.
Itoa
(
length
)
:
bson
.
M
{
"$exists"
:
true
}}
return
bson
.
M
{
field
+
"."
+
strconv
.
Itoa
(
length
)
:
bson
.
M
{
"$exists"
:
true
}}
case
op
==
">="
:
case
op
==
">="
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
+
"."
+
strconv
.
Itoa
(
length
-
1
)
:
bson
.
M
{
"$exists"
:
true
}}
return
bson
.
M
{
field
+
"."
+
strconv
.
Itoa
(
length
-
1
)
:
bson
.
M
{
"$exists"
:
true
}}
case
op
==
"<"
:
case
op
==
"<"
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
+
"."
+
strconv
.
Itoa
(
length
-
1
)
:
bson
.
M
{
"$exists"
:
false
}}
return
bson
.
M
{
field
+
"."
+
strconv
.
Itoa
(
length
-
1
)
:
bson
.
M
{
"$exists"
:
false
}
,
field
:
bson
.
M
{
"$type"
:
"array"
}
}
case
op
==
"<="
:
case
op
==
"<="
:
return
bson
.
M
{
c
.
identifier
(
lenNode
.
Arguments
[
0
])
+
"."
+
strconv
.
Itoa
(
length
)
:
bson
.
M
{
"$exists"
:
false
}}
return
bson
.
M
{
field
+
"."
+
strconv
.
Itoa
(
length
)
:
bson
.
M
{
"$exists"
:
false
}
,
field
:
bson
.
M
{
"$type"
:
"array"
}
}
default
:
default
:
panic
(
"invalid comparison operator with len()"
)
panic
(
"invalid comparison operator with len()"
)
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo_test.go
+
3
−
3
View file @
235e56b6
...
@@ -39,15 +39,15 @@ func TestConvertToMongo(t *testing.T) {
...
@@ -39,15 +39,15 @@ func TestConvertToMongo(t *testing.T) {
{
"len#5"
,
"len(s) == s"
,
nil
,
nil
,
true
},
{
"len#5"
,
"len(s) == s"
,
nil
,
nil
,
true
},
{
"len eq"
,
"len(s) == 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len eq"
,
"len(s) == 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len eq zero"
,
"len(s) == 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len eq zero"
,
"len(s) == 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len ne"
,
"len(s) != 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
1
}}},
false
},
{
"len ne"
,
"len(s) != 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
1
}
,
"$type"
:
"array"
}},
false
},
{
"len ne zero"
,
"len(s) != 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$ne"
:
bson
.
A
{},
"$type"
:
"array"
}},
false
},
{
"len ne zero"
,
"len(s) != 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$ne"
:
bson
.
A
{},
"$type"
:
"array"
}},
false
},
{
"len gt"
,
"len(s) > 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gt"
,
"len(s) > 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gt zero"
,
"len(s) > 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len gt zero"
,
"len(s) > 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len gte"
,
"len(s) >= 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gte"
,
"len(s) >= 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gte zero"
,
"len(s) >= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
false
},
{
"len gte zero"
,
"len(s) >= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
false
},
{
"len lt"
,
"len(s) < 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
}},
false
},
{
"len lt"
,
"len(s) < 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
}
,
"s"
:
bson
.
M
{
"$type"
:
"array"
}
},
false
},
{
"len lt zero"
,
"len(s) < 0"
,
nil
,
nil
,
true
},
{
"len lt zero"
,
"len(s) < 0"
,
nil
,
nil
,
true
},
{
"len lte"
,
"len(s) <= 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
false
}},
false
},
{
"len lte"
,
"len(s) <= 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
false
}
,
"s"
:
bson
.
M
{
"$type"
:
"array"
}
},
false
},
{
"len lte zero"
,
"len(s) <= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len lte zero"
,
"len(s) <= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"field#1"
,
"s.test > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#1"
,
"s.test > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#2"
,
"s['test'] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#2"
,
"s['test'] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment