COPY LOCAL 上的 vertica-python 错误 [英] vertica-python Error on COPY LOCAL

查看:62
本文介绍了COPY LOCAL 上的 vertica-python 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Vertica 7.1 上的 python 中使用此代码'COPY LOCAL':

conn_info = {'host': '192.168.1.1', 'port': 5433, 'user': 'dbadmin', 'password': 'xxxxxx', 'database': 'db'}连接 = vertica_python.connect(**conn_info)cur = connection.cursor()file_name="/tmp/tmp_file"temp_file = open(file_name,"w")temp_file .write(记录)temp_file.close()os.system('gzip -cvf9 %s > %s.gz'%(file_name,file_name))qr="copy tmp_table(int_id, int_timestamp, ... ) 从本地 '%s' GZIP 分隔符 ';'记录终止符 E'\\r' NULL '\\N';"%(file_name+'.gz')cur.execute(qr)

但我现在想在 Vertica 9.0.1 上做同样的事情,但我收到了这个错误:

<块引用>

回溯(最近一次调用最后一次):

文件collector_as.py",第 264 行,

cur.execute(qr)

文件/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/cursor.py",第126行,在执行中

self.connection.process_message(self._message)

文件/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/connection.py",第 232 行,在 process_message 中

raise errors.MessageError("未处理的消息:{0}".format(message))

MessageError:未处理的消息:

我的 vertica-python 版本:

pip 冻结 |grep vertica -->vertica-python==0.7.3

------------------------

另外我尝试了来自 VERTICA (vertica-client-9.0.1-4.x86_64.tar.gz)
我的 vertica-db-client 版本:

pip 冻结 |grep vertica -->vertica-db-client==9.0.1.4

我收到了这个错误:

<块引用>

回溯(最近一次调用最后一次):

文件collector_as.py",第 265 行,

cur.execute(qr)

NotSupportedError: COPY LOCAL 不受支持

解决方案

当使用 vertica-python 执行 COPY 命令时,您使用 cur.copy(...) 方法.>

游标的复制方法需要两个参数

  1. 复制命令
  2. 要复制的文件

此外,您使用 FROM STDIN 而不是 FROM LOCAL.

qr="copy tmp_table(int_id, int_timestamp, ... ) 从 STDIN GZIP 分隔符 ';'记录终止符 E'\\r' NULL '\\N';"cur.copy(qr, file_name+'.gz')

如果您使用的是 vsql,例如,那么您使用 FROM LOCAL 的语法将是正确的,但 vertica-python 基本上将给出的文件作为第二个参数并将其通过管道传输到复制命令中标准输入.

I was using this code for 'COPY LOCAL' in python on Vertica 7.1:

conn_info = {'host': '192.168.1.1', 'port': 5433, 'user': 'dbadmin', 'password': 'xxxxxx', 'database': 'db'}
connection = vertica_python.connect(**conn_info)
cur = connection.cursor()
file_name="/tmp/tmp_file"
temp_file = open(file_name,"w")
temp_file .write(records)
temp_file.close()
os.system('gzip -cvf9 %s > %s.gz'%(file_name,file_name))
qr="copy tmp_table(int_id, int_timestamp, ... ) from local '%s' GZIP delimiter ';' RECORD TERMINATOR E'\\r' NULL  '\\N';"%(file_name+'.gz')
cur.execute(qr)

But i want to do same on Vertica 9.0.1 now and i got this error:

Traceback (most recent call last):

File "collector_as.py", line 264, in

cur.execute(qr)

File "/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/cursor.py", line 126, in execute

self.connection.process_message(self._message)

File "/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/connection.py", line 232, in process_message

raise errors.MessageError("Unhandled message: {0}".format(message))

MessageError: Unhandled message:

my vertica-python version:

pip freeze | grep vertica  -->  vertica-python==0.7.3

------------------------

Also i tried new vertica-db-client from VERTICA (vertica-client-9.0.1-4.x86_64.tar.gz)
my vertica-db-client version:

pip freeze | grep vertica  -->  vertica-db-client==9.0.1.4

and i got this error:

Traceback (most recent call last):

File "collector_as.py", line 265, in

cur.execute(qr)

NotSupportedError: COPY LOCAL is not supported

解决方案

When using vertica-python to do a COPY command, you use the cur.copy(...) method.

The copy method of the cursor takes two arguments

  1. The copy command
  2. The file to be copied

Also, instead of FROM LOCAL, you use FROM STDIN.

qr="copy tmp_table(int_id, int_timestamp, ... ) from STDIN GZIP delimiter ';' RECORD TERMINATOR E'\\r' NULL  '\\N';"
cur.copy(qr, file_name+'.gz')

If you were using vsql—for example—then your syntax using FROM LOCAL would be correct, but vertica-python basically takes the file given as the second argument and pipes it into the copy command as STDIN.

这篇关于COPY LOCAL 上的 vertica-python 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆