在Spark JDBC中使用谓词读取

编程入门 行业动态 更新时间:2024-10-28 18:32:09
本文介绍了在Spark JDBC中使用谓词读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将数据从sql服务器拉到hdfs.这是我的摘录,

I am pulling data from sql server to hdfs. Here is my snippet for that,

val predicates = Array[String]("int_id < 500000", "int_id >= 500000 && int_id < 1000000") val jdbcDF = spark.read.format("jdbc") .option("url", dbUrl) .option("databaseName", "DatabaseName") .option("dbtable", table) .option("user", "***") .option("password", "***") .option("predicates", predicates) .load()

我的Intellij IDE一直说

My Intellij IDE keeps saying that

类型不匹配,预期为Boolean或Long或Double或String,实际: Array [String]"

"Type mismatch, expected Boolean or Long or Double or String, Actual : Array[String]"

谓词中的

.不确定这有什么问题.谁能看到这有什么问题吗?另外如何在这里使用提取大小?

in predicates. Not sure whats wrong with this. Can anyone see whats wrong with this? Also how do I use fetch size here?

谢谢.

推荐答案

对于option方法仅接受Boolean s,Long s,Double s或String s.要将predicates作为Array[String]传递,您必须使用jdbc方法,而不是在format方法中指定它.

To option method accepts only Booleans, Longs, Doubles or Strings. To pass the predicates as an Array[String] you have to use the jdbc method instead of specifying it in the format method.

val predicates = Array[String]("int_id < 500000", "int_id >= 500000 && int_id < 1000000") val jdbcDF = spark.read.jdbc( url = dbUrl, table = table, predicates = predicates, connectionProperties = new Properties(???) // user, pass, db, etc. )

您可以在此处查看示例.

更多推荐

在Spark JDBC中使用谓词读取

本文发布于:2023-11-30 14:40:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:谓词   Spark   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!