简体   繁体   English

Spark(小数精度 1 超过最大精度 0)

[英]Spark (Decimal precision 1 exceeds max precision 0)

I'm trying to get the count from a JDBC database with the following我正在尝试使用以下内容从 JDBC 数据库中获取计数

def getCount(url: String, user: String, password : String, driver: String, table: String): BigDecimal={

    Context.getSparkSession().read.format("jdbc")
    .option("url", url)
    .option("user", user)
    .option("password", password)
    .option("dtable", s"(SELECT COUNT(*) FROM $table)")
    .load()
    .head.getDecimal(0)
}

However, in the code, at the line where I call getDecimal(0) , I get the exception Decimal precision 1 exceeds max precision 0 .但是,在代码中,在我调用getDecimal(0)的那一行,我得到了异常Decimal precision 1 exceeds max precision 0

What I've tried to debug this:我试图调试这个:

  1. I've verified the credentials, URL, and table name, and I'm able to access the database and get the count with these parameters.我已经验证了凭据 URL 和表名,并且我能够访问数据库并使用这些参数获取计数。

  2. I've verified it's not a database grant issue by printing the dataframe with我已经通过打印 dataframe 验证了这不是数据库授权问题

Context.getSparkSession().read.format("jdbc")
    .option("url", url)
    .option("user", user)
    .option("password", password)
    .option("dtable", s"(SELECT * FROM $table)")
    .load()

and I'm able to view the entire database table with no issues.我可以毫无问题地查看整个数据库表。 I've also tried calling .count() on the dataframe and return the count that way but to no avail.我还尝试在 dataframe 上调用.count()并以这种方式返回计数,但无济于事。

Does anybody know what this issue is or has seen something like this before?有谁知道这个问题是什么或以前见过这样的事情? I'm stumped here.我被难住了。 Yes I'm aware there are similar questions here but I've seen no resolutions, and no situations where the max precision is listed as 0, so this is why I'm asking.是的,我知道这里有类似的问题,但我没有看到任何解决方案,也没有将最大精度列为 0 的情况,所以这就是我要问的原因。

Figured it out.弄清楚了。 The JDBC URL started with jdbc:Oracle instead of jdbc:oracle, which fixed it. The JDBC URL started with jdbc:Oracle instead of jdbc:oracle, which fixed it. Still puzzled why a connection exception didn't occur, and I was able to print out the table but not do a count.仍然很困惑为什么没有发生连接异常,我能够打印出表格但没有进行计数。 Oh well, it's resolved.恩,解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM