问题
i need to perform update query in spark job. i am trying below code. but facing issues.
import cx_Oracle
def query(sql):
connection = cx_Oracle.connect("username/password@s<url>/db")
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
return result
v = [10]
rdd = sc.parallelize(v).coalesce(1)
rdd.foreachPartition(lambda x : [query("UPDATE db.tableSET MAPPERS ="+str(i)+" WHERE TABLE_NAME = 'table_name'") for i in x])
when i execute the above process i am getting below error.
cx_Oracle.InterfaceError: not a query
i tried to update manually using below code.
result = query("<update query>")
when i do this, job is executing continuously
回答1:
I resolved my problem. As per Luke inputs. i used fetchall()
which is used for querying. i need to use commit()
. so changed the code and checked its working fine.
import cx_Oracle
def query(sql):
connection = cx_Oracle.connect("username/password@s<url>/db")
cursor = connection.cursor()
cursor.execute(sql)
result = connection.commit()
v = [10]
rdd = sc.parallelize(v).coalesce(1)
rdd.foreachPartition(lambda x : [query("UPDATE db.tableSET MAPPERS ="+str(i)+"WHERE TABLE_NAME = 'table_name'") for i in x])
来源:https://stackoverflow.com/questions/53285101/pyspark-cx-oracle-interfaceerror-not-a-query