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
d51503b0
Commit
d51503b0
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
test fix (?)
parent
ce9de869
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/sync.clj
+14
-7
14 additions, 7 deletions
src/metabase/driver/sync.clj
test/metabase/driver/query_processor_test.clj
+3
-5
3 additions, 5 deletions
test/metabase/driver/query_processor_test.clj
with
17 additions
and
12 deletions
src/metabase/driver/sync.clj
+
14
−
7
View file @
d51503b0
(
ns
metabase.driver.sync
"The logic for doing DB and Table syncing itself."
(
:require
[
clojure.math.numeric-tower
:as
math
]
[
clojure.string
:as
s
]
[
clojure.tools.logging
:as
log
]
[
colorize.core
:as
color
]
[
korma.core
:as
k
]
...
...
@@ -356,8 +357,11 @@
float
#
{
:DecimalField
:FloatField
}
int-or-text
#
{
:BigIntegerField
:IntegerField
:CharField
:TextField
}
text
#
{
:CharField
:TextField
}
pattern+base-types+special-type
[[
#
"^.*_lat$"
float
:latitude
]
; tuples of [pattern set-of-valid-base-types special-type]
[
#
"^.*_lon$"
float
:longitude
]
; we'll consider a nil set-of-valid-base-types to mean "match any base type"
;; tuples of [pattern set-of-valid-base-types special-type]
;; * Convert field name to lowercase before matching against a pattern
;; * consider a nil set-of-valid-base-types to mean "match any base type"
pattern+base-types+special-type
[[
#
"^.*_lat$"
float
:latitude
]
[
#
"^.*_lon$"
float
:longitude
]
[
#
"^.*_lng$"
float
:longitude
]
[
#
"^.*_long$"
float
:longitude
]
[
#
"^.*_longitude$"
float
:longitude
]
...
...
@@ -368,7 +372,7 @@
[
#
"^active$"
bool-or-int
:category
]
[
#
"^city$"
text
:city
]
[
#
"^country$"
text
:country
]
[
#
"^country
C
ode$"
text
:country
]
[
#
"^country
c
ode$"
text
:country
]
[
#
"^currency$"
int-or-text
:category
]
[
#
"^first_name$"
text
:name
]
[
#
"^full_name$"
text
:name
]
...
...
@@ -392,17 +396,20 @@
[
#
"^type$"
int-or-text
:category
]
[
#
"^url$"
text
:url
]
[
#
"^zip_code$"
int-or-text
:zip_code
]
[
#
"^zip
C
ode$"
int-or-text
:zip_code
]]]
[
#
"^zip
c
ode$"
int-or-text
:zip_code
]]]
;; Check that all the pattern tuples are valid
(
doseq
[[
name-pattern
base-types
special-type
]
pattern+base-types+special-type
]
(
assert
(
u/regex?
name-pattern
))
(
assert
(
every?
(
partial
contains?
field/base-types
)
base-types
))
(
assert
(
contains?
field/special-types
special-type
)))
(
fn
[
field
]
(
fn
[{
base-type
:base_type,
field-name
:name
}]
{
:pre
[(
string?
field-name
)
(
keyword?
base-type
)]}
(
m/find-first
(
fn
[[
name-pattern
valid-base-types
_
]]
(
and
(
or
(
nil?
valid-base-types
)
(
contains?
valid-base-types
(
:
base
_
type
field
)
))
(
re-matches
name-pattern
(
:nam
e
field
))))
(
contains?
valid-base-types
base
-
type
))
(
re-matches
name-pattern
(
s/lower-cas
e
field
-name
))))
pattern+base-types+special-type
))))
(
defn
auto-assign-field-special-type-by-name!
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/query_processor_test.clj
+
3
−
5
View file @
d51503b0
...
...
@@ -130,7 +130,7 @@
(
case
col
:id
{
:extra_info
{}
:special_type
:id,
:base_type
(
id-field-type
)
,
:description
nil,
:name
(
format-name
"id"
)
:table_id
(
id
:categories
)
,
:id
(
id
:categories
:id
)}
:name
{
:extra_info
{}
:special_type
nil
,
:base_type
:TextField,
:description
nil,
:name
(
format-name
"name"
)
:name
{
:extra_info
{}
:special_type
:name
,
:base_type
:TextField,
:description
nil,
:name
(
format-name
"name"
)
:table_id
(
id
:categories
)
,
:id
(
id
:categories
:name
)}))
;; #### checkins
...
...
@@ -296,10 +296,8 @@
[
4
"Asian"
]
[
5
"BBQ"
]]
:columns
(
->columns
"id"
"name"
)
:cols
[{
:extra_info
{}
:special_type
:id,
:base_type
(
id-field-type
)
,
:description
nil,
:name
(
format-name
"id"
)
:table_id
(
id
:categories
)
,
:id
(
id
:categories
:id
)}
{
:extra_info
{}
:special_type
nil,
:base_type
:TextField,
:description
nil,
:name
(
format-name
"name"
)
:table_id
(
id
:categories
)
,
:id
(
id
:categories
:name
)}]}
:cols
[(
categories-col
:id
)
(
categories-col
:name
)]}
{
:source_table
(
id
:categories
)
:aggregation
[
"rows"
]
:page
{
:items
5
...
...
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