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
2a68dfab
Unverified
Commit
2a68dfab
authored
1 year ago
by
Chris Truter
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix parsing integers after floats in CSV upload (#40552)
parent
b206d85b
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
src/metabase/upload.clj
+17
-11
17 additions, 11 deletions
src/metabase/upload.clj
test/metabase/upload_test.clj
+19
-0
19 additions, 0 deletions
test/metabase/upload_test.clj
with
36 additions
and
11 deletions
src/metabase/upload.clj
+
17
−
11
View file @
2a68dfab
...
...
@@ -175,7 +175,9 @@
number-regex
"\\s*"
upload-parsing/currency-regex
"?"
)))
(
defn-
int-regex
[
number-separators
]
(
defn-
int-regex
"Matches numbers which do not have a decimal separator."
[
number-separators
]
(
with-parens
(
with-currency
(
case
number-separators
...
...
@@ -184,7 +186,9 @@
", "
#
"\d[\d \u00A0]*"
".’"
#
"\d[\d’]*"
))))
(
defn-
float-or-int-regex
[
number-separators
]
(
defn-
float-or-int-regex
"Matches integral numbers, even if they have a decimal separator - e.g. 2 or 2.0"
[
number-separators
]
(
with-parens
(
with-currency
(
case
number-separators
...
...
@@ -193,14 +197,16 @@
", "
#
"\d[\d \u00A0]*(\,[0.]+)?"
".’"
#
"\d[\d’]*(\.[0.]+)?"
))))
(
defn-
float-regex
[
number-separators
]
(
defn-
float-regex
"Matches numbers, regardless of whether they have a decimal separator - e.g. 2, 2.0, or 2.2"
[
number-separators
]
(
with-parens
(
with-currency
(
case
number-separators
(
"."
".,"
)
#
"\d[\d,]*\.\d+"
",."
#
"\d[\d.]*\,[\d]+"
", "
#
"\d[\d \u00A0]*\,[\d.]+"
".’"
#
"\d[\d’]*\.[\d.]+"
))))
(
"."
".,"
)
#
"\d[\d,]*
(
\.\d+
)?
"
",."
#
"\d[\d.]*
(
\,[\d]+
)?
"
", "
#
"\d[\d \u00A0]*
(
\,[\d.]+
)?
"
".’"
#
"\d[\d’]*
(
\.[\d.]+
)?
"
))))
(
defmacro
does-not-throw?
"Returns true if the given body does not throw an exception."
...
...
@@ -246,17 +252,17 @@
(
mu/defn
^
:private
settings->type->check
:-
type->check-schema
[{
:keys
[
number-separators
]
:as
_settings
}]
(
let
[
int
?
(
regex-matcher
(
int-regex
number-separators
))
(
let
[
int
-string?
(
regex-matcher
(
int-regex
number-separators
))
float-or-int?
(
regex-matcher
(
float-or-int-regex
number-separators
))
float
?
(
regex-matcher
(
float-regex
number-separators
))]
float
-string?
(
regex-matcher
(
float-regex
number-separators
))]
{
::*boolean-int*
boolean-int-string?
::boolean
boolean-string?
::offset-datetime
offset-datetime-string?
::date
date-string?
::datetime
datetime-string?
::int
int?
::int
int
-string
?
::*float-or-int*
float-or-int?
::float
float?
::float
float
-string
?
::varchar-255
varchar-255?
::text
(
constantly
true
)}))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/upload_test.clj
+
19
−
0
View file @
2a68dfab
...
...
@@ -1926,6 +1926,25 @@
[
2
1.0
1.0
]]
(
rows-for-table
table
)))))))))
(
deftest
create-from-csv-int-and-non-integral-float-test
(
testing
"Creation should handle a mix of int and float values in any order"
(
mt/test-drivers
(
mt/normal-drivers-with-feature
:uploads
)
(
with-mysql-local-infile-on-and-off
(
with-upload-table!
[
table
(
let
[
table-name
(
mt/random-name
)]
(
@#
'upload/create-from-csv!
driver/*driver*
(
mt/id
)
table-name
(
csv-file-with
[
"float-1,float-2"
"1, 1.1"
"1.1, 1"
]))
(
sync-upload-test-table!
:database
(
mt/db
)
:table-name
table-name
))]
(
testing
"Check the data was uploaded into the table correctly"
(
is
(
=
[[
1
1.0
1.1
]
[
2
1.1
1.0
]]
(
rows-for-table
table
)))))))))
(
deftest
append-from-csv-int-and-float-test
(
mt/test-drivers
(
mt/normal-drivers-with-feature
:uploads
)
(
testing
"Append should handle a mix of int and float-or-int values being appended to an int column"
...
...
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