Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
4dd50562
Unverified
Commit
4dd50562
authored
2 years ago
by
Ngoc Khuat
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix mongo not able to filter by UUID (#26367)
parent
e2939bf6
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
modules/drivers/mongo/src/metabase/driver/mongo/query_processor.clj
+26
-8
26 additions, 8 deletions
...ivers/mongo/src/metabase/driver/mongo/query_processor.clj
modules/drivers/mongo/test/metabase/driver/mongo_test.clj
+59
-30
59 additions, 30 deletions
modules/drivers/mongo/test/metabase/driver/mongo_test.clj
with
85 additions
and
38 deletions
modules/drivers/mongo/src/metabase/driver/mongo/query_processor.clj
+
26
−
8
View file @
4dd50562
...
...
@@ -25,7 +25,8 @@
$multiply
$ne
$not
$or
$project
$regex
$second
$size
$skip
$sort
$strcasecmp
$subtract
$sum
$toLower
$year
]]
[
schema.core
:as
s
])
(
:import
org.bson.types.ObjectId
))
(
:import
[
org.bson.types
ObjectId
Binary
]
org.bson.BsonBinarySubType
))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Schema |
...
...
@@ -289,15 +290,32 @@
(
defmethod
->rvalue
nil
[
_
]
nil
)
(
defn-
uuid->bsonbinary
[
u
]
(
let
[
lo
(
.getLeastSignificantBits
^
java.util.UUID
u
)
hi
(
.getMostSignificantBits
^
java.util.UUID
u
)
ba
(
->
(
java.nio.ByteBuffer/allocate
16
)
; UUID is 128 bits-long
(
.putLong
hi
)
(
.putLong
lo
)
(
.array
))]
(
Binary.
BsonBinarySubType/UUID_STANDARD
ba
)))
(
defmethod
->rvalue
:value
[[
_
value
{
base-type
:base_type
}]]
(
if
(
and
(
isa?
base-type
:type/MongoBSONID
)
(
some?
value
))
;; Passing nil or "" to the ObjectId constructor throws an exception
;; "invalid hexadecimal representation of an ObjectId: []" so, just treat it as nil
(
when
(
not=
value
""
)
(
ObjectId.
(
str
value
)))
value
))
(
cond
;; Passing nil or "" to the ObjectId or Binary constructor throws an exception
(
or
(
nil?
value
)
(
=
value
""
))
value
(
isa?
base-type
:type/MongoBSONID
)
(
ObjectId.
(
str
value
))
(
isa?
base-type
:type/UUID
)
(
->
(
str
value
)
java.util.UUID/fromString
uuid->bsonbinary
)
:else
value
))
(
defn-
$date-from-string
[
s
]
{
:$dateFromString
{
:dateString
(
str
s
)}})
...
...
This diff is collapsed.
Click to expand it.
modules/drivers/mongo/test/metabase/driver/mongo_test.clj
+
59
−
30
View file @
4dd50562
...
...
@@ -91,7 +91,7 @@
:dbname
"metabase-test"
:version
"2.2134234.lol"
}
:expected
false
}]
:let
[
ssl-details
(
tdm/conn-details
details
)]]
:let
[
ssl-details
(
tdm/conn-details
details
)]]
(
testing
(
str
"connect with "
details
)
(
is
(
=
expected
(
let
[
db
(
db/insert!
Database
{
:name
"dummy"
,
:engine
"mongo"
,
:details
ssl-details
})]
...
...
@@ -264,42 +264,71 @@
{
:order-by
[
:name
]})]
(
into
{}
field
))))))))))
(
tx/defdataset
with-bson-ids
[[
"birds"
[{
:field-name
"name"
,
:base-type
:type/Text
}
{
:field-name
"bird_id"
,
:base-type
:type/MongoBSONID
}]
[[
"Rasta Toucan"
(
ObjectId.
"012345678901234567890123"
)]
[
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)]
{
:field-name
"bird_id"
,
:base-type
:type/MongoBSONID
}
{
:field-name
"bird_uuid"
,
:base-type
:type/UUID
}]
[[
"Rasta Toucan"
(
ObjectId.
"012345678901234567890123"
)
"11111111-1111-1111-1111-111111111111"
]
[
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
]
[
"Unlucky Raven"
nil
]]]])
(
deftest
bson-ids-test
(
mt/test-driver
:mongo
(
testing
"BSON IDs"
(
is
(
=
[[
2
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)]]
(
rows
(
mt/dataset
with-bson-ids
(
mt/run-mbql-query
birds
{
:filter
[
:=
$bird_id
"abcdefabcdefabcdefabcdef"
]}))))
"Check that we support Mongo BSON ID and can filter by it (#1367)"
)
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/dataset
with-bson-ids
(
mt/run-mbql-query
birds
{
:filter
[
:is-null
$bird_id
]}))))
"handle null ObjectId queries properly (#11134)"
)
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/dataset
with-bson-ids
(
mt/run-mbql-query
birds
{
:filter
[
:is-empty
$bird_id
]}))))
"treat null ObjectId as empty (#15801)"
)
(
is
(
=
[[
1
"Rasta Toucan"
(
ObjectId.
"012345678901234567890123"
)]
[
2
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)]]
(
rows
(
mt/dataset
with-bson-ids
(
mt/run-mbql-query
birds
{
:filter
[
:not-empty
$bird_id
]}))))
"treat non-null ObjectId as not-empty (#15801)"
))))
(
mt/dataset
with-bson-ids
(
testing
"BSON IDs"
(
testing
"Check that we support Mongo BSON ID and can filter by it (#1367)"
(
is
(
=
[[
2
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:=
$bird_id
"abcdefabcdefabcdefabcdef"
]
:fields
[
$id
$name
$bird_id
]})))))
(
testing
"handle null ObjectId queries properly (#11134)"
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:is-null
$bird_id
]
:fields
[
$id
$name
$bird_id
]})))))
(
testing
"treat null ObjectId as empty (#15801)"
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:is-empty
$bird_id
]
:fields
[
$id
$name
$bird_id
]})))))
(
testing
"treat non-null ObjectId as not-empty (#15801)"
(
is
(
=
[[
1
"Rasta Toucan"
(
ObjectId.
"012345678901234567890123"
)]
[
2
"Lucky Pigeon"
(
ObjectId.
"abcdefabcdefabcdefabcdef"
)]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:not-empty
$bird_id
]
:fields
[
$id
$name
$bird_id
]}))))))
(
testing
"BSON UUIDs"
(
testing
"Check that we support Mongo BSON UUID and can filter by it"
(
is
(
=
[[
2
"Lucky Pigeon"
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:=
$bird_uuid
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
]
:fields
[
$id
$name
$bird_uuid
]})))))
(
testing
"handle null UUID queries properly"
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:is-null
$bird_uuid
]
:fields
[
$id
$name
$bird_uuid
]})))))
(
testing
"treat null UUID as empty"
(
is
(
=
[[
3
"Unlucky Raven"
nil
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:is-empty
$bird_uuid
]
:fields
[
$id
$name
$bird_uuid
]}))))))
(
testing
"treat non-null UUID as not-empty"
(
is
(
=
[[
1
"Rasta Toucan"
"11111111-1111-1111-1111-111111111111"
]
[
2
"Lucky Pigeon"
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
]]
(
rows
(
mt/run-mbql-query
birds
{
:filter
[
:not-empty
$bird_uuid
]
:fields
[
$id
$name
$bird_uuid
]}))))))))
(
deftest
bson-fn-call-forms-test
(
mt/test-driver
:mongo
...
...
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