Spark JDBC仅返回数据帧与列名称 [英] Spark JDBC returning dataframe only with column names

查看:822
本文介绍了Spark JDBC仅返回数据帧与列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用spark JDBC连接到HiveTable,并使用以下代码:

I am trying to connect to a HiveTable using spark JDBC, with the following code:

val df = spark.read.format("jdbc").
  option("driver", "org.apache.hive.jdbc.HiveDriver").
  option("user","hive").
  option("password", "").
  option("url", jdbcUrl).
  option("dbTable", tableName).load()

df.show()

,但是我得到的回报只是一个空的数据框,它具有修改过的列名称,如下所示:

but the return I get is only an empty dataframe with modified columns name, like this:

--------------|---------------|
tableName.uuid|tableName.name |
--------------|---------------|

我尝试以很多方式读取数据帧,但结果始终如此。
我正在使用JDBC Hive Driver,并且此HiveTable位于EMR群集中。该代码也运行在同一个群集中。
任何帮助将非常感激。
谢谢大家。

I've tried to read the dataframe in a lot of ways, but it always results the same. I'm using JDBC Hive Driver, and this HiveTable is located in an EMR cluster. The code also runs in the same cluster. Any help will be really appreciated. Thank you all.

推荐答案

请设置fetchsize选项,它应该可以正常工作。

Please set fetchsize in option it should work.

Dataset<Row> referenceData
            = sparkSession.read()
            .option("fetchsize", "100")
            .format("jdbc")
            .option("url", jdbc.getJdbcURL())
            .option("user", "")
            .option("password", "")
            .option("dbtable", hiveTableName).load();

这篇关于Spark JDBC仅返回数据帧与列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆