hive string函数使用varchar失败,但使用string

j2qf4p5b  于 2021-05-31  发布在  Hadoop
关注(0)|答案(0)|浏览(413)

我用jaydebeapi连接到Hive。
我想使用配置单元选择varchar(100)的前3个字符。
我有列名为col1和col2。col1是字符串,col2是varchar(100)
当我这么做的时候,效果很好:

connection = jaydebeapi.connect(class_name, url)
cursor = connection.cursor()
cursor.execute('use db1')
cursor.execute("select substr(col1, 1, 3) from table1")
data = cursor.fetchall()
print(data)

但是,当我尝试对col2执行相同的操作时,我得到一个错误:

connection = jaydebeapi.connect(class_name, url)
cursor = connection.cursor()
cursor.execute('use db1')
cursor.execute("select substr(col2, 1, 3) from table1")
data = cursor.fetchall()
print(data)
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 537, in execute
    is_rs = self._prep.execute()
jpype._jexception.SQLExceptionPyRaisable: java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.tez.TezTask

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/test_query.py", line 50, in <module>
    cursor.execute("select substr(col2, 1, 3) from table1")
  File "/usr/local/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 539, in execute
    _handle_sql_exception()
  File "/usr/local/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 165, in _handle_sql_exception_jpype
    reraise(exc_type, exc_info[1], exc_info[2])
  File "/usr/local/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 57, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 537, in execute
    is_rs = self._prep.execute()
jaydebeapi.InterfaceError: java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.tez.TezTask

有什么办法解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题