I'm trying to extract hive tables from a server using connection details via pyspark.
Here is the code :
from pyspark.sql.session import SparkSession
from pyspark import SparkContext
from pyspark.sql import SQLContext
database = "some_db_name"
table = "some_table_name"
user = "user"
password = "pwd"
#read table data into a spark dataframe
jdbcDF = spark.read.format("jdbc") \
.option("url", f"jdbc:hive2://dbslp_server:10159/{database};") \
.option("dbtable", table) \
.option("user", user) \
.option("password", password) \
.option("driver", "org.apache.hive.jdbc.HiveDriver") \
.load()
I'm basically trying to connect to a server which has hive tables in it , while authenticating my credentials to that server with hive driver. However i get the following error:
Py4JJavaError Traceback (most recent call last) in 10 .option("user", user) \ 11 .option("password", password) \ ---> 12 .option("driver", "org.apache.hive.jdbc.HiveDriver") \ 13 .load()
/anaconda3/lib/python3.6/site-packages/pyspark/sql/readwriter.py in load(self, path, format, schema, **options) 170 return self._df(self._jreader.load(self._spark._sc._jvm.PythonUtils.toSeq(path))) 171 else: --> 172 return self._df(self._jreader.load()) 173 174 @since(1.4)
/anaconda3/lib/python3.6/site-packages/py4j/java_gateway.py in call(self, *args) 1255 answer = self.gateway_client.send_command(command) 1256 return_value = get_return_value( -> 1257 answer, self.gateway_client, self.target_id, self.name) 1258 1259 for temp_arg in temp_args:
/anaconda3/lib/python3.6/site-packages/pyspark/sql/utils.py in deco(*a, **kw) 61 def deco(*a, **kw): 62 try: ---> 63 return f(*a, **kw) 64 except py4j.protocol.Py4JJavaError as e: 65 s = e.java_exception.toString()
/anaconda3/lib/python3.6/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name) 326 raise Py4JJavaError( 327 "An error occurred while calling {0}{1}{2}.\n". --> 328 format(target_id, ".", name), value) 329 else: 330 raise Py4JError(
Py4JJavaError: An error occurred while calling o623.load. : java.sql.SQLException: Method not supported at org.apache.hive.jdbc.HiveStatement.setQueryTimeout(HiveStatement.java:739) at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:60) at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation$.getSchema(JDBCRelation.scala:210) at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:35) at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318) at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223) at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211) at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:167) at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) at py4j.Gateway.invoke(Gateway.java:282) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.GatewayConnection.run(GatewayConnection.java:238) at java.lang.Thread.run(Thread.java:748)
I understand that it is a driver related error, tried to change other hive related drivers, but all in vain, as the same error still persists.Do I have to download any driver. explicitly or link it in any other way?
Can anybody please throw some light on this issue and let me know how I can solve this? Or is there any other way I can achieve this?