Shivam Sajwan
Shivam Sajwan

Reputation: 41

register a custom codec in cassandra connector

I am using spark-cassandra-connector_2.11 and version 2.5.2 in my scala application and want to register a custom map codec, but facing issues. Is there any way to register it. I did the same thing on earlier version of connector(2.0.13) where I just did below

CassandraConnector.apply(spark.sparkContext.getConf).openSession().getCluster.getConfiguration.getCodecRegistry.register(new CustomMapCodec())

But in new version as it uses datastax java driver 4.x(also of CassandraConnector), when doing CassandraConnector.apply(spark.sparkContext.getConf).openSession() it gives object of CqlSession compare to Session in earlier version, due to which there is no getCodecRegistry() and not able to register my custom codec. Is there anything I am missing here or any other way to do it ?

I tried replicating earlier version(2.0.13) things, creating session and then tried getting CodecRegistrt object and invoking register() on it but failed to do so as its structure is different from earlier. Also tried manually creating CqlSession

CqlSession.builder().addContactPoint(new InetSocketAddress("127.0.0.1", 9042)).withLocalDatacenter("datacenter1").addTypeCodecs(new CustomMapCodec()).build();

also tried creating cluster

Cluster.builder().addContactPoint("127.0.0.1").build().getConfiguration.getCodecRegistry.register(codec)

but was getting error while connecting to cluster. Exception in thread "main" com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses

Upvotes: 2

Views: 66

Answers (0)

Related Questions