最近用java从hbase中 做spark清洗,由于需要根据key模糊查询,便在网上找了各种资料,凑合一块儿给弄出来了。
1、获取spark上下文,其中的 PropertiesUtils 是一个工具类,可以自己去写,就是加载spark的配置文件
public static JavaSparkContext getSparkConf() {
SparkConf sparkConf = new SparkConf();
Properties properties = PropertiesUtils.loadProperties("spark.properties");
Set<String> propertiesNameSet = properties.stringPropertyNames();
for (String propertiesName : propertiesNameSet) {
sparkConf.set(propertiesName, properties.getProperty(propertiesName));
}
return new JavaSparkContext(sparkConf);;
}
2、获取hbase的配置文件
public static Configuration getHbaseConfig() {
Properties properties = PropertiesUtils.loadProperties("hbase.properties");
Set<String> propertiesNameSet &#