You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beam.apache.org by Henrique Molina <he...@gmail.com> on 2019/02/08 11:44:47 UTC

What choose: HashMap to CSV ? or select * to CSV ?

Hi folks,
I using query select * from VIEW_*1* after View_*2*,  on database , and
next step is collect rows and export to CSV.
I actual in this point:


PCollection<HashMap<String, Object>> view1 = p.apply(JdbcIO.<HashMap<String,
Object>>read()
 .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(
"org.postgresql.Driver","jdbc:postgresql://IP:5432/DB?readOnly=true")
.withUsername("username")         .withPassword("password#"))

.withCoder(TableRowCoder.of())

.withRowMapper(new RowMapper<HashMap<String, Object>>() {

@Override

public HashMap<String, Object> mapRow(ResultSet resultSet) throws Exception
{             log.info("Reading view1");         HashMap<String, Object>
cols = TableRowMapper.asMap(resultSet, "View1", "");

return cols;

}

}).withQuery("select * from VIEW1"))

.apply("To CSV ", new DoFn<<HashMap<String,Object>,String>(){

     // using some library to read all hash map

}).apply("To CSV ", new SAVEFILE()); // not exist yet

Someone has same example to how I can continue using the best practices for
this approach ?
I looking for some things how to HashMap to CSV using this library, but I
don't know if is good
http://super-csv.github.io/super-csv/examples_writing.html

Thanks in Advanced!