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
200541d5
Unverified
Commit
200541d5
authored
7 months ago
by
Ngoc Khuat
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix sync indexes mark all fields with same name as indexed if one of them is (#46313)
parent
e2086b2f
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/test/metabase/driver/mongo_test.clj
+46
-2
46 additions, 2 deletions
modules/drivers/mongo/test/metabase/driver/mongo_test.clj
src/metabase/sync/sync_metadata/indexes.clj
+1
-1
1 addition, 1 deletion
src/metabase/sync/sync_metadata/indexes.clj
with
47 additions
and
3 deletions
modules/drivers/mongo/test/metabase/driver/mongo_test.clj
+
46
−
2
View file @
200541d5
...
...
@@ -265,6 +265,50 @@
(
finally
(
t2/delete!
:model/Database
(
mt/id
)))))))
(
deftest
sync-indexes-top-level-and-nested-column-with-same-name-test
(
mt/test-driver
:mongo
(
testing
"when a table has fields at the top level and nested level with the same name
we shouldn't mistakenly mark both of them as indexed if one is(#46312)"
(
mt/dataset
(
mt/dataset-definition
"index-duplicate-name"
[
"top-level-indexed"
[{
:field-name
"name"
:indexed?
true
:base-type
:type/Text
}
{
:field-name
"class"
:indexed?
false
:base-type
:type/Text
}]
[[
"Metabase"
{
"name"
"Physics"
}]]]
[
"nested-indexed"
[{
:field-name
"name"
:indexed?
false
:base-type
:type/Text
}
{
:field-name
"class"
:indexed?
false
:base-type
:type/Text
}]
[[
"Metabase"
{
"name"
"Physics"
}]]])
(
mongo.connection/with-mongo-database
[
db
(
mt/db
)]
(
mongo.util/create-index
(
mongo.util/collection
db
"nested-indexed"
)
(
array-map
"class.name"
1
)))
(
sync/sync-database!
(
mt/db
)
{
:scan
:schema
})
(
testing
"top level indexed, nested not"
(
let
[
name-fields
(
t2/select
[
:model/Field
:name
:parent_id
:database_indexed
]
:table_id
(
mt/id
:top-level-indexed
)
:name
"name"
)]
(
testing
"sanity check that we have 2 `name` fields"
(
is
(
=
2
(
count
name-fields
))))
(
testing
"only the top level field is indexed"
(
is
(
=?
[{
:name
"name"
:parent_id
nil
:database_indexed
true
}
{
:name
"name"
:parent_id
(
mt/malli=?
int?
)
:database_indexed
false
}]
(
sort-by
:parent_id
name-fields
))))))
(
testing
"nested field indexed, top level not"
(
let
[
name-fields
(
t2/select
[
:model/Field
:name
:parent_id
:database_indexed
]
:table_id
(
mt/id
:nested-indexed
)
:name
"name"
)]
(
testing
"sanity check that we have 2 `name` fields"
(
is
(
=
2
(
count
name-fields
))))
(
testing
"only the nested field is indexed"
(
is
(
=?
[{
:name
"name"
:parent_id
nil
:database_indexed
false
}
{
:name
"name"
:parent_id
(
mt/malli=?
int?
)
:database_indexed
true
}]
(
sort-by
:parent_id
name-fields
))))))))))
(
deftest
describe-table-indexes-test
(
mt/test-driver
:mongo
(
mt/dataset
(
mt/dataset-definition
"indexing"
...
...
@@ -561,8 +605,8 @@
(
testing
"make sure x-rays don't use features that the driver doesn't support"
(
is
(
empty?
(
lib.util.match/match-one
(
->>
(
magic/automagic-analysis
(
t2/select-one
Field
:id
(
mt/id
:venues
:price
))
{})
:dashcards
(
mapcat
(
comp
:breakout
:query
:dataset_query
:card
)))
:dashcards
(
mapcat
(
comp
:breakout
:query
:dataset_query
:card
)))
[
:field
_
(
_
:guard
:binning
)]))))))
(
deftest
no-values-test
...
...
This diff is collapsed.
Click to expand it.
src/metabase/sync/sync_metadata/indexes.clj
+
1
−
1
View file @
200541d5
...
...
@@ -19,7 +19,7 @@
(
let
[
normal-indexes
(
->>
indexes
(
filter
#
(
=
(
:type
%
)
:normal-column-index
))
(
map
:value
))
nested-indexes
(
->>
indexes
(
filter
#
(
=
(
:type
%
)
:nested-column-index
))
(
map
:value
))
normal-indexes-field-ids
(
when
(
seq
normal-indexes
)
(
t2/select-pks-vec
:model/Field
:name
[
:in
normal-indexes
]
:table_id
table-id
))
(
t2/select-pks-vec
:model/Field
:name
[
:in
normal-indexes
]
:table_id
table-id
:parent_id
nil
))
nested-indexes-field-ids
(
remove
nil?
(
map
#
(
field/nested-field-names->field-id
table-id
%
)
nested-indexes
))]
(
set
(
filter
some?
(
concat
normal-indexes-field-ids
nested-indexes-field-ids
))))))
...
...
This diff is collapsed.
Click to expand it.
Nicholas Bentley
@nbentley
mentioned in commit
bafe60bf
·
7 months ago
mentioned in commit
bafe60bf
mentioned in commit bafe60bfc819dd544d7617588023800889f88292
Toggle commit list
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