title: Connecting to SAPHANA from Spark
body: <p>I am trying to execute query using spark sql on SAP HANA via JAVA code. On calling any action on the data frame object, I am getting  java.io.NotSerializableException.In below piece of code when <code>df.count();</code> is invoked, NotSerializableException is thrown.</p>
  
  <pre><code>public class SaphanaTest implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      public void call() {
  
          SparkConf sparkconf = new SparkConf().set("spark.master", "local[*]");
  
          SparkContext sc = new SparkContext(sparkconf);
          HiveContext sqlContext = new HiveContext(sc);
  
          try {
              Class.forName("com.sap.db.jdbc.Driver");
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
  
          Map&lt;String, String&gt; options = new HashMap&lt;String, String&gt;();
          options.put("url",
                  "jdbc:sap://&lt;IP&gt;:30015/system");
          options.put("user", "SYSTEM");
          options.put("password", "Saphana123");
          options.put("dbtable", "SYSTEM.TEST1");
  
          DataFrame df = sqlContext.load("jdbc", options);
  
          df.registerTempTable("temp");
          df = sqlContext.sql("select * from temp");
  
          long count = df.count();
          sc.stop();
      }
  
      public static void main(String[] args) {
          SaphanaTest test = new SaphanaTest();
          test.call();
  }
  }
  </code></pre>
  
  <p>Error stack trace:</p>
  
  <blockquote>
    <p>Exception in thread "main" <strong>org.apache.spark.SparkException: Task not serializable  at</strong>
    org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:315)
      at
    org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:305)
      at
    org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:132)
      at org.apache.spark.SparkContext.clean(SparkContext.scala:1893)     at
    org.apache.spark.SparkContext.runJob(SparkContext.scala:1766)     at
    org.apache.spark.rdd.RDD$$anonfun$toLocalIterator$1.org$apache$spark$rdd$RDD$$anonfun$$collectPartition$1(RDD.scala:900)  at
    org.apache.spark.rdd.RDD$$anonfun$toLocalIterator$1$$anonfun$apply$30.apply(RDD.scala:902)
      at
    org.apache.spark.rdd.RDD$$anonfun$toLocalIterator$1$$anonfun$apply$30.apply(RDD.scala:902)
      at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)   at
    scala.collection.convert.Wrappers$IteratorWrapper.hasNext(Wrappers.scala:29)
      at com.impetus.saphana.SaphanaTest.main(SaphanaTest.java:48) <strong>Caused
    by: java.io.NotSerializableException: com.sap.db.jdbc.topology.Host
    Serialization stack:</strong>
      - object not serializable (class: com.sap.db.jdbc.topology.Host, value: 172.26.52.54:30015)
      - writeObject data (class: java.util.ArrayList)
      - object (class java.util.ArrayList, [172.26.52.54:30015])
      - writeObject data (class: java.util.Hashtable)
      - object (class java.util.Properties, {dburl=jdbc:sap://172.26.52.54:30015, user=SYSTEM,
    password=Saphana123,
    url=jdbc:sap://172.26.52.54:30015/?system&amp;user=SYSTEM&amp;password=Saphana123,
    dbtable=SYSTEM.TEST1, hostlist=[172.26.52.54:30015]})
      - field (class: org.apache.spark.sql.jdbc.JDBCRDD$$anonfun$getConnector$1, name:
    properties$1, type: class java.util.Properties)
      - object (class org.apache.spark.sql.jdbc.JDBCRDD$$anonfun$getConnector$1,
    )</p>
  </blockquote>
  
  <p>Any pointers?
  After doing research over google, I found one suggestion to make the connection properties serializable. But I have no idea of how to make it serializable in spark. </p>
  
  <p>Appreciate help on this.
  Thank you in advance.</p>