Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FACT Unified Data IO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FACT
FACT Utils
FACT Unified Data IO
Commits
3e9bbecc
Commit
3e9bbecc
authored
1 year ago
by
Riccardo Boero
Browse files
Options
Downloads
Patches
Plain Diff
Fixed nothing to NULL MySQL problem with workround trhough missing.
parent
f4689a97
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/manifestIO.jl
+4
-5
4 additions, 5 deletions
src/manifestIO.jl
with
4 additions
and
5 deletions
src/manifestIO.jl
+
4
−
5
View file @
3e9bbecc
...
@@ -316,7 +316,6 @@ This will insert each row of `df` into the `geographical_features` table in the
...
@@ -316,7 +316,6 @@ This will insert each row of `df` into the `geographical_features` table in the
function
custom_load
(
conn
::
MySQL
.
Connection
,
table_name
::
String
,
df
::
DataFrame
)
function
custom_load
(
conn
::
MySQL
.
Connection
,
table_name
::
String
,
df
::
DataFrame
)
# Preprocess DataFrame to ensure data integrity
# Preprocess DataFrame to ensure data integrity
preprocess_dataframe!
(
df
)
preprocess_dataframe!
(
df
)
println
(
df
)
col_names
=
join
([
"`
$(name)
`"
for
name
in
names
(
df
)],
", "
)
col_names
=
join
([
"`
$(name)
`"
for
name
in
names
(
df
)],
", "
)
placeholders
=
join
([
"?"
for
_
in
1
:
length
(
names
(
df
))],
", "
)
placeholders
=
join
([
"?"
for
_
in
1
:
length
(
names
(
df
))],
", "
)
...
@@ -324,8 +323,8 @@ function custom_load(conn::MySQL.Connection, table_name::String, df::DataFrame)
...
@@ -324,8 +323,8 @@ function custom_load(conn::MySQL.Connection, table_name::String, df::DataFrame)
prepared_stmt
=
DBInterface
.
prepare
(
conn
,
insert_stmt
)
prepared_stmt
=
DBInterface
.
prepare
(
conn
,
insert_stmt
)
for
row
in
eachrow
(
df
)
for
row
in
eachrow
(
df
)
# Convert row to Tuple, directly handling `
noth
ing` (for NULL handling in SQL)
# Convert row to Tuple, directly handling `
miss
ing` (for NULL handling in SQL)
values
=
Tuple
([
x
===
noth
ing
?
noth
ing
:
x
for
x
in
row
])
values
=
Tuple
([
x
===
miss
ing
?
miss
ing
:
x
for
x
in
row
])
DBInterface
.
execute
(
prepared_stmt
,
values
)
DBInterface
.
execute
(
prepared_stmt
,
values
)
end
end
end
end
...
@@ -369,7 +368,7 @@ function preprocess_dataframe!(df::DataFrame)
...
@@ -369,7 +368,7 @@ function preprocess_dataframe!(df::DataFrame)
col_type
=
eltype
(
df
[
!
,
col
])
col_type
=
eltype
(
df
[
!
,
col
])
# Convert missing values to nothing for SQL NULL compatibility
# Convert missing values to nothing for SQL NULL compatibility
df
[
!
,
col
]
=
map
(
x
->
ismissing
(
x
)
?
noth
ing
:
x
,
df
[
!
,
col
])
df
[
!
,
col
]
=
map
(
x
->
ismissing
(
x
)
?
miss
ing
:
x
,
df
[
!
,
col
])
# Clamp numeric values if range is defined for the column type
# Clamp numeric values if range is defined for the column type
if
haskey
(
SQL_RANGES
,
col_type
)
if
haskey
(
SQL_RANGES
,
col_type
)
...
@@ -379,7 +378,7 @@ function preprocess_dataframe!(df::DataFrame)
...
@@ -379,7 +378,7 @@ function preprocess_dataframe!(df::DataFrame)
# Replace NaN and Inf with nothing in numeric columns
# Replace NaN and Inf with nothing in numeric columns
if
col_type
<:
AbstractFloat
if
col_type
<:
AbstractFloat
df
[
!
,
col
]
=
map
(
x
->
isfinite
(
x
)
?
x
:
noth
ing
,
df
[
!
,
col
])
df
[
!
,
col
]
=
map
(
x
->
isfinite
(
x
)
?
x
:
miss
ing
,
df
[
!
,
col
])
end
end
end
end
end
end
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