简体   繁体   中英

How to save only few columns to cassandra using spark In Java

I'm trying to save a RDD to Cassandra using

JavaRDD<UserSetGet> rddFromGz = sc.parallelize(ListFromS3);

CassandraJavaUtil.javaFunctions(rddFromGz)
        .writerBuilder("dmp", "table", mapToRow(UserSetGet.class)).saveToCassandra();

Here UserSetGet object has all the fields Initialized.

But I wish to save some columns only , how to do that ?

In the doc , it says we can do

.saveToCassandra("test", "words", SomeColumns("word", "1"));

But it is not recognising SomeColumns Method.

The SomeColumns method is for the Scala api, you're using the Java API...

Maybe it's a good opportunity to switch to Scala

Hope the below lines will help you

val w1 = CassandraJavaUtil.javaFunctions(rdd23).writerBuilder("smart","emp", CassandraJavaUtil.mapToRow(classOf[emp]))
w1.withColumnSelector(CassandraJavaUtil.someColumns("pid","page")).saveToCassandra()

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