rbotafogo / jcsv Goto Github PK
View Code? Open in Web Editor NEWCSV read and write for JRuby based on uniVocity
License: Other
CSV read and write for JRuby based on uniVocity
License: Other
Hi,
It seems to be impossible to catch an exception inside the block that is passed to reader#read
. My code looks like this:
reader = Jcsv.reader(path,
format: :map)
reader.filters = { :agno => Jcsv.int, :rbd => Jcsv.int }
reader.read do |ln, rn, row, headers|
begin
writer << row
rescue
# skip row
end
end
A row in my CSV contains an invalid value for the rbd
column, causing jCSV to throw an exception
Jcsv::FilterError: '9089ÃSICA JOSÉ TORIBIO MEDINA' could not be parsed as an Integer in {lineNo=1576684, rowNo=1576684, columnNo=2, rowSource=[2011, 9089ÃSICA JOSÉ TORIBIO MEDINA, 13, 13120, ÑUÑOA, 1, 0, 110, 1, A, 12037904, 1, 20040909, 0, 13120, ÑUÑOA, , , 20110215, 5,7, 91, P, P]}
execute at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/numeric_filters.rb:42
block in executeProcessors at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:122
each_with_index at uri:classloader:/jruby/java/java_ext/java.lang.rb:19
executeProcessors at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:96
filter_input at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:220
read at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:209
read_chunk at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/reader.rb:352
read_chunk at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/map_reader.rb:184
parse_with_block at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/reader.rb:101
read at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/map_reader.rb:92
Is there anyway to skip a row that fails to validate the filters?
PS: Thanks for this gem! It's making my life a lot easier :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.