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
11de3080
Commit
11de3080
authored
7 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Don't overwrite previously infered special types
parent
c50f5c27
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/sync/analyze/classifiers/name.clj
+12
-9
12 additions, 9 deletions
src/metabase/sync/analyze/classifiers/name.clj
with
12 additions
and
9 deletions
src/metabase/sync/analyze/classifiers/name.clj
+
12
−
9
View file @
11de3080
...
...
@@ -107,19 +107,22 @@
(
s/defn
^
:private
special-type-for-name-and-base-type
:-
(
s/maybe
su/FieldType
)
"If `name` and `base-type` matches a known pattern, return the `special_type` we should assign to it."
[
field-name
:-
su/NonBlankString,
base-type
:-
su/FieldType
]
(
or
(
when
(
=
"id"
(
str/lower-case
field-name
))
:type/PK
)
(
some
(
fn
[[
name-pattern
valid-base-types
special-type
]]
(
when
(
and
(
some
(
partial
isa?
base-type
)
valid-base-types
)
(
re-find
name-pattern
(
str/lower-case
field-name
)))
special-type
))
pattern+base-types+special-type
)))
"If field `:name` and `:base_type` matches a known pattern, return the `special_type` we should assign to it."
[
field
:-
i/FieldInstance
]
(
cond
(
=
"id"
(
str/lower-case
(
:name
field
)))
:type/PK
(
nil?
(
:special_type
field
))
; don't overwrite previously infered types
(
some
(
fn
[[
name-pattern
valid-base-types
special-type
]]
(
when
(
and
(
some
(
partial
isa?
(
:base_type
field
))
valid-base-types
)
(
re-find
name-pattern
(
str/lower-case
(
:name
field
))))
special-type
))
pattern+base-types+special-type
)))
(
s/defn
infer-special-type
:-
(
s/maybe
i/FieldInstance
)
"Classifer that infers the special type of a FIELD based on its name and base type."
[
field
:-
i/FieldInstance,
_
:-
(
s/maybe
i/Fingerprint
)]
(
when-let
[
inferred-special-type
(
special-type-for-name-and-base-type
(
:name
field
)
(
:base_type
field
)
)]
(
when-let
[
inferred-special-type
(
special-type-for-name-and-base-type
field
)]
(
log/debug
(
format
"Based on the name of %s, we're giving it a special type of %s."
(
sync-util/name-for-logging
field
)
inferred-special-type
))
...
...
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