使用 Spark 从 teradata table 读取数据时出现 ExceptionInInitializer 错误

ExceptionInInitializer Error while Reading Data from teradata table using Spark

我正在使用下面的代码从 teradata 读取数据,但出现错误

val jdbcDF = spark.read
  .format("jdbc")
  .option("url",s"jdbc:teradata://${TeradataDBHost}/database=${TeradataDBDatabase}")
  .option("dbtable", TeradataDBDatabase+"."+TeradataDBTable)
  .option("driver","com.teradata.jdbc.TeraDriver")
  .option("user", TeradataDBUsername)
  .option("password", TeradataDBPassword)
  .load()

错误堆栈跟踪

Exception in thread "main" java.lang.ExceptionInInitializerError
            at com.teradata.jdbc.jdbc.GenericTeraEncrypt.getGSSM(GenericTeraEncrypt.java:577)
            at com.teradata.jdbc.jdbc.GenericTeraEncrypt.<init>(GenericTeraEncrypt.java:116)
            at com.teradata.jdbc.jdbc.GenericTeradataConnection.<init>(GenericTeradataConnection.java:107)
            at com.teradata.jdbc.jdbc_4.TDSession.<init>(TDSession.java:186)
            at com.teradata.jdbc.jdk6.JDK6_SQL_Connection.<init>(JDK6_SQL_Connection.java:36)
            at com.teradata.jdbc.jdk6.JDK6ConnectionFactory.constructSQLConnection(JDK6ConnectionFactory.java:25)

Caused by: java.lang.NullPointerException
        at com.teradata.tdgss.jtdgss.TdgssConfigApi.GetMechanisms(Unknown Source)
        at com.teradata.tdgss.jtdgss.TdgssManager.<init>(Unknown Source)
        at com.teradata.tdgss.jtdgss.TdgssManager.<clinit>(Unknown Source)

来自Teradata JDBC driver documentation

If you receive one of the following exceptions:

  • NullPointerException at com.teradata.tdgss.jtdgss.TdgssConfigApi.GetMechanisms
  • IllegalArgumentException "InputStream cannot be null" at javax.xml.parsers.DocumentBuilder.parse, at com.teradata.tdgss.jtdgss.TdgssParseXml.parse

then the problem may be due to the classpath not being set, or the classpath being set incorrectly, such that tdgssconfig.jar cannot be found.

所以我猜想在类路径中找不到 tdgssconfig.jar

当然,如果 JDBC 驱动程序能够抛出比 NPE 更有用的错误消息,那就太好了。我有点担心这似乎是驱动程序的 'known issue':我无法想象在这种情况下抛出更有用的异常需要付出很多努力。如果他们选择记录此行为而不是修复它,对他们来说并没有什么意义。

(致谢:通过 this Teradata Community post 找到。)