我在 Oracle 中有一个表,其中有一些俄语记录。
当我使用 Spark JDBC 读取此表时,我收到的数据帧的值不正确。
您知道为什么会发生这种情况以及如何解决吗?
// executes given query using jdbc
def executeQuery(spark: SparkSession, configuration: Map[String, String], sql_statement: String): DataFrame
= spark.read.format("jdbc")
.option("driver", "oracle.jdbc.OracleDriver")
.option("url", s"jdbc:oracle:thin:@//${configuration("address")}")
.option("user", configuration("username"))
.option("password", configuration("password"))
.option("dbtable", s"(${sql_statement})")
.option("fetchSize", configuration("fetch_size"))
.load()
在您的 jdbc 连接中,您需要设置.option("encoding", "UTF-8")
and ("characterEncoding", "UTF-8")
确保我们在读取数据时使用UTF8字符集。这应该确保您能够正确阅读俄语字符。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)