简体   繁体   中英

trouble with spark cassandra connector in java

I am trying to query cassandra from spark in java. Below is the code to fetch data but mapToRow method takes two parameter. first is class and second is ColumnMapper. How to get instance of the ColumnMapper class in java. Googling it recommends creating object of derived class JavaBeanColumnMapper but didn't find how JavaBeanColumnMapper class should be instantiated.

List<String> dates = Arrays.asList("2015-02-02","2015-02-08");
    JavaRDD<DailyTaxlot> openTaxlots = CassandraJavaUtil.javaFunctions(sc).
            cassandraTable("wedbush_praveen_testing", "cf_taxlots",CassandraJavaUtil.mapToRow(DailyTaxlot.class),).
                    where("openclosetag=?","Open").where("rundate IN",dates);

Any lead will be appreciated.

Have a look at the example from the spark-cassandra-connector here:

JavaApiDemo.java

In the example you can see how the Person bean class is defined. The API will instantiate it as needed for each row.

JavaRDD<Person> rdd = CassandraJavaUtil.javaFunctions(sc).cassandraTable("test", "people", mapRowTo(Person.class));

// Bean definition
public static class Person implements Serializable {
    private Integer id;
    private String name;
    private Date birthDate;

    public static Person newInstance(Integer id, String name, Date birthDate) {
        Person person = new Person();
        person.setId(id);
        person.setName(name);
        person.setBirthDate(birthDate);
        return person;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM