PYSPARK:CX_ORACLE.InterfaceError:不是查询 [英] PYSPARK: CX_ORACLE.InterfaceError: not a query
本文介绍了PYSPARK:CX_ORACLE.InterfaceError:不是查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在spark作业中执行更新查询.我正在尝试下面的代码.但面临问题.
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
推荐答案
我解决了我的问题.根据卢克的输入.我使用了 fetchall()
进行查询.我需要使用 commit()
.因此更改了代码并检查其工作正常.
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])
这篇关于PYSPARK:CX_ORACLE.InterfaceError:不是查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文