如何解决在Spark中在DataFrame上使用.show方法时,java.sql.SQLException-> NumberFormatException
每当我尝试在deps(//services/gateway:lib) - @npm//...:*
对象上使用.show()
方法时,我都会得到
org.apache.spark.sql.DataFrame
我的SparkSession:
java.sql.SQLException: Cannot convert column 2 to integerjava.lang.NumberFormatException: For input string: "{table_name.column_name}" // here table_name.column_table indicates a placeholder I added for the sake of this question
我的DataFrame加载器:
val sparkSession: SparkSession = SparkSession.builder()
.appName("My sql connector session")
.master("local")
.enableHiveSupport()
.getOrCreate()
当我执行以下代码时
val currentDF : DataFrameReader = sparkSession.sqlContext.read
.format("jdbc")
.option("url",hive_url)
.option("driver","org.apache.hive.jdbc.HiveDriver")
.option("user",username)
.option("inferSchema","true")
.option("password",password)
.option("dbtable",`{*table_name*}`).load()
我明白了
currentDF.createOrReplaceTempView("std")
val newDf = sparkSession.sql("select count(*) as count from std")
newDf.show()
当我使用+-----+
|count|
+-----+
| 726|
+-----+
打印架构时,我有
currentDF.printSchema()
这表示currentDF包含数据,但是每当我使用|-- {table_name}.{column_name}: integer (nullable = true)
方法时,都会出现上述错误。我进行了搜索,但找不到{我的错误},因为我正在获取.show()
,并且表中没有任何脏数据。我不知所措,对此感到非常困惑。任何帮助将不胜感激。
编辑:试图通过将所有列都转换为字符串类型来更改df的架构,但仍得到相同的结果。
PS:我的build.sbt
{table_name.column_name}
解决方法
检查以下代码。
from discord import Intents
from discord.ext.commands import Bot
intent = Intents().all()
bot = Bot(command_prefix='prefix',intents=intent)
... # Some code under this line
val sparkSession: SparkSession = SparkSession.builder()
.appName("My sql connector session")
.master("local")
.enableHiveSupport()
.getOrCreate()
val currentDF : DataFrame = sparkSession.sqlContext.read
.format("jdbc")
.option("url",hive_url)
.option("driver","org.apache.hive.jdbc.HiveDriver")
.option("user",username)
.option("inferSchema","true")
.option("password",password)
.option("dbtable","(select columna,columnb from schema_name.table_name) alias_name") // Replace your table name & column list as per your requirement.
.load()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。