如何使用Teradata python模块运行自定义函数?

时间:2018-10-12 08:00:29

标签: python sql pandas teradata

这是this的后续问题。

我想知道的是,有什么方法可以在teradata python模块中运行自定义函数。

我在查询中有一个名为hash_md5的自定义函数,模块无法识别。有什么办法可以运行查询?

此查询具有自定义功能:

td_query = """select 
hash_md5((XMLAGG(TRIM(h_age) ORDER BY h_age ASC) (VARCHAR(100))) )hash_age,
hash_md5((XMLAGG(TRIM(h_marks) ORDER BY h_age ASC )(VARCHAR(100)))) hash_marks,
hash_md5((XMLAGG(TRIM(h_id) ORDER BY h_age ASC )(VARCHAR(100)))) hash_id,
hash_md5((XMLAGG(TRIM(h_score) ORDER BY h_age ASC )(VARCHAR(100))))hash_score,
hash_md5((XMLAGG(TRIM(h_name) ORDER BY h_age ASC )(VARCHAR(100))))hash_name,
hash_md5((XMLAGG(TRIM(h_entry) ORDER BY h_entry ASC )(VARCHAR(100))))hash_entry,
SUM(Aggrownum) sum_val,
COUNT(Aggrownum) count_val,
sum_val/count_val row_num
from 
(
Select 
hash_md5(CAST(age AS VARCHAR(100)))h_age ,
hash_md5(CAST(marks AS VARCHAR(100)))h_marks,
hash_md5(CAST(id AS VARCHAR(100)))h_id,
hash_md5(CAST(score AS VARCHAR(100)))h_score,
hash_md5(CAST(f_name AS VARCHAR(100)))h_name,
hash_md5(CAST(entry AS FORMAT 'yyyy-mm-ddbhh:mi:ss') (char (20)))h_entry,
row_number() over (partition by dob order by  age asc) rno,round(rno/500.0) Aggrownum
from tdwm.student
) A group by Aggrownum ORDER BY row_num;
"""

这是相关的python代码:

import pandas as pd
import teradata as td

td_host, td_username, td_passwd, td_dbname = '10.20.181.55', 'dbac', 'dbac', 'tdwm'

udaExec = td.UdaExec(appName="test", version="1.0", logConsole=False)
with udaExec.connect(method="odbc",system=td_host, username=td_username, port=1025,
                            password=td_passwd, driver="Teradata Database ODBC Driver 16.20") as connect:
    df_teradata = pd.read_sql(td_query, connect)

当前我遇到此错误:

  

提高DatabaseError(i [2],u“ [{}] {}”。format(i [0],msg),i [0])   teradata.api.DatabaseError:(3706,“ [42000] [Teradata] [ODBC Teradata   驱动程序] Teradata DatabaseSyntax错误:预期内容   在'('和'('。“)之间

0 个答案:

没有答案