背景:
源码
def save_to_db(df,table,flag=0):
if flag==0:
df.write.jdbc(url=url, table=table, properties={'driver':driver,"user": user, "password": password})
else:
df.write.jdbc(url=xieurl, table=table, mode='append', properties={'driver':driver,"user": user, "password": password})
return
……………………………………
save_to_db(df=daysdf, table='t_exer_days_copy', flag=flag)
运行上一个程序正常
现在报错显示
/opt/python3.6.7/lib/python3.6/site-packages/pyspark/sql/readwriter.py in jdbc(self, url, table, mode, properties)
981 if properties is None:
982 properties = dict()
--> 983 jprop = JavaClass("java.util.Properties", self._spark._sc._gateway._gateway_client)()
984 for k in properties:
985 jprop.setProperty(k, properties[k])
AttributeError: 'SparkSession' object has no attribute '_gateway'
检查了好久了。也是心力交瘁呀!
……………………分割线
放弃观察,改变策略
def save_to_db(df,table,flag=0):
if flag==0:
mode='overwrite'
else:
mode='append'
df.write.mode("overwrite").format("jdbc").options(
url=xieurl,
user=user,
password=password,
dbtable=table,
batchsize="1000",
).save()