Zet*_*eth 1 mysql scala mariadb apache-spark
我正在尝试访问 Spark 中的 MariaDB 数据库以对其执行 SQL 查询。它确实成功打印了表的架构,因此连接正常工作,但是每当我尝试访问数据库内的任何列或值时,我总是会遇到超出范围的异常:java.sql.SQLException:超出列的范围值:价值规范
完整的日志和堆栈跟踪如下。
我可以访问 Spark 外部的数据库并成功获取数据库的值。此外,我尝试使用已弃用的类(例如 SparkSQLContext)来访问数据库,并获得类似的结果。
object Main {
def main(args: Array[String]) {
// parse commandline parameters, get database properties
val commandLineParser = new CommandLineParser()
val commandLineParameters = commandLineParser.parseCommandLineParameters(args)
val databaseProperties = PropertiesParser.readPropertiesFile(commandLineParameters.configFilePath)
if (commandLineParameters.sparkSupport) {
val spark =
if (commandLineParameters.localMode) {
SparkSession
.builder()
.appName("Spark Benchmark CLI")
.config("spark.master", "local")
.config("spark.driver.extraClassPath", "/opt/spark-apps/spark-apps/mariadb-java-client-2.4.1.jar")
.getOrCreate()
}
// For implicit conversions like converting RDDs to DataFrames
import spark.implicits._
// connect
Class.forName("org.mariadb.jdbc.Driver")
val connection = DriverManager.getConnection(databaseProperties.jdbcURL, databaseProperties.user, databaseProperties.password)
connection.isClosed
// Spark likes working with properties, hence we create a properties object
val connectionProperties = new Properties()
connectionProperties.put("user", s"${databaseProperties.user}")
connectionProperties.put("password", s"${databaseProperties.password}")
connectionProperties.put("driver", s"${commandLineParameters.databaseDriver}")
val table = spark.read.jdbc(databaseProperties.jdbcURL, commandLineParameters.table, connectionProperties)
table.printSchema() // this does successfully print the schema
table.show() // this is where the exceptions are created
} else {
// some code that accesses the database successfully outside spark
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在 Spark 内运行 SQL 查询,而不会出现任何超出范围的值异常。
实际发生的完整日志和堆栈跟踪: https://gist.github.com/Zethson/7e3f43cd80daac219704df25cccd68fa
我的一个同事弄清楚了。这是 Spark/MariaDB 连接器中的一个错误:参考文献: https: //jira.mariadb.org/browse/CONJ-421 https://issues.apache.org/jira/browse/SPARK-25013
我通过用 mysql 替换 DB Url 中的 mariadb 解决了这个问题。
| 归档时间: |
|
| 查看次数: |
771 次 |
| 最近记录: |