2017-01-17 78 views
0

我試圖在我使用 Citus創建的散列分佈表中插入一些數據。在Pyspark中,我使用JDBC postgres驅動器將數據插入到表中。 代碼,我使用的數據插入到在pyspark使用JDBC表是:在Pyspark中使用JDBC插入Citus散列分佈表

url = "jdbc:postgresql://host:port/db_name?rewriteBatchedStatements=true" 
    properties = {"user":"user_name","password":"password"} 
    df = spark.createDataFrame(rdd_name) 
    df.write.jdbc(url=url, table="table_name", mode="append", properties=properties) 

在此設置下,我得到這個錯誤:

: org.postgresql.util.PSQLException: ERROR: relation "table_name" already exists 
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) 
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) 
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) 
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) 
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356) 
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:303) 
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:289) 
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:266) 
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:246) 
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.createTable(JdbcUtils.scala:692) 
at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:89) 
at org.apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:426) 
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:215) 
at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:446) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) 
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) 
at py4j.Gateway.invoke(Gateway.java:280) 
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) 
at py4j.commands.CallCommand.execute(CallCommand.java:79) 
at py4j.GatewayConnection.run(GatewayConnection.java:214) 
at java.lang.Thread.run(Thread.java:745) 

能有人幫我我怎麼插入數據在pyspark中使用jdbc進入citus postgres?提前致謝。

+0

您使用哪種spark版本? – Yaron

回答

1

您的錯誤消息說「table_name」已經存在。很可能,您的代碼或框架試圖再次創建相同的表。你能檢查一下嗎?