|
|
@ -295,7 +295,9 @@ module CartoDB
|
|
|
|
job.log "Fallback: Disabling autoguessing because there are wrong dates in the source file"
|
|
|
|
job.log "Fallback: Disabling autoguessing because there are wrong dates in the source file"
|
|
|
|
@job.fallback_executed = "date"
|
|
|
|
@job.fallback_executed = "date"
|
|
|
|
ogr2ogr.overwrite = true
|
|
|
|
ogr2ogr.overwrite = true
|
|
|
|
ogr2ogr.csv_guessing = false
|
|
|
|
ogr2ogr.csv_guessing = true
|
|
|
|
|
|
|
|
ogr2ogr.quoted_fields_guessing = false
|
|
|
|
|
|
|
|
try_fix_invalid_field(ogr2ogr.filepath, ogr2ogr.command_output)
|
|
|
|
ogr2ogr.run(append_mode)
|
|
|
|
ogr2ogr.run(append_mode)
|
|
|
|
elsif ogr2ogr.encoding_error?
|
|
|
|
elsif ogr2ogr.encoding_error?
|
|
|
|
job.log "Fallback: There is an encoding problem, trying with ISO-8859-1"
|
|
|
|
job.log "Fallback: There is an encoding problem, trying with ISO-8859-1"
|
|
|
@ -385,6 +387,14 @@ module CartoDB
|
|
|
|
def statement_timeout?(error)
|
|
|
|
def statement_timeout?(error)
|
|
|
|
error =~ /canceling statement due to statement timeout/i
|
|
|
|
error =~ /canceling statement due to statement timeout/i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def try_fix_invalid_field(filepath, command_output)
|
|
|
|
|
|
|
|
line = command_output.split("line")[1].split(':')[0].split(',')[0].delete(' ').to_i - 1
|
|
|
|
|
|
|
|
column = command_output.split("column")[1].split(':')[0].split(',')[0].delete(' ')
|
|
|
|
|
|
|
|
csv_content = CSV.read(filepath, headers: true)
|
|
|
|
|
|
|
|
csv_content[line][column] = '"' + csv_content[line][column] + '"'
|
|
|
|
|
|
|
|
File.open(filepath, "w") {|file| file.puts csv_content.to_s }
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|