Trying to connect to HAWQ from Spark, using greenplum's odbc/jdbc drivers (downloaded from the proper Pivotal page).
Using Spark 1.4, here's the sample code written in python: (All capitals have proper variable assignments) ...
from pyspark import SparkContext
from pyspark.sql import SQLContext
sc = SparkContext()
sqlContext = SQLContext(sc)
df = sqlContext.read.load(source='jdbc',\
url='IP_ADDRESS:PORT/DB_NAME?user=USERNAME&password=PASSWORD&ssl=true',\
dbtable='SCHEMA.TABLE_NAME')
...
Spark submit command appends the odbc driver to the classpath. I've done a 'hello world' with the basic sqlContext instantiation and everything runs fine on the cluster. But when I try to actually connect to the HAWQ postgresql db it will not run.
Error:
py4j.protocol.Py4JJavaError: An error occurred while calling o24.load.
: java.util.NoSuchElementException: key not found: path
at scala.collection.MapLike$class.default(MapLike.scala:228)
at org.apache.spark.sql.sources.CaseInsensitiveMap.default(ddl.scala:467)
at scala.collection.MapLike$class.apply(MapLike.scala:141)
at org.apache.spark.sql.sources.CaseInsensitiveMap.apply(ddl.scala:467)
at org.apache.spark.sql.sources.ResolvedDataSource$.apply(ddl.scala:273)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
at py4j.Gateway.invoke(Gateway.java:259)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:207)
at java.lang.Thread.run(Thread.java:722)
Any thoughts or suggestions? I've tried at least 20 combinations of the "df = sqlContext.read.load..." definition but to no avail.
The correct format for JDBC should be something like this
df = sqlContext.read.format('jdbc').options(url='jdbc:postgresql://node1:5432/postgres?user=myuser&password=password',dbtable='test').load()
Another example here http://spark.apache.org/docs/latest/sql-programming-guide.html#jdbc-to-other-databases