落园 » 坑爹的RJDBC和Teradata|专注经济视角下的互联网

坑爹的RJDBC和Teradata

我实在是忍不住要抱怨了,哪有这样的半成品就给我们用的?RJDBC连TD是没有问题,可以读数据,但是dbWriteTable()写不回去!

[2016.1.12 更新]

亲爱的同事写了一个很方便用的r函数来解决这个问题,大家猛戳 -> github

以前的一些...

无奈之下,开始各种搜...除了大家都在抱怨的,有用的大概是两篇。抄过来。

第一篇讲dbWriteTable()的机制。

I have been able to reproduce the problem and look at the sourcecode of
RJDBC. The problem is that in dbWriteTable RJDBC disables autocommit
(and enables it again at the end), creates the table and then tries to
insert into it in the same transaction. Firebird does not allow inserts
into a table that is created in the same transaction.

As I see it, there are are two potential solutions:
1) Manually create the table and then use:
dbWriteTable(conn, "Tab_0", Tab, overwrite=FALSE, append=TRUE)

2) First execute dbWriteTable as normal to create the database (+ get
the error) and then append the data
dbWriteTable(conn, "Tab_0", Tab)
dbWriteTable(conn, "Tab_0", Tab, overwrite=FALSE, append=TRUE)

Other than that, I suggest you file a bug with the creators of RJDBC
that they should commit after the create table.

兴致冲冲的去试了一下,还是不行。没见过配合这么扭的,我建好了表去append吧,说我的表不存在;去建表吧,又说已经在了。坑爹啊!

然后又一阵苦搜,看遍了Teradata JDBC driver的文档之类的,最后觉得唯一靠谱的是这篇

等心情好的时候我去试试....大坑的感觉 T_T ODBC用起来怎么就没有那么多事儿呢?

update Jan 13 2015

居然teradataR可以用...

http://enoriver.net/index.php/2014/12/15/i-wrote-an-r-data-frame-to-a-teradata-table-on-a-mac/

Here's how I did it:

  1. On a new Mac running Mavericks and R 3.1.2 with devtools, I installed Java for Mac.
  2. I installed the RJDBC package from CRAN (which depends on the DBI package also from CRAN) and the teradataR package from GitHub.
  3. I downloaded the Teradata JDBC driver, unpacked it, and moved tdgssconfig.jar and terajdbc4.jar to /System/Library/Java/Extensions.

After that, writing the data frame foo to the table DATABASE.BAR was as simple as:

I had to do this because DBI::dbWriteTable() now fails on Teradata as explained here.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *