從pyspark。sql進口SparkSession
火花= SparkSession.builder.getOrCreate ()
def load_data(司機、jdbc_url、sql、用戶密碼):
返回的火花。讀\
.format (jdbc) \
.option \(司機,司機)
.option (“url”, jdbc_url) \
.option(“數據表”,“({sql})為src”.format sql (sql =)) \
.option \(“用戶”,用戶)
.option \(密碼,密碼)
.load ()
司機= ' com.teradata.jdbc.TeraDriver '
sql = " select * from hr.employees "
url = " jdbc: teradata: / / < IPADDRESS > /數據庫= dbc LOGMECH = TD2”
用戶= " dbc "
密碼= " dbc "
df_td = load_data(司機、url、sql、用戶密碼)
df_td.show (10)
我得到以下錯誤:
java.sql。SQLException異常:[Teradata JDBC驅動程序][TeraJDBC 17.20.00.08][錯誤1277][SQLState 08 s01]登錄超時連接XXXXX 8月18日星期四08:18:31 UTC 2022套接字源自= XXXXX cid = 2 ab4c070稅= 0 java.net.SocketTimeoutException:連接超時在java.net.PlainSocketImpl.socketConnect(本機方法)java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java: 350) java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java: 206) java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java: 188) java.net.SocksSocketImpl.connect (SocksSocketImpl.java: 392) java.net.Socket.connect (Socket.java: 607)美元com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF ConnectThread.run (TDNetworkIOIF.java: 1569)