使用 Phoenix 读取 HBase

我使用的是 CDH5.13.2, 所以 pom 文件依赖为:

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-spark</artifactId>
<version>4.14.0-cdh5.13.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.14.0-cdh5.13.2</version>
</dependency>

这样读取:

1
2
3
4
5
val df = sqlContext.read.format("jdbc")
.option("driver", "org.apache.phoenix.jdbc.PhoenixDriver")
.option("url", "jdbc:phoenix:localhost:2181")
.option("dbtable", "US_POPULATION")
.load()

或者

1
2
3
4
val df = sqlContext.load(
"jdbc",
Map("zkUrl" -> "localhost:2181", "url" -> "jdbc:phoenix:localhost:2181", "dbtable" -> "US_POPULATION", "driver" -> "org.apache.phoenix.jdbc.PhoenixDriver")
)