PYSPARK: CX_ORACLE.InterfaceError: not a query

混江龙づ霸主 提交于 2021-01-27 13:57:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!